Windows7 configuration Nginx+php+mysql Detailed tutorial _php instance

Source: Internet
Author: User
Tags db connect goto install php win32

Recently in the study of PHP, want to record their learning experience, and write some experience, only for reference exchange. This article is suitable for those who just contact PHP, want to learn and want to build their own nginx+php+mysql environment of students.

Of course, you can also choose to integrate a good installation package, such as Wamp, but I recommend that you or yourself to build a good environment, so that you can better understand PHP and its running process. Let's go straight to the bottom.

Steps:

1. Prepare installation package, etc.

(1) nginx-1.10.1.zip, download link for http://nginx.org/en/download.html. I personally chose the stable version.

(2) php-5.6.25-nts-win32-vc11-x86.zip or x64.zip download link is http://windows.php.net/download#php-5.6, select the appropriate version according to the system type.

(3) mysql-installer--------. msi download link for http://dlsw.baidu.com/sw-search-sp/soft/ea/12585/ Mysql-5.6.24-win32.1432006610.zip, because MySQL official website need to register, so I directly posted the address of Baidu.

2. Install MySQL service (If you have previously installed MySQL, you can not download the installation, when the operation of the MySQL service to start.) )

Double-click the Mysql-install-------. MSI installation package to enter the installation environment interface, select the default option to install, use typical (typical installation), and start the MySQL Configuration Wizard, select the default option configuration, the encoding select UTF-8, after setting the database password ( typically root), execute, and click Finish to complete the installation. To make sure that the MySQL service is turned on, check to see if the service is open by Win+r enter Services.msc carriage return and check for the MySQL service and start status as shown in the following figure.

3. Install nginx-1.10.1

(1) Extract nginx-1.10.1.zip files to C:\wnmp\nginx, and enter the folder, find Nginx.exe, mouse double-click Nginx.exe, start Nginx.

Go to the Task Manager Process tab, and if you find the Nginx.exe process, confirm that Nginx is started.

Open the browser, in the browser address bar type: http://127.0.0.1, as seen in the following image of the interface, instructions nginx normal work.

(2) Enter the C:\wnmp\nginx\conf folder, Notepad or WordPad to open the Nginx profile nginx.conf

Find the following two changes to modify the content as follows

server {
listen;
server_name localhost;
#modify by Lee 20160902 for php-s
location/{
root c:/wnmp/www;
Index index.html index.htm index.php;
}
# Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
location ~ \.php$ {
root c:/wnmp/www;
Fastcgi_pass 127.0.0.1:9001;
Fastcgi_index index.php;
Fastcgi_param script_filename $document _root$fastcgi_script_name;
Include Fastcgi_params;
}
#modify by Lee 20160902 for Php-e
}

4. Install Php-5.6.25-nts-win32-vc11-x64/x86

(1) Extract php-5.6.25-nts-win32-vc11-x64/x86.zip files to C:\wnmp\php.

(2) into the C:\wnmp\php directory, backup php.ini-development a copy, the php.ini-development renamed to PHP.ini

Find positioning and modify:

; Extension_dir = "ext", remove the preceding semicolon and modify it to: Extension_dir = "C:/wnmp/php/ext"

; extension=php_gd2.dll, remove the preceding semicolon: Extension=php_gd2.dll

; extension=php_mbstring.dll, remove the preceding semicolon: Extension=php_mbstring.dll

; extension=php_mysql.dll, remove the preceding semicolon: Extension=php_mysql.dll

; extension=php_mysqli.dll, remove the preceding semicolon: Extension=php_mysqli.dll

; extension=php_pdo_mysql.dll, remove the preceding semicolon: Extension=php_pdo_mysql.dll

; cgi.force_redirect = 1, removing the preceding semicolon: Cgi.force_redirect = 1

; cgi.fix_pathinfo=1, remove the preceding semicolon: cgi.fix_pathinfo=1

; cgi.rfc2616_headers = 0, removing the preceding semicolon: Cgi.rfc2616_headers = 1

