Windows PHP Installation

Let’s go through to setup PHP on Windows

DOWNLOAD PHP FILES

Head over to the PHP website and download the current version of PHP so we may proceed.

PHP Website

 

Download either x86 or x64 depending on your processor

EXTRACT PHP

In this tutorial we will be using the path of C:/nginx for everything so place the contents of the folder in the php Zip in a folder named php in C:/nginx

OPTIONAL

If you already have VC Runtime you can skip this step.

DOWNLOAD VCS

PHP Builds require Visual C++ Redistributable for Visual Studio.  Depending on which install you went with will determine which VC to download.  Once downloaded, extract and install like normal.

COPY php.ini-production

Head over to the php folder located in the nginx folder.

Find php.ini-production and copy or rename it to php.ini

We will come back to this file later.

OPTIONAL

If you already have NSSM installed, you may skip this step.

DOWNLOAD NSSM

Download From NSSM Webpage

Head over to the NSSM Webpage and download the pre-release  Zip file so we may extract it for Windows Command Prompt.

OPTIONAL

If you already have NSSM installed, you may skip this step.

EXTRACT NSSM

Now that you have download the NSSM Zip file.  Go ahead and unzip that file and navigate to the folder that has win32 and win64 folders.  Depending on your Windows installation [More than likely 64bit] go into the correct folder.  Copy the nssm.exe file into C:/windows/system32/

INSTALL PHP USING NSSM

Open up Command Prompt [Type cmd in start bar] by Right-Clicking it and selecting Run as Administrator.

Then type nssm install php

Then fill out the box like the image or with these values:


Reminder: This is assuming you have been following the guide with the installation folder as C:/nginx


Path: C:\nginx\php\php-cgi.exe

Startup Directory: C:\nginx\php

Arguments: -b 127.0.0.1:9000

EDIT php.ini FILE

Open up the file that you copied/renamed to php.ini

You will need to un-comment the following lines:

;extension_dir = "ext"
;extension=php_curl.dll
;extension=php_mbstring.dll
;extension=php_mysqli.dll
;extension=php_openssl.dll
;extension=php_pdo_mysql.dll
;extension=php_pdo_sqlite.dll
;extension=php_sqlite3.dll

If you don’t know how to un-comment, just delete the ; symbol infront of each line.

Then save the file.

START PHP SERVICE

In the Command Prompt that is still open with Administrator Privileges type in the following:

nssm start php

EDIT nginx.conf FOR PHP

Open up the nginx.conf file that is located at C:/nginx/conf/nginx.conf

Here is a brief overview of this page:

listen 80; This is the port that NGINX will listen on
server_name localhost; This is where you will put any domain name that you own
location / { root html; index index.html index.htm; } This is where NGINX will serve the website from

First thing we need to do is edit this line and add index.php:
index index.html index.htm;edit line to index index.php index.html index.htm;
Next we need to enable the php block so nginx knows where to send those files to process:

#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 line to

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;
}

Notice that we changed /scripts to $document_rootwhich will allow nginx to know where to pull files from

RESTART NGINX

In the Command Prompt that is still open with Administrator Privileges type in the following:

nssm restart nginx

CONTINUE TO NGINX REVERSE PROXIES

Now that NGINX is installed and is now working with PHP, let’s do some Reverse Proxies

REVERSE PROXIES