search
HomeBackend DevelopmentPHP ProblemHow to build a PHP environment under Windows system

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. If there is any infringement, please contact admin@php.cn delete
ACID vs BASE Database: Differences and when to use each.ACID vs BASE Database: Differences and when to use each.Mar 26, 2025 pm 04:19 PM

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

PHP Secure File Uploads: Preventing file-related vulnerabilities.PHP Secure File Uploads: Preventing file-related vulnerabilities.Mar 26, 2025 pm 04:18 PM

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

PHP Input Validation: Best practices.PHP Input Validation: Best practices.Mar 26, 2025 pm 04:17 PM

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

PHP API Rate Limiting: Implementation strategies.PHP API Rate Limiting: Implementation strategies.Mar 26, 2025 pm 04:16 PM

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

PHP Password Hashing: password_hash and password_verify.PHP Password Hashing: password_hash and password_verify.Mar 26, 2025 pm 04:15 PM

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

OWASP Top 10 PHP: Describe and mitigate common vulnerabilities.OWASP Top 10 PHP: Describe and mitigate common vulnerabilities.Mar 26, 2025 pm 04:13 PM

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

PHP XSS Prevention: How to protect against XSS.PHP XSS Prevention: How to protect against XSS.Mar 26, 2025 pm 04:12 PM

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

PHP Interface vs Abstract Class: When to use each.PHP Interface vs Abstract Class: When to use each.Mar 26, 2025 pm 04:11 PM

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.