1. 程式人生 > >php+Nginx 安裝手冊

php+Nginx 安裝手冊

1、需要安裝的程式:

  (1) http伺服器:nginx

  (2) php開發環境:phpstorm

  (3) php安裝環境:php

  (4) 資料庫:postgresql

 

2、修改nginx/conf/nginx.conf 找到該段

#location ~ \.php$ {

        #    root           html;

        #    fastcgi_pass   127.0.0.1:9000;

        #    fastcgi_index  index.php;

        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

        #    include        fastcgi_params;

        #}

修改為:

        location ~ \.php$ {

            root          html;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

                            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

            include        fastcgi_params;

        }

 

並修改include 為絕對路徑。列:  include   E:/nginx-1.15.7/conf/fastcgi_params

在nginx/html 目錄下新建index.php 內容如下

<?php

 phpinfo();

?>

 

Php目錄下copy檔案 php.ini-development 修改為 php.ini

修改php.ini

(1)    ;extension_dir ="./ext"   取消註釋,並修改為絕對路徑 extension_dir ="e:/php/ext”

(2)    取消註釋 ;cgi.fix_pathinfo=1

(3)    RunHiddenConsole.exe下載好放在nginx根目錄下,將start_php.bat和stop_php.bat放在同級目錄下

(4)    新建start_php.bat,修改php_home 和 nginx_home

 

@echo off

set php_home=E:/php

set nginx_home=E:/nginx-1.15.7

 

REM Windows 下無效

REM set PHP_FCGI_CHILDREN=5

 

REM 每個程序處理的最大請求數,或設定為 Windows 環境變數

set PHP_FCGI_MAX_REQUESTS=1000

 

echo Starting PHP FastCGI...

RunHiddenConsole %php_home%/php-cgi.exe -b 127.0.0.1:9000 -c %php_home%/php.ini

 

echo Starting nginx...

RunHiddenConsole %nginx_home%/nginx.exe -p %nginx_home%

 

(5)    新建stop_php.bat

@echo off

echo Stopping nginx...

taskkill /F /IM nginx.exe > nul

echo Stopping PHP FastCGI...

taskkill /F /IM php-cgi.exe > nul

exit

 

 

啟動nginx php: 點選 start_php.bat

停止 nginx php: 點選 stop_php.bat

 

成功後開啟http://localhost/index.php 顯示下面頁面

.

以後就可以在nginx/html目錄下直接放php了;