{"id":5856,"date":"2018-12-16T16:56:17","date_gmt":"2018-12-16T16:56:17","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=5856"},"modified":"2018-12-28T21:14:15","modified_gmt":"2018-12-28T21:14:15","slug":"how-to-install-lemp-stack-on-ubuntu-18-04","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/12\/16\/how-to-install-lemp-stack-on-ubuntu-18-04\/","title":{"rendered":"How to install LEMP Stack on Ubuntu 18.04"},"content":{"rendered":"<h2>Install LEMP Stack On Ubuntu<\/h2>\n<p>LEMP stack stands for <em>Linux, Nginx, MariaDB, and PHP<\/em>. Here in LAMP stack which stands for <em>Linux, Apache, MariaDB <\/em>and<em> PHP<\/em>, all components are not tightly coupled. So by replacing Apache With Nginx, we are installing LEMP stack. This tutorial outlines how to install LEMP stack on Ubuntu 18.04.<\/p>\n<h3>Prerequisites<\/h3>\n<p>Before you start to install LEMP on Ubuntu 18.04. You must have a non-root user account on your server with sudo privileges.<\/p>\n<h3>1. Install NGINX<\/h3>\n<p>To <a href=\"https:\/\/linux4one.com\/how-to-install-nginx-on-ubuntu-18-04\">install Nginx<\/a> first update local package index to access most recent package listing by typing<\/p>\n<p>sudo apt update<\/p>\n<p>Now install Nginx by typing<\/p>\n<p>sudo apt install nginx<\/p>\n<p>You can check the <em>status<\/em> of Nginx by typing<\/p>\n<p>systemctl status nginx<\/p>\n<p>The output should be:<\/p>\n<p>Output:<br \/>\n\u25cf nginx.service &#8211; A high performance web server and a reverse proxy server<br \/>\nLoaded: loaded (\/lib\/systemd\/system\/nginx.service; enabled; vendor preset: enabled)<br \/>\nActive: active (running) since Fri 2018-07-01 16:08:19 UTC; 1 days ago<br \/>\nDocs: man:nginx(8)<br \/>\nMain PID: 2369 (nginx)<br \/>\nTasks: 2 (limit: 1153)<br \/>\nCGroup: \/system.slice\/nginx.service<br \/>\n\u251c\u25002369 nginx: master process \/usr\/sbin\/nginx -g daemon on; master_process on;<br \/>\n\u2514\u25002380 nginx: worker process<\/p>\n<h3>2. Install MariaDB<\/h3>\n<p>To <a href=\"https:\/\/linux4one.com\/how-to-install-mariadb-10-on-ubuntu-18-04\">install MariaDB<\/a> and related MySQL php extension type following command.<\/p>\n<p>sudo apt install mariadb-server php-mysql<\/p>\n<p>To setup secure installation enter following command, you will be prompted for the password which is not set previously that time press ENTER only.<\/p>\n<p>sudo mysql_secure_installation<\/p>\n<h3>3. Install PHP<\/h3>\n<p>By default Nginx does not support native PHP processing. So you will need to install <em>php-fpm (\u201cfastCGI process manager\u201d) <\/em>package to <a href=\"https:\/\/linux4one.com\/how-to-install-php-7-2-on-ubuntu-18-04\">install PHP<\/a>. Now you can install php-fpm by typing following command.<\/p>\n<p>sudo apt install php-fpm<\/p>\n<p>You can check the status where it is correctly installed or not by following command<\/p>\n<p>systemctl status php7.2-fpm<\/p>\n<h3>4. Set up nginx configuration file<\/h3>\n<p>Create directory inside var\/www\/html named example.com (you can use your domain name).<\/p>\n<p>sudo mkdir -p \/var\/www\/html\/example.com<\/p>\n<p>Now you should <em>remove the default configuration file<\/em> provided. To remove default Nginx configuration file type following.<\/p>\n<p>sudo rm -f \/etc\/nginx\/sites-enabled\/default<\/p>\n<p>Configuration files for the website are stored inside \/etc\/nginx\/sites-available directory so you need to create configuration file inside this directory named <u>example.com.conf<\/u> (you can use your domain name). Then enter following code inside that file by replacing <u>example.com<\/u> with your domain name.<\/p>\n<p>\/etc\/nginx\/sites-available\/example.com.conf<\/p>\n<p>server {<br \/>\nlisten 80 default_server;<br \/>\nlisten [::]:80 default_server;<\/p>\n<p>server_name example.com www.example.com;<br \/>\nroot \/var\/www\/html\/example.com;<br \/>\nindex index.php;<\/p>\n<p>location \/ {<br \/>\ntry_files $uri $uri\/ =404;<br \/>\n}<\/p>\n<p>location ~* .php$ {<br \/>\nfastcgi_pass unix:\/run\/php\/php7.2-fpm.sock;<br \/>\ninclude fastcgi_params;<br \/>\nfastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;<br \/>\nfastcgi_param SCRIPT_NAME $fastcgi_script_name;<br \/>\n}<br \/>\n}<\/p>\n<p>Create a link of above configuaration file inside \/etc\/nginx\/sites-enabled\/ directory by typing<\/p>\n<p>sudo ln -s \/etc\/nginx\/sites-available\/example.com \/etc\/nginx\/sites-enabled\/<\/p>\n<h3>5. Testing LEMP stack<\/h3>\n<p>Ensure your domain reaching at your server by configuring DNS records of your domain.<\/p>\n<p>Now you need to restart PHP and reload Nginx configuration file as you have made changes in Nginx configuration directory. Type following command to restart PHP and reload Nginx.<\/p>\n<p>sudo systemctl restart php7.2-fpmsudo nginx -s reload<\/p>\n<p>You can check the status of Nginx by typing following.<\/p>\n<p>sudo nginx -t<\/p>\n<p>Create an index.php file inside \/var\/www\/html\/example.com directory and enter following code inside the file.<\/p>\n<p>&lt;html&gt;<br \/>\n&lt;head&gt;<br \/>\n&lt;h2&gt;Index Page&lt;\/h2&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body&gt;<br \/>\n&lt;?php<br \/>\necho &#8216;&lt;p&gt;Hello,&lt;\/p&gt;&#8217;;<\/p>\n<p>\/\/ Define PHP variables for the MySQL connection.<br \/>\n$servername = &#8220;localhost&#8221;;<br \/>\n$username = &#8220;test_user&#8221;;<br \/>\n$password = &#8220;password&#8221;;<\/p>\n<p>\/\/ Creating a MySQL connection.<br \/>\n$conn = mysqli_connect($servername, $username, $password);<\/p>\n<p>\/\/ Show if the connection fails or is successful.<\/p>\n<p>if (!$conn) {<br \/>\nexit(&#8216;&lt;p&gt;Your connection has failed.&lt;p&gt;&#8217; . mysqli_connect_error());<br \/>\n}<br \/>\nelse {<br \/>\necho &#8216;&lt;p&gt;You have connected successfully.&lt;\/p&gt;&#8217;;<br \/>\n}<br \/>\n?&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n<h3>Conclusion<\/h3>\n<p>In this tutorial you have successfully learned how to install LEMP stack on Ubuntu 18.04. If you have any queries regarding this please don\u2019t forget to comment below.<\/p>\n<h3>Detailed tutorials<\/h3>\n<ul>\n<li><a href=\"https:\/\/linux4one.com\/how-to-install-nginx-on-ubuntu-18-04\">How to install Nginx on Ubuntu 18.04.<\/a><\/li>\n<li><a href=\"https:\/\/linux4one.com\/how-to-install-php-7-2-on-ubuntu-18-04\">Install PHP 7.2 on Ubuntu 18.04.<\/a><\/li>\n<li><a href=\"https:\/\/linux4one.com\/how-to-install-mariadb-10-on-ubuntu-18-04\">How to install MariaDB on Ubuntu 18.04. <\/a><\/li>\n<\/ul>\n<p><a href=\"http:\/\/lxer.com\/module\/newswire\/ext_link.php?rid=263806\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Install LEMP Stack On Ubuntu LEMP stack stands for Linux, Nginx, MariaDB, and PHP. Here in LAMP stack which stands for Linux, Apache, MariaDB and PHP, all components are not tightly coupled. So by replacing Apache With Nginx, we are installing LEMP stack. This tutorial outlines how to install LEMP stack on Ubuntu 18.04. Prerequisites &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/12\/16\/how-to-install-lemp-stack-on-ubuntu-18-04\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to install LEMP Stack on Ubuntu 18.04&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5856","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/5856","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=5856"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/5856\/revisions"}],"predecessor-version":[{"id":6465,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/5856\/revisions\/6465"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=5856"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=5856"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=5856"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}