Home > Backend Development > PHP Tutorial > The simplest Nginx+PHP

The simplest Nginx+PHP

WBOY
Release: 2016-07-30 13:31:54
Original
999 people have browsed it

Note:
1. Only used in Windows 7 environment, date is 2015-8-11, other environments are for reference only.
2. Only provide the simplest configuration


Quick installation and configuration

  • Download the required Nginx version, and decompress (compile and install) to the required directory http://nginx.org/en/download.html
  • Download the required PHP version and unzip (compile and install) it to the required directory http://php.net/downloads.php
  • Find and modify or add the server block of the Nginx configuration file nginx.conf:
<code>server {
        # 替换为需要的端口
        listen       80<span>;</span>
        server_name  localhost<span>;</span>        # 替换为需要的目录
        root   D:/Projects/nginx-html<span>;</span>
        index  index.html index.htm index.php<span>;</span>        location ~ \.php$ {
            include         fastcgi.conf<span>;</span>
            # 连接到本机 PHP FastCGI Server 开启的端口
            fastcgi_pass    127.0.0.1:9001<span>;</span>
        }
    }</code>
Copy after login
  • Add the directory where nginx and php-cgi are located to the Path environment variable
  • Run nginx
  • Enter the following command on the command line to run php-cgi, the port remains with the server block location block fastcgi_passConfiguration is consistent
<code>php<span>-cgi</span><span>-b</span><span>127.0</span><span>.0</span><span>.1</span>:<span>9001</span></code>
Copy after login
  • Create a new index.php file under D:Projectsnginx-html (the directory set by the root of the server block), and write
<code><span><?php</span><span>echo</span><span>"<h1>PHP works!</h1>"</span>;</code>
Copy after login
  • access the server_name and listen of the server block The configured address and port (for example http://localhost:80/index.php), and seeing "PHP works!" indicates success!

Quickly start, restart, and shut down Nginx service under Windows

    Tool download RunHiddenConsole, and add its storage location to Path
  • Create
  • nginx-start.bat, and write
<code>@echo off
echo Starting php-cgi <span>...</span>
RunHiddenConsole php-cgi -b <span>127.0</span><span>.0</span><span>.1</span>:<span>9001</span>
echo Starting nginx <span>...</span>
c:
cd C:\Program Files\nginx-<span>1.9</span><span>.3</span>
RunHiddenConsole nginx
pause</code>
Copy after login
    New
  • nginx-reload.bat and write
<code>@echo off
echo Reloading Nginx <span>...</span>
c:
cd C:\Program Files\nginx-<span>1.9</span><span>.3</span>
nginx -s reload
pause</code>
Copy after login
    Create new
  • nginx-quit.bat and write
<code>@echo off
echo Closing php-cgi <span>...</span>
taskkill /IM php-cgi.exe
echo Closing nginx <span>...</span>
c:
cd C:\Program Files\nginx-<span>1.9</span><span>.3</span>
nginx -s quit
pause</code>
Copy after login
    Store the above three files to the nginx installation directory
  • Command line input
  • nginx- start, nginx-reload, nginx-quit can quickly start, restart, and shut down Nginx service and php-cgi

Reference:

1. How to correctly configure Nginx+PHP
2. Installation and configuration method of Nginx+PHP5 under Windows

Copyright statement: This article is an original article by the blogger. Please indicate the source when reprinting. Although I don't think there's anything better. . .

The above has introduced the simplest Nginx+PHP, including all aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template