{"id":66,"date":"2015-11-09T07:12:02","date_gmt":"2015-11-09T07:12:02","guid":{"rendered":"http:\/\/cloudkul.com\/blog\/?p=66"},"modified":"2017-04-13T08:20:44","modified_gmt":"2017-04-13T08:20:44","slug":"introduction-to-nginx-how-to-setup-lemp-stack","status":"publish","type":"post","link":"https:\/\/cloudkul.com\/blog\/introduction-to-nginx-how-to-setup-lemp-stack\/","title":{"rendered":"Introduction to Nginx : How to setup LEMP stack"},"content":{"rendered":"<p><strong>Why another web server : Take a quick look\u00a0<\/strong><\/p>\n<p>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&#8217;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.<\/p>\n<p>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.<\/p>\n<p>Apache is based on process-driven architecture i.e \u00a0it 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.<\/p>\n<p>On the other hand, Nginx works on event-driven architecture i.e it\u00a0does 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.<\/p>\n<p><strong>How to install LEMP (Linux, Nginx, Mysql,Php) on Ubuntu 14.04 :<\/strong><\/p>\n<p>Run the following commands to install nginx :-<\/p>\n<pre class=\"lang:default decode:true \">sudo apt-get update\r\nsudo apt-get install nginx<\/pre>\n<p>Hit the URL to check if nginx has been successfully installed :-<\/p>\n<pre class=\"lang:default decode:true\">http:\/\/server_domain_name_or_IP<\/pre>\n<p><a href=\"http:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2015\/11\/Selection_009.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-360 size-full\" src=\"http:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2015\/11\/Selection_009.png\" alt=\"\" width=\"897\" height=\"323\" \/><\/a><\/p>\n<p>Install mysql using the following command :-<\/p>\n<pre class=\"lang:default decode:true \">sudo apt-get install mysql-server<\/pre>\n<p>Since Nginx does not contain native PHP processing like some other web servers, we will need to install php5-fpm, which stands for &#8220;fastCGI process manager&#8221;. We will tell Nginx to pass PHP requests to this software for processing.<\/p>\n<p>Run the following command :-<\/p>\n<pre class=\"lang:default decode:true \">sudo apt-get install php5-fpm php5-mysql<\/pre>\n<p>Open the main php5-fpm configuration file :-<\/p>\n<pre class=\"lang:default decode:true \">sudo nano \/etc\/php5\/fpm\/php.ini<\/pre>\n<p>In this file, we have to uncomment the parameter &#8220;cgi.fix_pathinfo&#8221; and set it to zero :-<\/p>\n<pre class=\"lang:default decode:true \">cgi.fix_pathinfo=0<\/pre>\n<p>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&#8217;t be allowed to execute.<\/p>\n<p>Restart php5-fpm :-<\/p>\n<pre class=\"lang:default decode:true \">sudo service php5-fpm restart<\/pre>\n<p>Now, we need to tell Nginx to use our Php processer. To enable php, we have to make the following changes in\u00a0default Nginx server block configuration file :-<\/p>\n<pre class=\"lang:default decode:true \">sudo nano \/etc\/nginx\/sites-available\/default<\/pre>\n<p>The changes which we need to make are highlighted below :-<\/p>\n<pre class=\"lang:default decode:true\">server {\r\nlisten 80 default_server;\r\nlisten [::]:80 default_server ipv6only=on;\r\n\r\nroot \/usr\/share\/nginx\/html;\r\nindex <span style=\"color: #ff0000\">index.php<\/span> index.html index.htm;\r\n\r\n<span style=\"color: #ff0000\">server_name server_domain_name_or_IP;\r\n\r\nlocation \/ {\r\ntry_files $uri $uri\/ =404;\r\n}\r\n\r\nerror_page 404 \/404.html;\r\nerror_page 500 502 503 504 \/50x.html;\r\nlocation = \/50x.html {\r\nroot \/usr\/share\/nginx\/html;\r\n}\r\n\r\nlocation ~ \\.php$ {\r\ntry_files $uri =404;\r\nfastcgi_split_path_info ^(.+\\.php)(\/.+)$;\r\nfastcgi_pass unix:\/var\/run\/php5-fpm.sock;\r\nfastcgi_index index.php;\r\nfastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\r\ninclude fastcgi_params;<\/span>\r\n}\r\n}<\/pre>\n<p>Restart Nginx :-<\/p>\n<pre class=\"lang:default decode:true \">sudo service nginx restart<\/pre>\n<p>Now, create a php file to test if the changes have been successfully done :-<\/p>\n<pre class=\"lang:default decode:true\">sudo nano \/usr\/share\/nginx\/html\/info.php<\/pre>\n<pre class=\"lang:default decode:true\">&lt;?php\r\nphpinfo();\r\n?&gt;<\/pre>\n<p>Hit the URL :-<\/p>\n<pre class=\"lang:default decode:true\">http:\/\/server_domain_name_or_IP\/info.php\r\n<\/pre>\n<p><a href=\"http:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2015\/11\/Selection_0092.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-362 size-full\" src=\"http:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2015\/11\/Selection_0092.png\" alt=\"\" width=\"897\" height=\"323\" \/><\/a><\/p>\n<p>If you see a page that looks like this, you&#8217;ve set up PHP processing with Nginx successfully.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><strong><a href=\"http:\/\/cloudkul.com\/contact\/\" target=\"_blank\">FOR ANY TYPE OF QUERY OR HELP, KINDLY CONTACT US<\/a><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Why another web server : Take a quick look\u00a0 Every process running on apache server <a class=\"text-primary\" title=\"read more\" href=\"https:\/\/cloudkul.com\/blog\/introduction-to-nginx-how-to-setup-lemp-stack\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":5,"featured_media":331,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Introduction to Nginx : How to setup LEMP stack - Cloudkul<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cloudkul.com\/blog\/introduction-to-nginx-how-to-setup-lemp-stack\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Introduction to Nginx : How to setup LEMP stack - Cloudkul\" \/>\n<meta property=\"og:description\" content=\"Why another web server : Take a quick look\u00a0 Every process running on apache server [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudkul.com\/blog\/introduction-to-nginx-how-to-setup-lemp-stack\/\" \/>\n<meta property=\"og:site_name\" content=\"Cloudkul\" \/>\n<meta property=\"article:published_time\" content=\"2015-11-09T07:12:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-04-13T08:20:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2015\/11\/Introduction-to-Nginx.png\" \/>\n\t<meta property=\"og:image:width\" content=\"848\" \/>\n\t<meta property=\"og:image:height\" content=\"422\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Naina Johari\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cloudkul.com\/blog\/introduction-to-nginx-how-to-setup-lemp-stack\/\",\"url\":\"https:\/\/cloudkul.com\/blog\/introduction-to-nginx-how-to-setup-lemp-stack\/\",\"name\":\"Introduction to Nginx : How to setup LEMP stack - Cloudkul\",\"isPartOf\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/#website\"},\"datePublished\":\"2015-11-09T07:12:02+00:00\",\"dateModified\":\"2017-04-13T08:20:44+00:00\",\"author\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/38f7cddff574c7fe989d6ca2df61fc57\"},\"breadcrumb\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/introduction-to-nginx-how-to-setup-lemp-stack\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cloudkul.com\/blog\/introduction-to-nginx-how-to-setup-lemp-stack\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cloudkul.com\/blog\/introduction-to-nginx-how-to-setup-lemp-stack\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cloudkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Introduction to Nginx : How to setup LEMP stack\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#website\",\"url\":\"https:\/\/cloudkul.com\/blog\/\",\"name\":\"Cloudkul\",\"description\":\"Host your eCommerce Store on AWS with Optimized Performance\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/cloudkul.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/38f7cddff574c7fe989d6ca2df61fc57\",\"name\":\"Naina Johari\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c7a0be3afff58963975900f809e57046?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c7a0be3afff58963975900f809e57046?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g\",\"caption\":\"Naina Johari\"},\"url\":\"https:\/\/cloudkul.com\/blog\/author\/naina-johari379\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Introduction to Nginx : How to setup LEMP stack - Cloudkul","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cloudkul.com\/blog\/introduction-to-nginx-how-to-setup-lemp-stack\/","og_locale":"en_US","og_type":"article","og_title":"Introduction to Nginx : How to setup LEMP stack - Cloudkul","og_description":"Why another web server : Take a quick look\u00a0 Every process running on apache server [...]","og_url":"https:\/\/cloudkul.com\/blog\/introduction-to-nginx-how-to-setup-lemp-stack\/","og_site_name":"Cloudkul","article_published_time":"2015-11-09T07:12:02+00:00","article_modified_time":"2017-04-13T08:20:44+00:00","og_image":[{"width":848,"height":422,"url":"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2015\/11\/Introduction-to-Nginx.png","type":"image\/png"}],"author":"Naina Johari","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/cloudkul.com\/blog\/introduction-to-nginx-how-to-setup-lemp-stack\/","url":"https:\/\/cloudkul.com\/blog\/introduction-to-nginx-how-to-setup-lemp-stack\/","name":"Introduction to Nginx : How to setup LEMP stack - Cloudkul","isPartOf":{"@id":"https:\/\/cloudkul.com\/blog\/#website"},"datePublished":"2015-11-09T07:12:02+00:00","dateModified":"2017-04-13T08:20:44+00:00","author":{"@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/38f7cddff574c7fe989d6ca2df61fc57"},"breadcrumb":{"@id":"https:\/\/cloudkul.com\/blog\/introduction-to-nginx-how-to-setup-lemp-stack\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudkul.com\/blog\/introduction-to-nginx-how-to-setup-lemp-stack\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/cloudkul.com\/blog\/introduction-to-nginx-how-to-setup-lemp-stack\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Introduction to Nginx : How to setup LEMP stack"}]},{"@type":"WebSite","@id":"https:\/\/cloudkul.com\/blog\/#website","url":"https:\/\/cloudkul.com\/blog\/","name":"Cloudkul","description":"Host your eCommerce Store on AWS with Optimized Performance","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cloudkul.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/38f7cddff574c7fe989d6ca2df61fc57","name":"Naina Johari","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c7a0be3afff58963975900f809e57046?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c7a0be3afff58963975900f809e57046?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g","caption":"Naina Johari"},"url":"https:\/\/cloudkul.com\/blog\/author\/naina-johari379\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/66"}],"collection":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/comments?post=66"}],"version-history":[{"count":8,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/66\/revisions"}],"predecessor-version":[{"id":552,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/66\/revisions\/552"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/media\/331"}],"wp:attachment":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/media?parent=66"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/categories?post=66"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/tags?post=66"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}