{"id":1989,"date":"2016-06-17T11:40:06","date_gmt":"2016-06-17T15:40:06","guid":{"rendered":"https:\/\/www.globo.tech\/learning-center\/?p=1989"},"modified":"2017-11-24T17:02:49","modified_gmt":"2017-11-24T22:02:49","slug":"setup-nginx-php-fpm-mysql-ubuntu-16","status":"publish","type":"post","link":"https:\/\/www.globo.tech\/learning-center\/setup-nginx-php-fpm-mysql-ubuntu-16\/","title":{"rendered":"How to Setup NGINX, PHP-FPM, MySQL (LEMP) on Ubuntu 16"},"content":{"rendered":"<h1>How to Setup NGINX with PHP-FPM and MySQL on Ubuntu 16<\/h1>\n<p>PHP, Apache and MySQL are some of the most popular technologies for building commodity web applications. Even so, <a rel=\"nofollow\" href=\"https:\/\/www.apache.org\/\" target=\"_blank\">Apache<\/a> is a large web server that consumes lots of resources, and those looking for budget hosting might want to replace it with the lighter Nginx.<\/p>\n<h2>Getting Started<\/h2>\n<p>To complete this guide, you will need the following:<br \/>\n\u2022 1 Node (<a href=\"https:\/\/www.globo.tech\/cloud-server-pricing\" target=\"_blank\"><b>Cloud Server<\/b><\/a> or <a href=\"http:\/\/www.globo.tech\/dedicated-server-hosting\" target=\"_blank\"><b>Dedicated Server<\/b><\/a>) with a clean installation of Ubuntu 16.04.<\/p>\n<p>Ubuntu 16.04 LTS is a long-term support release, meaning Canonical will provide updates for 5 years rather than for only 9 months.<\/p>\n<p><code class=\"rouge\">Notice: Every command should be run as root user<\/code><\/p>\n<h2>Tutorial<\/h2>\n<p>Let&#8217;s get started. When finished, you&#8217;ll have a server platform capable of efficiently running any number of PHP and MySQL web apps.<\/p>\n<p>Let&#8217;s begin by applying all the latest updates. Not only will this improve security, but it will also avoid potential package download failures in later steps.<\/p>\n<p><code> apt-get update &amp;&amp; apt-get upgrade -y<br \/>\n reboot<\/code><\/p>\n<p>Now we&#8217;ll install the MySQL database, where the web application will keep all of its data.<\/p>\n<p><code> apt-get -y install mysql-server mysql-client<\/code><\/p>\n<p>You&#8217;ll be asked to set a root password. Make this password a strong one and remember it for later. Anyone with this password can access and modify all of your database content.<\/p>\n<p>A few additional steps are needed to further secure the database server. Let&#8217;s take care of those now.<\/p>\n<p><code> mysql_secure_installation<\/code><\/p>\n<p>It is now time to install the Nginx web server. Let&#8217;s install the package.<\/p>\n<p><code> apt-get install nginx -y<\/code><\/p>\n<p>The Nginx daemon must now be started so it will serve files.<\/p>\n<p><code> systemctl start nginx.service<br \/>\n systemctl enable nginx.service<\/code><\/p>\n<p>While Apache runs PHP scripts directly, Nginx must connect to an external FPM daemon to interpret scripts. That daemon must be installed before it can be used. Let&#8217;s install the necessary packages.<\/p>\n<p><code> apt-get -y install php7.0-fpm php7.0-mysql<\/code><\/p>\n<p>Now that the daemon is installed and running, Nginx virtual hosts must be configured to know how to access it, and which paths and files should be run through the FPM interpreter.<\/p>\n<p><code> nano \/etc\/nginx\/sites-available\/default<br \/>\n[...]<br \/>\n# Add index.php to the list if you are using PHP<br \/>\nindex index.php index.html index.htm index.nginx-debian.html;<br \/>\nserver_name_,<br \/>\n[...]<br \/>\n# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000<br \/>\n#<br \/>\nlocation ~ \\.php$ {<br \/>\ninclude snippets\/fastcgi-php.conf;<br \/>\n# # With php7.0-cgi alone:<br \/>\nfastcgi_pass 127.0.0.1:9000;<br \/>\n# # With php7.0-fpm:<br \/>\n# fastcgi_pass unix:\/run\/php\/php7.0-fpm.sock;<br \/>\n}<br \/>\n# deny access to .htaccess files, if Apache's document root<br \/>\n# concurs with nginx's one<br \/>\n#<br \/>\nlocation ~ \/\\.ht {<br \/>\ndeny all;<br \/>\n}<br \/>\n}<br \/>\n[...]<\/code><\/p>\n<p>Save the virtual host configuration, and restart Nginx to take advantage of the changes.<\/p>\n<p><code> systemctl restart nginx.service<br \/>\n systemctl enable nginx.service<\/code><\/p>\n<p>The php.ini file is where PHP and its modules are configured. It is necessary to change one line in order to successfully run scripts in the FPM daemon.<\/p>\n<p><code> nano \/etc\/php\/7.0\/fpm\/php.ini<\/code><\/p>\n<p>Find this block in the configuration file:<\/p>\n<p><code>; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.<br \/>\n; http:\/\/php.net\/cgi.fix-pathinfo<br \/>\n; cgi.fix_pathinfo=1<\/code><\/p>\n<p>Change the last line to this:<\/p>\n<p><code>; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.<br \/>\n; http:\/\/php.net\/cgi.fix-pathinfo<br \/>\ncgi.fix_pathinfo=0<\/code><\/p>\n<p>Save and exit. As with Nginx, it is now necessary to restart and enable the FPM daemon so the configuration changes take effect.<\/p>\n<p><code> systemctl restart php7.0-fpm.service<br \/>\n systemctl enable php7.0-fpm.service <\/code><\/p>\n<p>Finally, we&#8217;ll create a simple phpinfo page that provides diagnostic information on the installation. This page will later be replaced with a real application.<br \/>\nEnter the document root of the Nginx virtual host.<\/p>\n<p><code> cd \/var\/www\/html\/<\/code><\/p>\n<p>Create the file index.php<\/p>\n<p><code> nano index.php<\/code><\/p>\n<p>Now paste the following code:<\/p>\n<p><code>&lt;?php<br \/>\nphpinfo();<br \/>\n?&gt;<\/code><\/p>\n<p>Finally, visit the page you just created by visiting http:\/\/your_main_ip. You should see lots of diagnostic details about your PHP installation.<\/p>\n<h2>Conclusion<\/h2>\n<p>While this tutorial only installs a diagnostic page, you can now replace it with either a site you&#8217;ve developed yourself, or any number of third-party applications downloaded off the web. PHP is an easy platform to work with, and these instructions can easily apply to dozens or hundreds of PHP tools. If this guide was helpful to you, kindly share it with others who may also be interested. <\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>How to Setup NGINX with PHP-FPM and MySQL on Ubuntu 16 PHP, Apache and MySQL are some of the most popular technologies for building commodity web applications. Even so, Apache is a large web server that consumes lots of resources, and those looking for budget hosting might want to replace it with the lighter Nginx.<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[71],"tags":[],"class_list":["post-1989","post","type-post","status-publish","format-standard","hentry","category-applications","operating_system-ubuntu-16-04"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Setup NGINX, PHP-FPM, MySQL (LEMP) on Ubuntu 16 - Globo.Tech<\/title>\n<meta name=\"description\" content=\"This tutorial will show you how to setup NGINX, including PHP-FPM and MySQL on your Ubuntu 16.04 LTS Server. PHP, Apache and MySQL are some of the most...\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.globo.tech\/learning-center\/setup-nginx-php-fpm-mysql-ubuntu-16\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Setup NGINX, PHP-FPM, MySQL (LEMP) on Ubuntu 16 - Globo.Tech\" \/>\n<meta property=\"og:description\" content=\"This tutorial will show you how to setup NGINX, including PHP-FPM and MySQL on your Ubuntu 16.04 LTS Server. PHP, Apache and MySQL are some of the most...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.globo.tech\/learning-center\/setup-nginx-php-fpm-mysql-ubuntu-16\/\" \/>\n<meta property=\"og:site_name\" content=\"Globo.Tech\" \/>\n<meta property=\"article:published_time\" content=\"2016-06-17T15:40:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-11-24T22:02:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2016\/09\/GloboTech-Logo.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"963\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"GloboTech Communications\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"GloboTech Communications\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/setup-nginx-php-fpm-mysql-ubuntu-16\/\",\"url\":\"https:\/\/www.globo.tech\/learning-center\/setup-nginx-php-fpm-mysql-ubuntu-16\/\",\"name\":\"How to Setup NGINX, PHP-FPM, MySQL (LEMP) on Ubuntu 16 - Globo.Tech\",\"isPartOf\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#website\"},\"datePublished\":\"2016-06-17T15:40:06+00:00\",\"dateModified\":\"2017-11-24T22:02:49+00:00\",\"author\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87\"},\"description\":\"This tutorial will show you how to setup NGINX, including PHP-FPM and MySQL on your Ubuntu 16.04 LTS Server. PHP, Apache and MySQL are some of the most...\",\"breadcrumb\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/setup-nginx-php-fpm-mysql-ubuntu-16\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.globo.tech\/learning-center\/setup-nginx-php-fpm-mysql-ubuntu-16\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/setup-nginx-php-fpm-mysql-ubuntu-16\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.globo.tech\/learning-center\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Setup NGINX, PHP-FPM, MySQL (LEMP) on Ubuntu 16\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#website\",\"url\":\"https:\/\/www.globo.tech\/learning-center\/\",\"name\":\"Globo.Tech\",\"description\":\"Welcome to the Official Globo.Tech Learning Center\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.globo.tech\/learning-center\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87\",\"name\":\"GloboTech Communications\",\"sameAs\":[\"http:\/\/www.gtcomm.net\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Setup NGINX, PHP-FPM, MySQL (LEMP) on Ubuntu 16 - Globo.Tech","description":"This tutorial will show you how to setup NGINX, including PHP-FPM and MySQL on your Ubuntu 16.04 LTS Server. PHP, Apache and MySQL are some of the most...","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:\/\/www.globo.tech\/learning-center\/setup-nginx-php-fpm-mysql-ubuntu-16\/","og_locale":"en_US","og_type":"article","og_title":"How to Setup NGINX, PHP-FPM, MySQL (LEMP) on Ubuntu 16 - Globo.Tech","og_description":"This tutorial will show you how to setup NGINX, including PHP-FPM and MySQL on your Ubuntu 16.04 LTS Server. PHP, Apache and MySQL are some of the most...","og_url":"https:\/\/www.globo.tech\/learning-center\/setup-nginx-php-fpm-mysql-ubuntu-16\/","og_site_name":"Globo.Tech","article_published_time":"2016-06-17T15:40:06+00:00","article_modified_time":"2017-11-24T22:02:49+00:00","og_image":[{"width":1920,"height":963,"url":"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2016\/09\/GloboTech-Logo.png","type":"image\/png"}],"author":"GloboTech Communications","twitter_misc":{"Written by":"GloboTech Communications","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.globo.tech\/learning-center\/setup-nginx-php-fpm-mysql-ubuntu-16\/","url":"https:\/\/www.globo.tech\/learning-center\/setup-nginx-php-fpm-mysql-ubuntu-16\/","name":"How to Setup NGINX, PHP-FPM, MySQL (LEMP) on Ubuntu 16 - Globo.Tech","isPartOf":{"@id":"https:\/\/www.globo.tech\/learning-center\/#website"},"datePublished":"2016-06-17T15:40:06+00:00","dateModified":"2017-11-24T22:02:49+00:00","author":{"@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87"},"description":"This tutorial will show you how to setup NGINX, including PHP-FPM and MySQL on your Ubuntu 16.04 LTS Server. PHP, Apache and MySQL are some of the most...","breadcrumb":{"@id":"https:\/\/www.globo.tech\/learning-center\/setup-nginx-php-fpm-mysql-ubuntu-16\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.globo.tech\/learning-center\/setup-nginx-php-fpm-mysql-ubuntu-16\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.globo.tech\/learning-center\/setup-nginx-php-fpm-mysql-ubuntu-16\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.globo.tech\/learning-center\/"},{"@type":"ListItem","position":2,"name":"How to Setup NGINX, PHP-FPM, MySQL (LEMP) on Ubuntu 16"}]},{"@type":"WebSite","@id":"https:\/\/www.globo.tech\/learning-center\/#website","url":"https:\/\/www.globo.tech\/learning-center\/","name":"Globo.Tech","description":"Welcome to the Official Globo.Tech Learning Center","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.globo.tech\/learning-center\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87","name":"GloboTech Communications","sameAs":["http:\/\/www.gtcomm.net"]}]}},"_links":{"self":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/1989","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/comments?post=1989"}],"version-history":[{"count":10,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/1989\/revisions"}],"predecessor-version":[{"id":3882,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/1989\/revisions\/3882"}],"wp:attachment":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/media?parent=1989"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/categories?post=1989"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/tags?post=1989"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}