Install nginx and PHP on Windows
This tutorial is based on Windows 8.1 + nginx 1.5.12 + PHP 5.5.11 but should work with other versions as well.
Setup
Some downloads will have a x86 and x64 version. Choose the same architecture as your Windows installation. You can check this by pressing Windows Key + Pause.
- Download nginx (nginx/Windows), PHP (Non Thread Safe) and Visual C++ Redistributable for Visual Studio 2012 (PHP needs this to run)
- Install Visual C++ Redistributable for Visual Studio 2012
- Extract nginx to a directory
- Create a directory called
PHP
inside nginx’s directory - Extract PHP to the PHP directory you just created
- Open the file
conf\nginx.conf
and uncomment (remove the leading #) the following lines:#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; #}
- Change
/scripts$fastcgi_script_name
to an absolute path, replacing the backslashes (\) by slashes (/):C:/Users/Louis/Desktop/nginx-1.5.12/html$fastcgi_script_name
- Open the PHP directory
- Rename
php.ini-production
orphp.ini-development
tophp.ini
(depending on your needs) - Start PHP
- Hold shift, right-click on an empty spot in the PHP directory and choose
Open command window here
- Type
php-cgi -b 127.0.0.1:9000
and press enter
- Hold shift, right-click on an empty spot in the PHP directory and choose
- Start nginx
- Hold shift, right-click on an empty spot in the nginx directory and choose
Open command window here
- Type
nginx
and press enter
- Hold shift, right-click on an empty spot in the nginx directory and choose
You’re done. You have set up and started your webserver with PHP.
Test
To test if everything went right, follow these simple instructions:
- Create a file called
test.php
in the html directory - Edit the file and insert the following PHP code:
<?php phpinfo(); >
- Browse to http://localhost/test.php
If you see a page displaying your PHP version and other information everything is working as it should. If you see an error you should check if you did everything right.
Install service
You’re now running nginx and PHP in a command window. You can also run it as a service (in the background). This way Windows will start nginx and PHP automatically at startup, make sure they restart when they crash and you can easily start, stop or restart them yourself.
To install normal programs as a service in Windows I recommend NSSM (the Non-Sucking Service Manager). It’s a very small program and very easy to use.
A tutorial about NSSM can be found here.
Leave a comment