Home  >  Article  >  Backend Development  >  How to build a PHP environment under Windows system

How to build a PHP environment under Windows system

醉折花枝作酒筹
醉折花枝作酒筹forward
2021-05-24 17:43:033827browse

This article will introduce to you how to build a PHP environment under Windows system. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

How to build a PHP environment under Windows system

#1. The prerequisite for building a PHP environment is that the Apache HTTP Server (Apache server) has been successfully installed and deployed, and the main page of the server can be accessed normally. The installation and deployment of Apache HTTP Server has been explained in detail in the previous article. If you are unclear, you can click "Apache HTTP Servcer-Apache Server Download and Installation under Windows System" to view the specific operations.

2. PHP download:

2.1. Download address: http://php.net/downloads.php

2.1. Version selection: If paired with Apache, It is recommended to choose the Thread Safe version; if it is used with CGI or FAST-CGI, it is recommended to choose the Non Thread Safe version.

3. PHP environment setup:

3.1. Extract the downloaded .zip compressed package to the specified installation directory. The installation path here is: D:\solt\php_5.6.33.

3.2. Copy php.ini-development or php.ini-production in the root directory of PHP and rename it to php.ini as the PHP configuration file;

3.3. Open php.ini and modify the configuration information:

Note: a. The comment in the ini file is a semicolon (English semicolon), so if you uncomment, delete the semicolon;

b, ${ phphome} is the root directory of PHP, that is: D:\solt\php_5.6.33, and the absolute path is written in the configuration file.

3.3.1. Modify the path of the extension file:

; extension_dir = "ext"

Uncomment, or change it to:

extension_dir = "${phphome}\ext";

Note: If it is used with Apache, it is recommended to change the path of the extension file Change it to an absolute path because it may not be loaded.

3.3.2. Modify the extension file that needs to be loaded. The following code is the code after uncommenting some extensions:

extension=php_bz2.dll
extension=php_curl.dll
extension=php_fileinfo.dll
extension=php_gd2.dll
extension=php_gettext.dll
;extension=php_gmp.dll
;extension=php_intl.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
extension=php_mbstring.dll
extension=php_exif.dll      ; Must be after mbstring as it depends on it
extension=php_mysql.dll
extension=php_mysqli.dll
;extension=php_oci8_12c.dll  ; Use with Oracle Database 12c Instant Client
extension=php_openssl.dll
;extension=php_pdo_firebird.dll
extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
extension=php_pdo_odbc.dll
extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll
extension=php_pgsql.dll
;extension=php_shmop.dll

; The MIBS data available in the PHP distribution must be installed. 
; See http://www.php.net/manual/en/snmp.installation.php 
;extension=php_snmp.dll

extension=php_soap.dll
extension=php_sockets.dll
extension=php_sqlite3.dll
;extension=php_sybase_ct.dll
extension=php_tidy.dll
extension=php_xmlrpc.dll
extension=php_xsl.dll

3.3.3. Set the default time zone:

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone 选择时区列表网址
date.timezone = Asia/Shanghai

3.3.4. Set up ssl:

[openssl]
; The location of a Certificate Authority (CA) file on the local filesystem
; to use when verifying the identity of SSL/TLS peers. Most users should
; not specify a value for this directive as PHP will attempt to use the
; OS-managed cert stores in its absence. If specified, this value may still
; be overridden on a per-stream basis via the "cafile" SSL stream context
; option.
openssl.cafile= cacert.pem

You can add extensions according to your needs.

3.4. Modify httpd.conf in the Apache24\conf\ directory to configure Apache so that Apache and PHP can work together;

3.4.1. DocumentRoot settings:

Before modification : The default is the htdocs directory under Apache24:

After modification: Specify a custom path, but remember this path.

##3.4.2. Modify the default index to support PHP:

Before modification:

# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

After modification:

# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html index.php index.htm
</IfModule>

3.4.3. Turn on the rewrite function: remove the # in front of the following line of code:

LoadModule rewrite_module modules/mod_rewrite.so

3.4.4. Load the PHP module, pay attention to the absolute path:

If it is PHP 5. Add the following code at the end of the httpd.conf file:

#php5.6
LoadModule php5_module D:/soft/php-5.6.33/php5apache2_4.dll 
<IfModule php5_module> 
    PHPIniDir "D:/soft/php-5.6.33/" 
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
</IfModule>

If it is PHP 7, change it accordingly. The example is as follows:

#php7
LoadModule php7_module D:/soft/php-7.x.x/php7apache2_4.dll
<IfModule php7_module> 
    PHPIniDir "D:/soft/php-7.x.x/" 
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
</IfModule>

3.5. If the PHP x64 version is installed, Apache It also needs to be the x64-bit version. Then copy the four files including libeay32.dll, ssleay32.dll, libssh2.dll in the php directory and php_curl.dll in the ext directory to the System32 directory. Otherwise the curl extension cannot be used. Reference link: http://my.oschina.net/lsfop/blog/496181. No verification is done, just follow the instructions and display normally.

4. Start the Apache PHP running test:

4.1. In the D:\soft\php_5.6.33\www directory, create the index.php file with the following text content:

<?php
echo phpinfo();
?>

4.2. Restart the Apache service, open the browser address bar and enter: localhost:8081/index.php or 127.0.0.1:8081/index.php to open the PHP page.

Finally, the PHP environment can be built with the help of the PHP development environment building tool. Download address: http://www.php.cn/xiazai/gongju or http://www.wampserver.com/ , I will not introduce the tool installation method here.

Recommended learning:

php video tutorial

The above is the detailed content of How to build a PHP environment under Windows system. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete