Installing and Running nginx
- Download nginx for Windows Download
- Extract the downloaded .zip file
- Rename the extracted folder nginx
- Copy the extracted nginx files to the desired location, for example C:\Program Files\nginx
- Open the nginx folder and double click nginx.exe to run the server
Adding PHP Support
- Download PHP for Windows (VC15 x64 NTS) Download
- Install Microsoft Visual C++
- Extract the downloaded .zip file
- Rename the extracted folder php
- Copy the extracted php folder to the desired location, for example C:\Program Files\PHP
- Open the php install location and right click in the white space while holding down the Shift key > Open PowerShell window here
- Paste the following command in the PowerShell window to start the PHP CGI process
.\php-cgi.exe -b 127.0.0.1:9123
- Open Windows Explorer and navigate to the nginx installation directory /conf
- Edit nginx.conf in a text editor
- Add the following lines inside the server object
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9123;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
} - Save the changes to nginx.conf
- Right click the Start button > Run > Type taskkill /f /im "nginx.exe" > Press Enter
- Double click nginx.exe to restart the process with PHP support
Running nginx Server on Startup
nginx doesn't currently have the ability to run as a Windows service natively. A simple workaround is to create a scheduled task to start the nginx server on system startup
- Open notepad and paste the following into a blank text file
start "" /b "C:\Program Files\PHP\php-cgi.exe" -b 127.0.0.1:9123
start "" /b "C:\Program Files\nginx\nginx.exe" -c "C:\Program Files\nginx\conf\nginx.conf" - Save the text file as startup.bat in the nginx installation directory
- Click the Start button > Search Task > Click Task Scheduler
- Right click the Task Scheduler Library folder in the top left > Create Basic Task
- Name the task nginx startup > Click Next
- Select When the computer starts > Click Next
- Select Start a program > Click Next
- Click the Browse... button and navigate to C:\Program Files\nginx\startup.bat
- Set the Start in value to C:\Program Files\nginx > Click Next
- Click Finish
- Reboot to test that nginx with PHP support starts with the system on boot