Home > Article > Backend Development > Building PHP development environment under windows
In the current Internet era, most websites are built based on PHP language. In order to quickly develop PHP, a corresponding development environment needs to be built. For Windows systems, below we will introduce in detail how to set up a PHP development environment.
1. Install Apache
Apache is one of the most popular web server software currently. When developing with PHP, we need to install Apache's web service.
Before installation, make sure that no other Web services (such as IIS) are running on this machine.
You can download the latest version of Apache software from the download page of Apache official website (http://httpd.apache.org/), or click directly (http://httpd.apache.org/download.cgi )download.
After the download is completed, double-click to install.
During the installation process, you need to select the components to be installed, as shown in the figure below:
Here we only need to install the default "Apache HTTP Server" that is Can.
During the installation process, you will be asked for the default installation directory. Here we take the default directory as an example for demonstration.
After completing the installation, we can find the "Apache HTTP Server" folder in the "Start" menu, and then enter the "Control Apache Server" menu item in the folder , and click the "Start" button to start this Web service.
How to verify whether Apache is started successfully? It's very simple. We can enter http://localhost in the browser and see the following picture, which means Apache is successfully started.
2. Install PHP
PHP is one of the most popular web development languages, and PHP needs to be installed to support website development.
You can go to the PHP official website (http://www.php.net/downloads.php) to download the latest version of PHP, or click directly (http://windows.php.net/download/) to download .
After the download is complete, run the installer.
Before installation, confirm that the Apache Web service has been closed.
Here we take the php-7.2.3-Win32-VC15-x64.zip file as an example for demonstration.
Extract the downloaded php-7.2.3-Win32-VC15-x64.zip file to the local "C:\PHP" directory.
After decompression is completed, edit the php.ini-development file in the "C:\PHP" directory and modify the relevant configuration items to support the extended class libraries required for PHP development, as shown below:
;extension=bz2 ;extension=curl ;extension=fileinfo ;extension=gd2 ;extension=gettext ;extension=gmp ;extension=intl ;extension=imap ;extension=interbase/firebird ;extension=ldap ;extension=mbstring ;extension=exif ; Must be after mbstring as it depends on it ;extension=mysqli ;extension=oci8_12c ; Use with Oracle Database 12c Instant Client ;extension=odbc ;extension=openssl ;extension=pdo_firebird ;extension=pdo_mysql ;extension=pdo_oci ;extension=pdo_odbc ;extension=pdo_pgsql ;extension=pdo_sqlite ;extension=pgsql ;extension=shmop
By the way, I would like to explain that ";" is used here to comment out some extensions because in the following "Integration of PHP and Apache" environment configuration, loading of all PHP extension libraries into Apache has not been activated. middle.
Now you can use the "php -v" command in the command line to verify whether PHP has been successfully installed. If you see the output as shown below, the installation is successful.
3. Integration of PHP and Apache
Next, you need to integrate PHP and Apache.
In this example, we use Apache's module approach to achieve this integration.
First, we need to open the "httpd.conf" configuration file in Apache and make some modifications to its contents.
Enter the "C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf" directory, find the "httpd.conf" file, and make the following changes after editing:
1. Enable PHP module
Look for "LoadModule" in the file and find the available "php7_module". You should be able to find the newly installed PHP, and then uncomment this line in front of it.
For example:
LoadModule php7_module "C:/PHP/php7apache2_4.dll"
2. Add the processor of the PHP file
In the "httpd.conf" file, find the default processor "AddHandler" item, and After this item, add the setting of the PHP file extension (.php), for example:
AddHandler php7-script .php
3. Set the directory index
Add index.php to "DirectoryIndex" to support elfinder Configuration:
DirectoryIndex index.php elfinder.php
The settings are as follows:
<ifmodule dir_module> DirectoryIndex index.php elfinder.php </ifmodule>
4. Set the document root directory
Set the document root directory to the path of the Apache Web root directory:
DocumentRoot "C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs"
5. Configure PHP.ini
Search for "PHPIniDir" in "httpd.conf" and change its path to the installation path of PHP, for example:
PHPIniDir "C:/PHP"
设置完成后重启Apache Web服务即可,此时可以在“C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs”目录中新建“index.php”文件,内容如下:
<?php phpinfo(); ?>
(笑容虽不逊“Hello World”示例,查看php环境的信息毕竟是学习PHP的必经之路。)
保存并通过浏览器访问http://localhost/index.php文件,查验php脚本是否正常运行,如果您能看到如下输出,说明PHP和Apache环境均已经成功搭建。
至此,PHP开发环境的安装与配置工作就完成了。
The above is the detailed content of Building PHP development environment under windows. For more information, please follow other related articles on the PHP Chinese website!