Wednesday, 21 September 2016

Install Nginx along with apache in ubuntu

NGINX is a very fast Webserver, its faster than Apache (under similar conditions) because it doesn't need to spawn new processes or threads for each request like Apache does.Hence it also has a low memory foot print.Nginx and Apache are alternative web server softwares. Web server softwares serve web pages in response to browser requests.

Install Nginx along with apache in ubuntu

Nginx has few dependencies that Ubuntu doesn't already take care of. Here's what you'll need:
  • The Gzip modules requires the zlib library.
  • The rewrite module requires the pcre library.
  • SSL support requires the openssl library.
With the Ubuntu platform, the only library from the list above that you'll need to install is the pcre library. To install this, follow these steps:

sudo apt-get install libpcre3-dev

Nginx can use PHP5 with the help of PHP-FPM (an alternative PHP FastCGI implementation with additional features, which is useful to busier sites). Here’s how to install PHP-FPM:

Install PHP-FPM using command:
sudo apt-get install php5-fpm

After installing all above things now Installing Nginx:
sudo apt-get install nginx

Starting and stopping the server
sudo service nginx start

Top stop the Nginx server, issue the following command:
sudo service nginx stop

Configure nginx:
sudo nano /etc/nginx/sites-available/default (This is default file of nginx)

server {
listen 8081 default_server; //default port is change now because in port 80 apache already running
listen [::]:8081 default_server ipv6only=on;

root /usr/share/nginx/html; //directory path of nginx files you can change it to /var/www/html
index index.php index.html index.htm;

location ~ \.php$ {
# fastcgi_split_path_info ^(.+\.php)(/.+)$;
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# # With php5-cgi alone:
# fastcgi_pass;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

Activate the virtual host.
sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default

Make sure your Document Root is correct. Save and exit the file and activate that virtual host:
sudo a2ensite default

sudo service php5-fpm restart
sudo service nginx restart

Check Your nginx : http://localhost:8081/

Featured post

How to create dynamic schema in mongodb

Sometime what we need in our application is to create mongodb schema for collection and some of our collection schema are same but names are...

Popular Posts