Home php教程 php手册 Windows上安装PHP开发测试环境

Windows上安装PHP开发测试环境

Jun 06, 2016 pm 08:08 PM
php windows Install develop test environment

先从HTTP请求处理流程图来看看我们所需的PHP开发测试环境包含哪些组件。 从图中可以看出系统包含如下几种组件之间的交互: Nginx与PHP-CGI(PHP)的交互 PHP-CGI(PHP)与文件系统、分布式内存对象缓存系统、数据库之间的交互 除了PHP与文件系统之间的交互,其他

先从HTTP请求处理流程图来看看我们所需的PHP开发测试环境包含哪些组件。

PHP开发测试环境

从图中可以看出系统包含如下几种组件之间的交互:

  • Nginx与PHP-CGI(PHP)的交互
  • PHP-CGI(PHP)与文件系统、分布式内存对象缓存系统、数据库之间的交互

除了PHP与文件系统之间的交互,其他几种交互均为客户端-服务器模式,以Socket方式进行连接,都需要安装配置相关组件。

对于Nginx与PHP-CGI(PHP)的交互,PHP-CGI默认打开9000端口,等待Nginx转发过来的请求,所以需要在Nginx配置文件中添加类似于如下所示的虚拟主机配置:

server {
    listen  8000;
    server_name localhost;
    location / {
        root    html;   # 这里为你的网站的根目录
        index   index.php index.html index.htm;
    }
    location ~ \.php$ {
        root    html;   # 这里也设置为你的网站的根目录
        fastcgi_pass    127.0.0.1:9000; # 这里设置为你的PHP-CGI监听的网络地址
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
Copy after login

在Windows上,直接双击运行php-cgi.exe文件打开PHP-CGI服务,貌似没用,可以在CMD中执行php-cgi.exe -b 127.0.0.1:9000来打开服务。

对于Nginx.exe,可以直接双击nginx.exe来运行,但如果要停止nginx的运行或者重新加载配置文件,则可以在CMD中执行如下相应的命令:

nginx -s stop   fast shutdown
nginx -s quit   graceful shutdown
nginx -s reload  changing configuration, starting new worker processes with a new configuration, graceful shutdown of old worker processes
nginx -s reopen re-opening log files
Copy after login

另外,Nginx的虚拟主机配置信息中,root指令指定的网站根目录路径应遵从Unix的格式,而不是Windows的格式,即使用/而不是\来分割目录层次。

Nginx与PHP的Windows版本可分别从:Nginx for Windows,PHP for Windows。无需安装,解压缩即可。PHP-CGI的可执行文件php-cgi.exe也在PHP的压缩包中。


对于分布式内存对象系统,以Memcached和Redis为例。PHP通过扩展包与它们交互,所以需要下载相应的扩展包,并配置PHP。

以PHP 5.3版本为例,可分别从http://downloads.php.net/pierre/、http://blog.phpwind.me/wp-content/plugins/download-monitor/download.php?id=9下载PHP的memcached扩展包与redis扩展包,注意扩展包对应的php版本号必须与你安装的PHP的版本号一致。

解压缩后将php_memcache.dll和php_redis.dll文件复制到PHP的ext目录下。

然后将PHP目录下的php.ini-development文件重命名为php.ini,打开php.ini,首先删除;extension_dir="ext"一行行首的分号,然后删除;extension=php_memcache.dll一行行首的分号,并在其后添加一行extension=php_redis.dll

对于Memcached和Redis的服务器端程序,可分别从:Memcached for Windows、Redis for Windows下载。

Memcached的默认端口为11211。

关于Redis的配置见:http://redis.io/topics/config

关于windows下redis和php的redis扩展的安装,可进一步参考http://blog.phpwind.me/?p=152


PHP与MySQL之间的交互,类似于PHP与分布式内存对象系统之间的交互。只不过PHP的压缩包的ext目录下已经包含了php_mysql.dllphp_mysqli.dll扩展包,只需修改php.ini配置文件即可:删除;extension=php_mysql.dll;extension=php_mysqli.dll两行行首的分号。

MySQL的服务器端程序从MySQL官网下载,默认端口为3306。


除了上述安装配置,你可能还需要在php.ini中启用extension=php_mbstring.dllextension=php_soap.dll等扩展。


安装配置完毕后,启动Nginx、PHP-CGI、MySQL(可选)、Redis/Memcached(可选)。在某个Nginx虚拟主机中指定的网站根目录下添加测试文件phpinfo.php,其内容如下:

<?php phpinfo();
?>
Copy after login

通过浏览器访问该网页,若PHP环境配置成功,则会看到一个当前PHP环境的详细信息列表,从中可以看到当前所启动的PHP扩展,若未找到memcache、redis、mysql这几个扩展包信息,则说明未成功启用。


如果你测试某些以前别人写的PHP代码,发现结果与预期的不相符,则看看是不是那些代码中使用了PHP短标记?>。PHP默认不启用短标记,所以你需要修改php.ini,删除;short_open_tag = On一行之前的分号。

另外,注意Nginx虚拟主机所使用的端口不要和Windows中其他网络应用的端口冲突。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

Why can't my code get the data returned by the API? How to solve this problem? Why can't my code get the data returned by the API? How to solve this problem? Apr 01, 2025 pm 08:09 PM

Why can't my code get the data returned by the API? In programming, we often encounter the problem of returning null values ​​when API calls, which is not only confusing...

Four ways to implement multithreading in C language Four ways to implement multithreading in C language Apr 03, 2025 pm 03:00 PM

Multithreading in the language can greatly improve program efficiency. There are four main ways to implement multithreading in C language: Create independent processes: Create multiple independently running processes, each process has its own memory space. Pseudo-multithreading: Create multiple execution streams in a process that share the same memory space and execute alternately. Multi-threaded library: Use multi-threaded libraries such as pthreads to create and manage threads, providing rich thread operation functions. Coroutine: A lightweight multi-threaded implementation that divides tasks into small subtasks and executes them in turn.

Explain the match expression (PHP 8 ) and how it differs from switch. Explain the match expression (PHP 8 ) and how it differs from switch. Apr 06, 2025 am 12:03 AM

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.

Where to download Python .whl files under Windows? Where to download Python .whl files under Windows? Apr 01, 2025 pm 08:18 PM

Python binary library (.whl) download method explores the difficulties many Python developers encounter when installing certain libraries on Windows systems. A common solution...

How to monitor system performance through Debian logs How to monitor system performance through Debian logs Apr 02, 2025 am 08:00 AM

Mastering Debian system log monitoring is the key to efficient operation and maintenance. It can help you understand the system's operating conditions in a timely manner, quickly locate faults, and optimize system performance. This article will introduce several commonly used monitoring methods and tools. Monitoring system resources with the sysstat toolkit The sysstat toolkit provides a series of powerful command line tools for collecting, analyzing and reporting various system resource metrics, including CPU load, memory usage, disk I/O, network throughput, etc. The main tools include: sar: a comprehensive system resource statistics tool, covering CPU, memory, disk, network, etc. iostat: disk and CPU statistics. mpstat: Statistics of multi-core CPUs. pidsta

See all articles