Home > Backend Development > PHP Problem > How to build php and install database

How to build php and install database

PHPz
Release: 2023-04-13 09:44:37
Original
839 people have browsed it

In the process of website development, setting up a PHP environment and database is an essential step. This article will introduce how to set up a PHP environment under Windows systems and install a MySQL database.

1. Install PHP

  1. Download the PHP installation package

Download the precompiled version from the official website https://windows.php.net/download/ version of the PHP installation package, select the installation package corresponding to the system architecture and PHP version to download.

  1. Install PHP

Run the downloaded PHP installation package, select the appropriate installation path, and after the installation is complete, add the PHP installation directory to the system path environment variable.

  1. Test PHP

Open the command line and enter the php -v command to check whether the PHP version is correct. If the PHP version information is output, it means that PHP has been successfully installed.

2. Install MySQL

  1. Download the MySQL installation package

On the MySQL official website https://dev.mysql.com/downloads/mysql/ Download the MySQL installation package and select the version suitable for your system.

  1. Install MySQL

Run the downloaded MySQL installation package, follow the prompts to complete the MySQL installation, set the password of the MySQL root user, and add the MySQL bin directory to in the system path environment variable.

  1. Connect to MySQL

Open the command line, enter the mysql -u root -p command, and enter the set password. If the MySQL database is successfully connected, the MySQL installation is successful. .

3. Configure PHP and MySQL

  1. Configure PHP

Open the php.ini file in the PHP installation directory and find mysql.dll in the file and enable configuration items of mysqli.dll and enable them. At the same time, modify the configuration options of the system time and time zone to ensure that the time zones of PHP and MySQL databases are the same.

  1. Configuring MySQL

Open the my.ini file in the MySQL installation directory, find the bind-address and character_set_server configuration items, and set them to 127.0.0.1 and utf8mb4 respectively. , so that the correct character set can be used when accessing the MySQL database locally, and the default encoding of MySQL is modified to utf8mb4.

4. Test PHP and MySQL

  1. Create PHP file

Create a PHP file named test.php in any local directory and edit it file, write PHP code in it to connect to the MySQL database, and perform related operations, such as querying the data in the MySQL database and outputting the data on the web page.

  1. Start the server

Enter the command php -S localhost:8000 on the command line to start the PHP built-in server to access the PHP file locally.

  1. Test

Enter the address http://localhost:8000/test.php in the browser, you can see the relevant data in the MySQL database on the web page Information indicating that the environment configuration of PHP and MySQL has been successful.

Summary

This article introduces in detail how to set up a PHP environment and install the MySQL database under Windows systems, and performs relevant configuration and testing of PHP and MySQL. I hope this article can help beginners quickly set up a development environment for PHP and MySQL, and facilitate the development and testing of websites and applications.

The above is the detailed content of How to build php and install database. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template