v5tech / notes

notes
https://ameizi.gitee.io/notes
MIT License
1.52k stars 378 forks source link

Windows7 + Nginx + PHP #96

Open v5tech opened 9 years ago

v5tech commented 9 years ago

https://www.nginx.com/resources/wiki/start/topics/examples/phpfastcgionwindows/ http://windows.php.net/downloads/releases/php-5.6.9-Win32-VC11-x64.zip http://nginx.org/download/nginx-1.8.0.zip

php.ini

extension_dir = "C:/php/ext"

extension=php_curl.dll
extension=php_gd2.dll
extension=php_mbstring.dll
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_pdo_mysql.dll

date.timezone = Asia/Shanghai

nginx.conf


#user  nobody;
worker_processes  4;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm index.php;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        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;
        }

    }

}

启动脚本

start

@echo off
echo Start nginx...
D:\soft\nginx-1.5.11\RunHiddenConsole.exe D:\soft\nginx-1.5.11\nginx.exe
echo Start php...
D:\soft\nginx-1.5.11\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9000 -c C:\php\php.ini

stop

@echo off
echo Stopping nginx...
taskkill /F /IM nginx.exe
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe
exit

restart

@echo off
echo Stopping nginx...
taskkill /F /IM nginx.exe
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe
echo Start nginx...
D:\soft\nginx-1.5.11\RunHiddenConsole.exe D:\soft\nginx-1.5.11\nginx.exe
echo Start php...
D:\soft\nginx-1.5.11\RunHiddenConsole.exe C:\php\php-cgi.exe -b 127.0.0.1:9000 -c C:\php\php.ini