(3) Configure environment variables:

Open the Environment Variable configuration window,

To add a variable variable name to a system environment variable: Php_home variable value: C:\wnmp\php

To add a variable variable name to a system environment variable: Nginx_home variable value: C:\wamp\nginx

At the end of the path variable add:%php_home%;%nginx_home%; (Note adding semicolons)

(4) Start php-cgi service:

Win+r Enter cmd carriage return, enter the command prompt interface, enter C:\WNMP\PHP>

Use the command php-cgi.exe-b 127.0.0.1:9001-c php.ini

Reopen a new command prompt interface,

Enter command: NETSTAT-ANO|FINDSTR "9001" will show 9001 port number occupancy

Re-enter the command: Tasklist|findstr "2892" (note: 2892 The process number shown in the last column after completion of the previous command)

As shown in the following figure: Indicates that the PHP-CGI service started successfully

(5) Write a startup script Start.bat (in fact, the previous step, has been configured to complete, but in order to facilitate the launch of a variety of services, a startup script is written. )

Create a new text document and rename it to Start.bat

When you open it with Notepad, edit it as follows:

(If the file directory is exactly the same as the one described in this tutorial, this script can be used directly, and if there is a difference, it needs to be modified with Nginx_dir and Php_dir)

@echo off REM The use of bat echo ==================begin======================== cls SET nginx_path=c:set nginx_dir=c: 
\wnmp\nginx\ SET php_dir=c:\wnmp\php\ Color 0a TITLE nginx Manager CLS ECHO. ECHO. 
* Nginx Manage App * ECHO. : MENU ECHO. 
* Nginx Process List * tasklist|findstr/i "Nginx.exe" ECHO. ECHO. [1] Start Nginx ECHO. [2] Stop Nginx ECHO. [3] Restart Nginx ECHO. 
[4] Exit ECHO. ECHO. Please input the number:set/p id= if "%id%" = = "1" goto start if "%id%" = "2" GOTO stop If "%id%" = 3 "GOTO Restart if" %id% "=" 4 "EXIT pause:start call:startnginx call:startphpfastcgi GOTO menu:stop call:shutdownnginx GOTO menu:rest 
Art Call:shutdownnginx Call:startnginx GOTO menu:shutdownnginx ECHO. ECHO. Stop Nginx ... taskkill/f/im nginx.exe > Nul ECHO.
Stopping PHP FastCGI ... ECHO. 
Ok,stop all Nginx process and PHP fastcgi Goto:eof:startNginx ECHO. ECHO. 
Start Nginx ... 
IF not EXIST "%nginx_dir%nginx.exe" ECHO "%nginx_dir%nginx.exe" are NOT exists%nginx_path% CD "%nginx_dir%" IF EXIST "%nginx_dir%nginx.exe" (echo "Start" Nginx.exe "Start" "Nginx.exe") echo. 
OK Goto:eof:startPhpFastCGI ECHO. ECHO.
Start PHP FastCGI ... If not EXIST "%php_dir%php-cgi.exe" ECHO "%php_dir%php-cgi.exe" are NOT exists%nginx_path% CD "%php_dir%" If EXIST "%ph" P_dir%php-cgi.exe "(echo" Start "Php-cgi.exe" start/b php-cgi.exe-b 127.0.0.1:9001-c php.ini) echo. OK goto:eof

(6) Successful test

Create a new WWW folder under C:\WNMP, create a new PHP file index.php under the WWW folder, and edit it as follows

The following mysqli_connect () Code section needs to be changed accordingly.

 
 

Double-click the above start.bat script file and press ENTER after 1 keyboard input

As shown in the following illustration, it means that nginx-php started successfully

Open the browser, in the browser address bar type: http://127.0.0.1, as seen in the following image of the interface, indicating the success of WNMP configuration.

At this point, WNMP configuration success!

The above is a small set to introduce the Windows7 configuration nginx+php+mysql detailed tutorials, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.