Website building series (8) --- Local development environment construction (WNMP)

Related series of articles

Website building series (1) - Basic knowledge about websites
Website building series (2) - Detailed explanation of domain name, IP address, URL, port
Website building series (3) - Network protocol
website building series (4) - Web server Apache and Nginx
website building series (5) - Front-end development languages ​​HTML, CSS, JavaScript
website building series (6) - Back-end development languages ​​website
building series (7) - Commonly used front-end and back-end framework
website building series (8) - Local development environment construction (WNMP)

Preface

This article takes the WNMP (Windows+Nginx+MySQL+PHP) environment as an example.

1. Preparation work

2. Nginx installation

  • (1) Directly extract the downloaded Nginx installation package to the target directory (choose the installation directory yourself, do not include Chinese in the path), and rename it to Nginx
    ![2.png][3]

  • (2) Enter the Nginx directory and directly double-click Nginx.exe to start Nginx or enter cmd and use the command start nginx (the stop command is: nginx -s stop). After starting, enter the browser to visit localhost (127.0.0.1) and you will have the following interface.
    ![3.png][4]

3. MySQL installation

  • (1) Select the installation method Server only
    ![4.png][5]

  • (2) If there are no special instructions in the follow-up, please proceed directly to next.
    ![5.png][6]

  • (3) This step is very important! ! ! Be sure to choose the second one!
    ![6.png][7]

  • (4) Enter the root password and remember it yourself
    ![7.png][8]

  • (5) The default is enough. If there is a yellow exclamation mark, the name needs to be modified.
    ![8.png][9]

  • (6) As shown in the picture, you need to wait for a while after clicking.
    ![9.png][10]

  • (7) Follow the next step directly until the installation is completed.
    ![10.png][11]

  • (8) Verify whether the installation is successful, open the mysql command line client you just installed, and enter the password you just set.
    ![11.png][12]

  • (9) If the following message appears, the installation is successful
    ![12.png][13]

4. PHP installation and Nginx configuration

  • (1) Unzip to the target directory
    ![13.png][14]

  • (2) Copy a copy of php.ini-development and rename it to php.ini and put it in the installation path
    ![14.png][15]

  • (3) Open php.ini and directly add the following content, extension_dir = "Your PHP installation path\ext"

cgi.fix_pathinfo=1
cgi.force_redirect = 0
fastcgi.impersonate = 1
cgi.rfc2616_headers = 1
extension_dir = "C:\software\wnmp\php\ext"

![15.png][16]

  • (4) Open cmd and enter the PHP installation directory (it is recommended to directly configure the PHP environment variables to facilitate global execution), execute the command: php-cgi.exe -b 127.0.0.1:9000 -c your PHP installation path, pay attention Do not close this cmd window after execution
php-cgi.exe -b 127.0.0.1:9000 -c C:\software\wnmp\php
  • (5) Modify the nginx.conf file (in the conf folder under the Nginx installation directory, it is recommended to back it up before modification to prevent errors), find the following content in the configuration file, and modify or add
location / {
            root   html;
            index  index.html index.php index.htm;
            #这里添加index.php
        }

 location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
           # fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
           #这一部分前面的#号全部去掉,并将上面这一句改为下面这一句,否则会报运行PHP文件No 
           #input file specified错误
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
  • (6) Restart Nginx. At this time, put the PHP file in the html folder and you can access it normally through the browser. You are done.

5. Summary

Setting up a development environment is not a simple process, and you may encounter many problems in the process. For novices, it is recommended to try it a few times on a virtual machine to prevent some irreversible errors. Although the installation process is relatively cumbersome, it is still an easy one. The learning process, this series of tutorials has come to an end for the time being, but the learning process is far from over. This series of tutorials will be expanded in the future. Finally, I will leave some questions for you readers. I hope you can help yourself. Learn to solve.

  • Question 1: How to use MySQL database?
  • Question 2: How to modify the server root directory? (Tip: This article places the PHP file in the html directory and then accesses it through localhost)
  • Question 3: How to set up a development environment under Linux system?
  • Question 4: How does the local Web project realize access to different devices under the LAN?
  • Question 5: Try to deploy your own project to your own server and achieve access (I believe this is a learning process that is not short, provided that you have to learn the basics first)
  • Question 6: Understand phpstudy and Pagoda Linux

Guess you like

Origin blog.csdn.net/weixin_53902288/article/details/132776964