Today now in this post i will show you How to install Nginx 1.4.x on Unix systems? In this documentation i will cover up installing and the configuring of PHP also with PHP-FPM for a Nginx 1.4.x HTTP server.
So now in this guide i will be show that we have to built Nginx server from the source and the therefore all binaries and the configuration files are as located at /usr/local/nginx
. Now so If this is not the case and we have obtained Nginx through other means then it please refer to the Nginx Wiki in order to the translate this manual to our setup.
So now in this guide i will fully cover all the basics of how to configuring an Nginx server to process PHP applications and the serve them on port 80, so it is highly recommended that way we can study the Nginx and PHP-FPM documentation. Now if we need to wish optimize our setup to past the scope from this documentation.
So please need to note that throughout this documentation version numbers it have been replaced with an ‘x’ to ensure so this documentation stays it correct in the future, need to please replace these as necessary with the corresponding version of the numbers.
- It i am recommended that we can visit the Nginx Wiki » install page for more information so in order to obtain and install Nginx on our system.
2. Obtain and unpack the PHP source:
tar zxf php-x.x.x
For Configure and build the PHP. So this where we can customize the PHP with the various options, as like as which an extensions will be enabled. Run the ./configure –help for a list of an available options. Now In our example i’ll do a simple configure with the PHP-FPM and MySQLi support.
cd ../php-x.x.x
./configure --enable-fpm --with-mysqli
make
sudo make install
So Obtain and the move configuration files to their correct locations
cp php.ini-development /usr/local/php/php.ini
cp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.conf
cp sapi/fpm/php-fpm /usr/local/bin
Now it is an important that we have to prevent the Nginx from the passing requests to the PHP-FPM backend if the file does not exists, so allowing us to prevent arbitrarily script the injection.
Load up php.ini:
vim /usr/local/php/php.ini
To Locate cgi.fix_pathinfo=
and to modify it as follows:
cgi.fix_pathinfo=0
Now php-fpm.conf must be modified to the specify on that php-fpm must be run as the user www-data and the group to www-data before we can start the service:
vim /usr/local/etc/php-fpm.d/www.conf
Find and modify our following:
; Unix user/group of processes ; Note: The user is mandatory. If the group is not set, the default user's group ; will be used. user = www-data group = www-data
The php-fpm service can now be started:
/usr/local/bin/php-fpm
So this guide will not be configure by php-fpm any further, if we are interested in this further configuring php-fpm then please consult the documentation.
Nginx must now be configured to support the processing with PHP applications:
vim /usr/local/nginx/conf/nginx.conf
To modify the default location to block be aware it must be attempt to serve .php files:
location / {
root html;
index index.php index.html index.htm;
}
Now in the next step is for ensure the .php files are passed on the PHP-FPM backend. So the below commented default PHP location block, enter the following:
location ~* \.php$ {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
Restart Nginx.
sudo /usr/local/nginx/sbin/nginx -s stop
sudo /usr/local/nginx/sbin/nginx
Create a test file
rm /usr/local/nginx/html/index.html echo "<?php phpinfo(); ?>" >> /usr/local/nginx/html/index.php
Now need to navigate http://localhost. The phpinfo() should now be shown here.
So the following steps in the above it we will have to running Nginx web server with in support for the PHP as an FPM
SAPI
module. Now of course need to there are many more configuration to options available for the Nginx and PHP. So for the more information need to type ./configure –help in the corresponding to source tree.
Read Also: How to Install Apache 2.x on Unix systems ?