Windows7 Configuring Nginx+php+mysql Tutorials

Source: Internet
Author: User
Tags db connect goto

Windows7 Configuring Nginx+php+mysql Tutorials

  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 students who have just contacted PHP, want to learn and want to build their own nginx+php+mysql environment.

  Of course, you can also choose to integrate a good installation package, such as Wamp, but I recommend you to manually set up a good environment, so that better understand PHP and its running process. The following goes straight to the chase.

Steps:

1. Preparing the 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 the MySQL official website needs to register, so I directly posted Baidu's address.

2. Installing the MySQL service (If you have previously installed MySQL, you may not have to download the installation and start the MySQL service at the time of operation.) )

Double-click the Mysql-install-------. MSI installation package to enter the installation environment interface, select the default option to install, take typical (typical installation), and start the MySQL Configuration Wizard, select the default option configuration, here encoding select UTF-8, after setting the database password ( typically root), execute executes, and click Finish to complete the installation. to ensure that the MySQL service is turned on, check that the service is turned on by: Win+r Enter services.msc carriage return to see if there is a MySQL service as shown and is in the start state.

      

3. Installing nginx-1.10.1

 (1) Extract Nginx-1.10.1.zip file 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, if you find the Nginx.exe process, confirm that Nginx is started.

Open the browser, type: http://127.0.0.1 in the browser address bar, as shown in the interface, stating that Nginx is working properly.

      。

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

Find the following two places to modify the content as follows

Server {Listen80;server_name localhost;#modify by Lee 20160902For php-s location/{root c:/wnmp/www;Index index.html index.htm index.php;# Pass the PHP scripts to FastCGI server listening on127.0.0.1:9000Location ~ \.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 Lee20160902For php-e}

4. Installing php-5.6.25-nts-win32-vc11-x64/x86

  (1) Unzip the Php-5.6.25-nts-win32-vc11-x64/x86.zip file to C:\wnmp\php.

(2) Enter C:\wnmp\php directory, backup php.ini-development one copy, rename php.ini-development to PHP.ini

Find location and modify:

; Extension_dir = "ext", delete 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, remove the preceding semicolon: Cgi.force_redirect = 1

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

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

(3) Configure environment variables:

Open the Environment Variables Configuration window,

Add variable variable name to system environment variable: Php_home variable value: C:\wnmp\php

Add variable variable name to system environment variable: Nginx_home variable value: C:\wamp\nginx

Added at the end of the path variable:%php_home%;%nginx_home%; (Note add semicolons)

(4) Start php-cgi service:

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

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

Re-open a new command prompt interface,

Input command: NETSTAT-ANO|FINDSTR "9001" will appear 9001 port number occupancy

Enter the command again: Tasklist|findstr "2892" (Note: 2892 is the process number shown in the last column after execution of the previous command)

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

      

(5) Write the startup script Start.bat (in fact, up to the previous step, has been configured to complete, but in order to facilitate the start of various services later, write a startup script.) )

New text document, renamed to Start.bat

After opening with Notepad, make the following edits:

(if the file directory is exactly the same as described in this tutorial, this script can be used directly, if there is a difference, you need to Nginx_dir and Php_dir To be used after the corresponding modification)

@echo Offrem the use of batEcho==================begin========================CLS SET Nginx_path=C:set Nginx_dir=C:\wnmp\nginxSET Php_dir=C:\wnmp\phpcolor 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"exitpause:start call:startnginx call:startphpfastcgi goto menu:stop Call:shutdownnginx Goto M     Enu:restart 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"is 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"is not exists%nginx_path%CD"%php_dir%"IF EXIST"%php_dir%php-cgi.exe" (        Echo "start ' Php-cgi.exe"Start/b Php-cgi.exe-b127.0.0.1:9001-c php.ini) ECHO. OK goto:eof

(6) Test success

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

The following mysqli_connect () code sections need to be changed accordingly.

    

mysql+php+nginx</title>  PHP   $linkmysqli_connect("localhost", "root", "root");    if ($link) {    echo "DB Connect success!" ;   } Else {    echo "DB Connect failed!" ;   }  ? >  <br>  phpinfo();? > </body>

Double-click the Start.bat script file above, press ENTER after keyboard input 1

As shown, it indicates that the nginx-php started successfully

      

Open the browser, type: http://127.0.0.1 in the browser address bar, as seen in the interface shown, stating that the WNMP configuration was successful.

      

At this point, WNMP configuration is successful!

The next article will be how to configure the virtual Hosts and OpenSSL settings on Nginx.

This is the first time the younger brother Post, if there are shortcomings also please correct, welcome comments exchange.

Reference Link: http://jingyan.baidu.com/article/636f38bb408ee4d6b84610b9.html

Windows7 Configuring Nginx+php+mysql Tutorials

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.