System: Windows 7 64-bit system
Before installation, download the software first:
Nginx: http://nginx.org/en/download.html
PHP Stable PHP 5.6.26: http://php.net/downloads.php
mysql: http://dev.mysql.com/downloads/utilities/
Step one: Create the folder Nginx+php+Mysql on the D drive, the path is: D:Nginx+php+Mysql
Step 2: Install Nginx, the installation directory is: D:Nginx+php+Mysqlnginx
1. Open the D:Nginx+php+Mysqlnginx directory and run nginx.exe in this folder
2. Test whether nginx is started. Open the browser and visit http://localhost or http://127.0.0.1 and see if "Welcome to nginx!" appears. The appearance proves that the startup has been successful.
If the startup fails, check whether the port is occupied.
Install PHP, the installation directory is: D:Nginx+php+Mysqlphp
Install mySQL, the installation directory is: D:Nginx+php+Mysqlmysql
Step 3: Modify Nginx’s conf file: the directory is D:Nginx+php+Mysqlnginxconf
File name: nginx.conf
1. Remove the # before worker_processes and start a process
2. Add events
3. Set http->set server->support php
<span style="color: #000000;">#user nobody; worker_processes </span><span style="color: #800080;">1</span><span style="color: #000000;">; #error_log logs</span>/<span style="color: #000000;">error.log; #error_log logs</span>/<span style="color: #000000;">error.log notice; #error_log logs</span>/<span style="color: #000000;">error.log info; #pid logs</span>/<span style="color: #000000;">nginx.pid; events { worker_connections </span><span style="color: #800080;">1024</span><span style="color: #000000;">; } http { include mime.types; default_type application</span>/octet-<span style="color: #000000;">stream; #log_format main </span><span style="color: #800000;">'</span><span style="color: #800000;">$remote_addr - $remote_user [$time_local] "$request" </span><span style="color: #800000;">'</span><span style="color: #000000;"> # </span><span style="color: #800000;">'</span><span style="color: #800000;">$status $body_bytes_sent "$http_referer" </span><span style="color: #800000;">'</span><span style="color: #000000;"> # </span><span style="color: #800000;">'</span><span style="color: #800000;">"$http_user_agent" "$http_x_forwarded_for"</span><span style="color: #800000;">'</span><span style="color: #000000;">; #access_log logs</span>/<span style="color: #000000;">access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout </span><span style="color: #800080;">0</span><span style="color: #000000;">; keepalive_timeout </span><span style="color: #800080;">65</span><span style="color: #000000;">; #gzip on; server { listen </span><span style="color: #800080;">80</span><span style="color: #000000;">; server_name localhost; #charset koi8</span>-<span style="color: #000000;">r; #access_log logs</span>/<span style="color: #000000;">host.access.log main; location </span>/<span style="color: #000000;"> { root d:</span>/Nginx+php+Mysql/nginx/<span style="color: #000000;">html; index index.html index.htm; }</span><span style="color: #000000;"> error_page </span><span style="color: #800080;">500</span> <span style="color: #800080;">502</span> <span style="color: #800080;">503</span> <span style="color: #800080;">504</span> /<span style="color: #000000;">50x.html; location </span>= /<span style="color: #000000;">50x.html { root html; }</span><span style="color: #000000;"> # pass the PHP scripts to FastCGI server listening on </span><span style="color: #800080;">127.0</span>.<span style="color: #800080;">0.1</span>:<span style="color: #800080;">9000</span><span style="color: #000000;"> # location </span>~<span style="color: #000000;"> \.php$ { root html; fastcgi_pass </span><span style="color: #800080;">127.0</span>.<span style="color: #800080;">0.1</span>:<span style="color: #800080;">9000</span><span style="color: #000000;">; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }</span><span style="color: #000000;"> } }</span>
Test whether nginx is installed successfully
Step 4: Modify the php.ini-development file under php, change the file name to php.ini, and find php.ini:
Search for "extension_dir" and find extension_dir = "ext". First remove the semicolon in front and change it to extension_dir = "./ext"
Search for "php_mysql" and find: "extension=php_mysql.dll and extension=php_mysqli.dll. Remove the ";" extension=php_mysql.dll and extension=php_mysqli.dll (supports MYSQL database)
Check whether php is installed successfully:
Step 4: Create a new file php-cgi.vbs in the php directory and start php-cgi with the php-cgi.vbs file:
Open php-cgi.vbs and write the startup code:
<span style="color: #0000ff;">set</span> wscriptObj = CreateObject(<span style="color: #800000;">"</span><span style="color: #800000;">Wscript.Shell</span><span style="color: #800000;">"</span><span style="color: #000000;">) wscriptObj.run </span><span style="color: #800000;">"</span><span style="color: #800000;">php-cgi -b 127.0.0.1:9000</span><span style="color: #800000;">"</span>,<span style="color: #800080;">0</span>
Step 5: Create new startup items in the D:Nginx+php+Mysql directory: runServer.bat and stop items stopServer.bat
In the startup item runServer.bat, enter:
<span style="color: #000000;">@echo off echo Starting nginx... cd </span>%~<span style="color: #000000;">dp0nginx start </span><span style="color: #800000;">""</span> <span style="color: #800000;">"</span><span style="color: #800000;">./nginx.exe</span><span style="color: #800000;">"</span><span style="color: #000000;"> echo Starting mysql... net start mysql echo Starting PHP FastCGI... cd </span>%~<span style="color: #000000;">dp0PHP start </span><span style="color: #800000;">""</span> <span style="color: #800000;">"</span><span style="color: #800000;">php-cgi.vbs</span><span style="color: #800000;">"</span><span style="color: #000000;"> pause Exit</span>
Enter in the stop field:
<span style="color: #000000;">@echo off echo Stopping nginx... taskkill </span>/F /IM nginx.exe ><span style="color: #000000;"> nul echo Stopping PHP FastCGI... taskkill </span>/F /IM php-cgi.exe ><span style="color: #000000;"> nul echo Stopping mysql... net stop mysql pause exit</span>
Finally, check whether the startup is successful:
In the html directory of nginx, D:Nginx+php+Mysqlnginxhtml, create a new phpinfo.php
Write:
<?<span style="color: #000000;">php phpinfo(); </span>?>
Enter the path to phpinfo.php in the browser to check whether the configuration is successful: