Windows7 configuration Nginx+php+mysql tutorial

Windows7 configuration Nginx+php+mysql tutorial

  I am learning php recently, and I want to record my learning experience and write some experience for reference only. This article is suitable for those who are new to php, want to learn and want to build Nginx+php+mysql environment by themselves.

  Of course, you can also choose an integrated installation package, such as wamp, etc., but I recommend that you build the environment manually, so that you can better understand PHP and its running process. Go directly to the topic below.

step:

1. Prepare the installation package, etc.

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

  (2) The download link of php-5.6.25-nts-Win32-VC11-x86.zip or x64.zip is http://windows.php.net/download#php-5.6, select the corresponding version according to the system type.

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

2. Install mysql service (if you have installed mysql before, you don’t need to download and install it, just start mysql service during operation.)

  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, here the encoding is UTF- 8. After setting the database password (generally root), execute "Execute" and click "Finish" to complete the installation. To ensure that the mysql service is turned on, the method to check whether the service is turned on is: win+R enter services.msc and press Enter to see if there is a mysql service as shown in the figure below and is in the starting state.

      

3. Install nginx-1.10.1

  (1) Unzip the nginx-1.10.1.zip file to C:\wnmp\nginx, enter the folder, find nginx.exe, double-click nginx.exe to start nginx.

    Enter the task manager process tab, if you find the nginx.exe process, it confirms that nginx has started.

    Open the browser and type: http://127.0.0.1 in the browser address bar . If you see the interface as shown in the figure below, it means that nginx is working normally .

      。

  (2)进入C:\wnmp\nginx\conf文件夹内,记事本或写字板打开nginx的配置文件nginx.conf

     Find the following two places to modify, modify the content as follows
`server {
listen 80;
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) Unzip the php-5.6.25-nts-Win32-VC11-x64/x86.zip file to C:\wnmp\php.

  (2) Enter the C:\wnmp\php directory, back up a copy of php.ini-development, and rename php.ini-development to php.ini

  Find location and modify:

      ; extension_dir = "ext", delete the semicolon in front and modify it to: extension_dir = "C:/wnmp/php/ext"

      ;extension=php_gd2.dll, delete the semicolon in front: extension=php_gd2.dll

      ;extension=php_mbstring.dll, delete the semicolon in front: extension=php_mbstring.dll

      ;extension=php_mysql.dll, delete the semicolon in front: extension=php_mysql.dll

      ;extension=php_mysqli.dll, delete the semicolon in front: extension=php_mysqli.dll

      ;extension=php_pdo_mysql.dll, delete the semicolon in front: extension=php_pdo_mysql.dll

      ;cgi.force_redirect = 1, delete the semicolon in front: cgi.force_redirect = 1

      ;cgi.fix_pathinfo=1, delete the semicolon in front: cgi.fix_pathinfo=1

      ;cgi.rfc2616_headers = 0, delete the semicolon in front: cgi.rfc2616_headers = 1

  (3) Configure environment variables:

      Open the environment variable configuration window,

      Add the variable name in the system environment variables: PHP_HOME Variable value: C:\wnmp\php

      Add the variable name to the system environment variables: NGINX_HOME Variable value: C:\wamp\nginx

      Add at the end of the path variable: %PHP_HOME%;%NGINX_HOME%; (note adding a semicolon)

  (4) Start php-cgi service:

      win+R enter cmd and press 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

      Reopen a new command prompt interface,

        Enter the command: netstat -ano|findstr "9001" will show the occupation of port 9001

        Enter the command again: tasklist|findstr "2892" (Note: 2892 is the process number displayed in the last column after the previous command is executed)

        As shown in the figure below: indicates that the php-cgi service has started successfully

      

  (5) Write the startup script start.bat (In fact, up to the previous step, the configuration has been completed, but in order to facilitate the startup of various services in the future, a startup script is hereby written.)

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

      After opening with Notepad, edit as follows:

(If all the file directories are exactly the same as described in this tutorial, this script can be used directly. If there is a difference, you need to modify NGINX_DIR and PHP_DIR to use it)

@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

: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 -b 127.0.0.1:9001 -c php.ini
    )
    ECHO.OK
    goto :eof

(6) The test is successful

      Create a new www folder under C:\wnmp, create a new php file index.php under the www folder, and edit as follows

      The following mysqli_connect() code part needs to be changed accordingly.
&lt;html&gt;<br/>&lt;head&gt;<br/>&lt;title&gt;test mysql+php+nginx&lt;/title&gt;<br/>&lt;/head&gt;<br/>&lt;body&gt;<br/>&lt;?php<br/>$link = mysqli_connect("localhost","root","root");<br/>if($link){<br/>echo "db connect success!";<br/>}else{<br/>echo "db connect failed!";<br/>}<br/>?&gt;<br/>&lt;br&gt;<br/>&lt;?php phpinfo();?&gt;<br/>&lt;/body&gt;<br/>&lt;/html&gt;
  Double-click the above start.bat script file, enter 1 on the keyboard and press Enter

        As shown in the figure below, it means that nginx-php started successfully

      

      Open the browser and type: http://127.0.0.1 in the address bar of the browser . If you see the interface as shown in the figure below, it indicates that the wnmp configuration is successful .

      

  So far, WNMP configuration is successful!

  The next article will be how to configure Virtual Hosts and Openssl settings on nginx.

  This is the first time I posted, please correct me if there are any shortcomings, and welcome comments and exchanges.

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

Guess you like

Origin blog.51cto.com/15082565/2589379