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
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.
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.
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
On the MySQL official website https://dev.mysql.com/downloads/mysql/ Download the MySQL installation package and select the version suitable for your system.
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.
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
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.
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
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.
Enter the command php -S localhost:8000 on the command line to start the PHP built-in server to access the PHP file locally.
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!