Installing Nginx on Windows

Download NginX files from: https://nginx.org/en/docs/windows.html.

Unzip to C\{name-version} (in my case it would be C:\nginx-1.25.4 directory). Open PowerShell as an Administrator and lunch server by typing cmd:

start nginx

Every time you will edit server configuration, You need to reload or stop and start server with:

nginx -s reload
nginx -s stop
start nginx

Run PHP-CGI worker on Windows

Download PHP zip file from https://mkyong.com/nginx/nginx-php-on-windows/. Unzip and to a folder and move to C:\ directory. To run a PHP worker, cd inside php directory

cd C:\PHP\php-8.3.4\

Open new PowerShell terminal as Administrator and run:

./php-cgi.exe -b 127.0.0.1:9999


If you use PowerShell in your Windows Task Manager, you should find new tasks:

Crete www directory. I have chosen to create it under an existing nginx path C:\nginx-1.25.4\www, so that I can use the relative path in a nginx config file:

You could also create it anywhere in the system, just remember to configure absolute path instead if you don’t use nginx default directory.

Set PHP-CGI worker to talk to NginX server

Now change nginx configuration file. Edit C:\nginx-1.25.4\conf\nginx.conf to match php-cgi IP and PORT number:

#user  nobody;
worker_processes  1;

#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       8080;
        server_name  localhost;
        root   www;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            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   c:/nginx-1.25.4/www;
        # }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
           fastcgi_pass   127.0.0.1:9999;
           fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
           include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

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


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

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

}

In above configuration, you will also notice, that I have added index.php to Location configuration in two lines.

Configure an auto start of NginX server and PHP-CGI worker

Create a batch file start-php-fcgi.bat under the c:\nginx\ directory:

@ECHO OFF
ECHO Starting PHP FastCGI...
set PATH=C:\PHP\php-8.3.4\;%PATH%
c:\bin\RunHiddenConsole.exe C:\PHP\php-8.3.4\php-cgi.exe -b 127.0.0.1:9999

Update the above directory name to reflect your directory structure (I choose to use version directory). 
Schedule a basic task to run C:\nginx\conf\start-nginx.bat on system startup.

https://www.nginx.com/resources/wiki/start/topics/examples/phpfastcgionwindows/

3
0
Would love your thoughts, please comment.x
()
x