18K Views

Introduction to Nginx : How to setup LEMP stack

Why another web server : Take a quick look 

Every process running on apache server can have only one client i.e each process can handle only one request at a time and that’s how most of the servers have been designed.The need of serving large number of requests is raising day by day. So, if we require 10,000 clients to connect, we must have 10,000 processes currently running on our web server.If such large number of simultaneous connections are established, you might be facing problems like deadlocks,memory issues and lack of hardware resources etc. Therefore, the problem of scalability of web server came into picture.

The web server scalability problem can be solved either by increasing the hardware capabilities (i.e memory, CPU, etc ) or by improving the web server architecture.The goal here is to improve the web server architecture.

Apache is based on process-driven architecture i.e  it creates processes and threads to handle additional connections so the administrator has to configure the server to handle the maximum number of allowable processes.Too many processes can exhaust memory, resulting a server with degrading performance.Moreover,when the limit of the processes is reached it also refuses additonal connections.

On the other hand, Nginx works on event-driven architecture i.e it does not create new processes for each web request, instead the administrator configures how many worker processes to create for the main Nginx process and each worker can handle thousands of concurrent connections.Several benchmarking results indicates that when compared to Apache, Nginx is light-weighted and extremely fast for serving static pages.

How to install LEMP (Linux, Nginx, Mysql,Php) on Ubuntu 14.04 :

Run the following commands to install nginx :-

Hit the URL to check if nginx has been successfully installed :-

Install mysql using the following command :-

Since Nginx does not contain native PHP processing like some other web servers, we will need to install php5-fpm, which stands for “fastCGI process manager”. We will tell Nginx to pass PHP requests to this software for processing.

Run the following command :-

Open the main php5-fpm configuration file :-

In this file, we have to uncomment the parameter “cgi.fix_pathinfo” and set it to zero :-

This is an extremely insecure setting because it tells PHP to attempt to execute the closest file it can find if a PHP file does not match exactly. This basically would allow users to craft PHP requests in a way that would allow them to execute scripts that they shouldn’t be allowed to execute.

Restart php5-fpm :-

Now, we need to tell Nginx to use our Php processer. To enable php, we have to make the following changes in default Nginx server block configuration file :-

The changes which we need to make are highlighted below :-

Restart Nginx :-

Now, create a php file to test if the changes have been successfully done :-

Hit the URL :-

If you see a page that looks like this, you’ve set up PHP processing with Nginx successfully.

 

FOR ANY TYPE OF QUERY OR HELP, KINDLY CONTACT US

Category(s) Uncategorized
. . .

Comment

Add Your Comment

Be the first to comment.

css.php