Before using PHP to develop applications, you need to install PHP on your computer and configure the Apache web server correctly. This tutorial will show you how to install and configure a PHP environment on Windows operating systems.
First, you need to download the latest version of PHP from PHP’s official website https://windows.php.net/download/. Download the version you need (for this tutorial, we chose the Thread Safe version of PHP 7.4.16).
After downloading PHP, unzip the file to install PHP on your computer. It is recommended to install it in the C:\php directory.
After you have PHP installed on your computer, you need to configure the Apache web server to use PHP. Locate the Apache web server's configuration file httpd.conf (default location: C:\Program Files\Apache Group\Apache2\conf\httpd.conf) and edit the file.
Find the following line:
#LoadModule php7_module modules/php7apache2_4.dll
Remove the comment symbol "#" and it becomes:
LoadModule php7_module “C:/php/php7apache2_4.dll”
Add the following content at the end of the file:
# PHP Settings PHPIniDir "C:/php/" AddHandler application/x-httpd-php .php
Save and close the file.
Open the command prompt with administrator privileges and execute the following command to start the Apache Web server:
net start Apache2.4
After completing the above steps, you can create a PHP file and place it in the Web directory of the Apache Web server (default location: C:\Program Files\Apache Group\Apache2\htdocs).
For example, create a file called info.php and enter the following:
<?php phpinfo(); ?>
Then enter the following URL in your web browser to access the info.php file:
http://localhost/info.php
If you have configured PHP correctly, you will be able to see the PHP configuration information page.
Now, you have successfully installed and configured a PHP environment on your Windows operating system. Next, you can develop web applications using PHP.
The above is the detailed content of How to install and configure PHP environment on Win system. For more information, please follow other related articles on the PHP Chinese website!