Windows下nginx+php环境的配置
1、首先需要准备的应用程序包。 nginx:nginx/Windows-1.0.4 php:php-5.2.16-nts-Win32-VC6-x86.zip(nginx下php是以FastCGI的方式运行,所以我们下载非线程安全也就是nts的php包) (还会用到)RunHiddenConsole:RunHiddenConsole.zip 2、安装与配置。 1
1、首先需要准备的应用程序包。
nginx:nginx/Windows-1.0.4
php:php-5.2.16-nts-Win32-VC6-x86.zip (nginx下php是以FastCGI的方式运行,所以我们下载非线程安全也就是nts的php包)
(还会用到)RunHiddenConsole:RunHiddenConsole.zip
2、安装与配置。
1)php的安装与配置。
直接解压下载好的php包,到D盘wnmp目录(D:\wnmp),这里把解压出来的文件夹重命名成php5。进入文件夹修改php.ini-recommended文件为php.ini,并用Editplus或者Notepad++打开来。找到
extension_dir = <span>"</span><span>./ext</span><span>"</span>
更改为
extension_dir = <span>"</span><span>D:/wnmp/php5/ext</span><span>"</span>
;extension=php_mysql.dll ;extension=php_mysqli.dll
前面指定了php的ext路径后,只要把需要的扩展包前面所对应的“;”去掉,就可以了。这里打开php_mysql.dll和php_mysqli.dll,让php支持mysql。当然不要忘掉很重要的一步就是,把php5目录下的libmysql.dll文件复制到C:\Windows目录下,也可以在系统变量里面指定路径,当然这里我选择了更为方便的方法^_^。
到这里,php已经可以支持mysql了。
接下来我们来配置php,让php能够与nginx结合。找到
;cgi.fix_pathinfo=<span>1</span>
我们去掉这里的封号。
cgi.fix_pathinfo=<span>1</span>
2)nginx的安装与配置。
把下载好的nginx-1.0.4的包同样解压到D盘的wnmp目录下,并重命名为nginx。接下来,我们来配置nginx,让它能够和php协同工作。进入nginx的conf目录,打开nginx的配置文件nginx.conf,找到
location / { root html; #这里是站点的根目录 index index.html index.htm; }
将root html;改为root D:/wnmp/www;
再往下,找到
# pass the PHP scripts to FastCGI server listening on <span>127.0</span>.<span>0.1</span>:<span>9000</span> # #location ~ \.php$ { # root html; # fastcgi_pass <span>127.0</span>.<span>0.1</span>:<span>9000</span>; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME <span>/</span><span>scripts</span>$fastcgi_script_name; # include fastcgi_params; #}
先将前面的“#”去掉,同样将root html;改为root D:/wnmp/www;。再把标记为红色的/scripts改为“$document_root”,这里的“$document_root”就是指前面“root”所指的站点路径,这是改完后的:
# pass the PHP scripts to FastCGI server listening <span>on</span> 127.0.0.1:9000 # location ~ \.php$ { root <span>D:</span><span>/wnmp/www;</span> fastcgi_pass <span>127.0.0.1<span>:</span>9000</span>; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME <span>$document_root</span>$fastcgi_script_name; include fastcgi_params; }
保存配置文件,就可以了。
nginx+php的环境就初步配置好了,来跑跑看。我们可以输入命令
来启动php,并手动启动nginx,当然也可以利用脚本来实现。
首先把下载好的RunHiddenConsole.zip包解压到nginx目录内,RunHiddenConsole.exe的作用是在执行完命令行脚本后可以自动关闭脚本,而从脚本中开启的进程不被关闭。然后来创建脚本,命名为“start_nginx.bat”,我们在Notepad++里来编辑它
<span>@echo</span> <span>off</span> <span>REM</span><span> Windows 下无效</span><span> REM</span><span> set PHP_FCGI_CHILDREN=5</span> <span>REM</span><span> 每个进程处理的最大请求数,或设置为 Windows 环境变量</span><span>set</span> PHP_FCGI_MAX_REQUESTS=1000 <span>echo</span> Starting PHP FastCGI... RunHiddenConsole D:/wnmp/php5/php-cgi.exe -b 127.0.0.1:9000 -c D:/wnmp/php5/php.ini <span>echo</span> Starting nginx... RunHiddenConsole D:/wnmp/nginx/nginx.exe -p D:/wnmp/nginx
再另外创建一个名为stop_nginx.bat的脚本用来关闭nginx
<span>@echo</span> <span>off</span> <span>echo</span> Stopping nginx... taskkill /F /IM nginx.exe > nul <span>echo</span> Stopping PHP FastCGI... taskkill /F /IM php-cgi.exe > nul <span>exit</span>
做好后,是这样的
这样,我们的服务脚本也都创建完毕了。双击start_nginx.bat看看进程管理器是不是有两个nginx.exe的进程和一个php-cgi.exe的进程呢?
这样nginx服务就启动了,而且php也以fastCGI的方式运行了。
到站点目录下,新建一个phpinfo.php的文件,在里面编辑
<?php <span>phpinfo(); ?>
保存后,打开浏览器输入“http://localhost/phpinfo.php”,如果看到
就说明,nginx+php的环境已经配置好了,呵呵~
我安装时候遇到的问题:
1. 我已经安装了apache了占用了80端口,怎么办?
解决方法:方法一:如果不想改变nginx的http默认端口(即也是80),那么在用nginx的时候不要启动apache
方法二:在nginx.conf中修改 server 下listen 端口值(如我的:listen 81)就可以同时用apache和nginx访问网页
2. nginx可以正常启动了,可以正常访问页面 http://127.0.0.1:81/index.html,但是不能访问php文件???
我的配置都是按上面配置的,但是发现在资源管理器中不能启动php-cgi.exe,这是为什么???
找到原因:在cmd 命令窗口里输入:netstat -anob 查看9000端口被KugouService占用了,所以不能正常启动,关闭酷狗,点击start_nginx.bat,就可以了,一切Ok
总之,一步一步来,nginx是否安装好,可以看是否能正常访问普通.html页面,php与mysql是否安装好,看phpinfo()信息,php与nginx的是否连接好,运行php文件,动手做,慢慢找原因!!!!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

ETA Prime recently showcased a paid software called Lossless Scaling on ROG Ally X. While it doesn't actually improve the actual gaming performance, the software enhances the experience by adding frame generation and resolution scaling. These two can

The way to update ByBit exchanges varies by platform and device: Mobile: Check for updates and install in the app store. Desktop Client: Check for updates in the Help menu and install automatically. Web page: You need to manually access the official website for updates. Failure to update the exchange can lead to security vulnerabilities, functional limitations, compatibility issues and reduced transaction execution efficiency.

DeepSeek is a powerful intelligent search and analysis tool that provides two access methods: web version and official website. The web version is convenient and efficient, and can be used without installation; the official website provides comprehensive product information, download resources and support services. Whether individuals or corporate users, they can easily obtain and analyze massive data through DeepSeek to improve work efficiency, assist decision-making and promote innovation.

Detailed explanation and installation guide for PiNetwork nodes This article will introduce the PiNetwork ecosystem in detail - Pi nodes, a key role in the PiNetwork ecosystem, and provide complete steps for installation and configuration. After the launch of the PiNetwork blockchain test network, Pi nodes have become an important part of many pioneers actively participating in the testing, preparing for the upcoming main network release. If you don’t know PiNetwork yet, please refer to what is Picoin? What is the price for listing? Pi usage, mining and security analysis. What is PiNetwork? The PiNetwork project started in 2019 and owns its exclusive cryptocurrency Pi Coin. The project aims to create a one that everyone can participate

There are many ways to install DeepSeek, including: compile from source (for experienced developers) using precompiled packages (for Windows users) using Docker containers (for most convenient, no need to worry about compatibility) No matter which method you choose, Please read the official documents carefully and prepare them fully to avoid unnecessary trouble.

Microsoft has just announced a new Compact Mode for Xbox Game Bar, with a focus on making the overlay more usable on Windows gaming handhelds. These devices usually come with screens that are smaller than 9 inches, and things that are designed for re

Using light to train neural networks, Tsinghua University results were recently published in Nature! What should I do if I cannot apply the backpropagation algorithm? They proposed a Fully Forward Mode (FFM) training method that directly performs the training process in the physical optical system, overcoming the limitations of traditional digital computer simulations. To put it simply, it used to be necessary to model the physical system in detail and then simulate these models on a computer to train the network. The FFM method eliminates the modeling process and allows the system to directly use experimental data for learning and optimization. This also means that training no longer needs to check each layer from back to front (backpropagation), but can directly update the parameters of the network from front to back. To use an analogy, like a puzzle, backpropagation

The official website entrance of the Coinsuper Exchange: https://www.coinsuper.com. The client download channels are: Windows client, macOS client, and mobile (iOS/Android). Registration requires an email, mobile phone number and password, and you need to complete real-name authentication before you can trade. The platform provides a variety of digital asset transactions, including Bitcoin, Ethereum, etc., with the transaction fee rate of 0.1% for both orders and acceptors. Security safeguards include cold wallet storage, dual-factor verification, anti-money laundering and anti-terrorism financing measures, and with security public
