_:ne0226c2c80ac4833b7a4b5f8640e99bcxb0
<http://schema.org/articleBody>
"Once you have an idea for a complex website or a web application, before you even start working on its design, you should decide how the backend will look like. If you are new to the world of web hosting, here are some basic software components you need to host a web app:\r\n\r\nServer operating system\r\nWeb server software\r\nDatabase\r\nScripting language for dynamic content\r\n\r\nWhen combined all together, it is called a web hosting stack. While there are many possible stacks out there, some are more popular than others, such as LEMP. In today&rsquo;s article we will discuss the different components that make up this stack, followed by a detailed step-by-step tutorial on how to install it on Ubuntu.\r\n&nbsp;\r\nWhat is LEMP?\r\nLEMP is an acronym for Linux, Nginx, MySQL, and PHP. LEMP stack, just like the LAMP stack (with Apache instead of Nginx), is used for the development and deployment of web applications. Nginx in LEMP provides modular event-driven architecture handling requests using asynchronous events. This feature enables it to have high performance even under high loads. MySQL is used to store the website&rsquo;s data whereas PHP is for processing the dynamic content of the sites.\r\n&nbsp;\r\nPrerequisites\r\nThis is all that you need in order to install the LEMP stack on your Ubuntu VPS/Server.\r\n\r\nA&nbsp;Linux VPS running Ubuntu version 18.04\r\nUsername and password for your&nbsp;VPS Server.\r\n\r\n&nbsp;\r\nHow to Install LEMP on Ubuntu 18.04\r\nThis tutorial is split into distinctive parts, each with its own step numbers. We strongly recommend following the order outlined in this article. Also, please note that the commands used to complete each step are written after each one.\r\n&nbsp;\r\nPart 1: Connect to your server via SSH\r\nAll VPS plans allow SSH access. You should therefore connect to your&nbsp;Ubuntu server with the public IP address that was allocated to you. If you are running Windows as your local computer, consider downloading the PuTTY SSH client. You can also initiate an SSH connection from Mac or Linux using the inbuilt SSH client Terminal.\r\nFor more info on&nbsp;how to connect to a Linux VPS,&nbsp;click here.\r\n&nbsp;\r\nPart 2: Install Nginx server\r\nStep 1: Update your software packages.\r\n$ sudo apt update\r\nStep 2: Install Nginx\r\n$ sudo apt install nginx\r\nStep 3: Once you have installed it, the&nbsp;Nginx&nbsp;service should start automatically and will be enabled to start at boot time, you can check if it&rsquo;s up and running using the following code.\r\n$ sudo systemctl status nginx\r\nStep 4: If you have a firewall enabled and running on your system, you should open ports 80&nbsp;(HTTP) and&nbsp;443(HTTPS) to allow client requests to the Nginx web server, and reload the firewall rules.\r\n$ sudo ufw allow 80/tcp\r\n$ sudo ufw allow 443/tcp\r\n$ sudo ufw reload\r\nStep 5: Next, test if the&nbsp;Nginx package was successfully installed and is working fine. Type your server's IP address in your web browser. If you see the Nginx default web page, it means your installation is working fine.\r\n&nbsp;\r\nPart 3: Install MySQL\r\nNow that you have a web server, you need to install MySQL (a database management system) to store and manage the data for your site.\r\nStep 1: Update your software packages.\r\n$ sudo apt update\r\nStep 2: Install MySQL\r\n$ sudo apt install mysql-server\r\nStep 3: Press &ldquo;y&rdquo;&nbsp;and&nbsp;&ldquo;Enter&rdquo;&nbsp;when prompted to install the MySQL package.\r\nStep 4: Once the package installer has finished, we can check to see if the MySQL service is running.\r\n$ sudo service mysql status\r\nIf it is running, you will see a green active status like the one shown below.\r\n\r\nmysql.service - MySQL Community ServerLoaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled (Active: active (running) since Wed 2018-05-09 21:10:24 UTC; 16s agoMain PID: 30545 (mysqld)Tasks: 27 (limit: 1153)CGroup: /system.slice/mysql.service30545 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid&nbsp;\r\n\r\nYou may need to press&nbsp;&ldquo;q&rdquo;&nbsp;to exit the service status.\r\n&nbsp;\r\nPart 4: Configure MySQL Security\r\nStep 1: You should now run&nbsp;mysql_secure_installation to configure security for your MySQL server.\r\n$ sudo mysql_secure_installation\r\nStep 2: If you have a root password, you&nbsp;may be prompted to enter it here, otherwise you will be asked to create one.\r\nStep 3: You will be asked if you want to set up the Validate Password Plugin. It&rsquo;s not really necessary unless you want to enforce strict password policies. Press&nbsp;&ldquo;n&rdquo;&nbsp;and&nbsp;&ldquo;Enter&rdquo;&nbsp;here if you don&rsquo;t want to set up the validate password plugin.\r\nVALIDATE PASSWORD plugin can be used to test passwords and improve security. It checks the strength of the passwords and allows the users to set only those passwords which are secure enough, meaning you cannot use blank passwords.&nbsp;\r\nStep 4: You will be prompted with: Remove anonymous users?&nbsp;Press&nbsp;&ldquo;y&rdquo;&nbsp;and&nbsp;&ldquo;Enter&rdquo;&nbsp;to do so.\r\nBy default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing and to make the installation go a bit smoother. You should remove them before moving into a production environment.\r\nStep 5: The next prompt you will encounter is: Disallow root login remotely?&nbsp;Press&nbsp;&ldquo;y&rdquo;&nbsp;and&nbsp;&ldquo;Enter&rdquo;&nbsp;to disallow root login remotely.\r\nNormally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess the root password from the network.\r\nStep 6: The following prompt will look like this: Remove test database and access to it? Press&nbsp;&ldquo;y&rdquo;&nbsp;and&nbsp;&ldquo;Enter&rdquo;&nbsp;to remove the test database.\r\nBy default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing and should be removed before moving into a production environment.\r\nStep 6: Lastly, you will see: Reload privilege tables now?&nbsp;Press&nbsp;&ldquo;y&rdquo;&nbsp;and&nbsp;&ldquo;Enter&rdquo;&nbsp;to&nbsp;reload the privilege tables.\r\nReloading the privilege tables will ensure that all changes made so far will take effect immediately.\r\nStep 7: As a test, you can log into the MySQL server and run the&nbsp;version&nbsp;command.\r\n$ sudo mysqladmin &ndash;p &ndash;u root version\r\nStep 8: Enter the MySQL root password you created earlier and you should see the following:\r\n\r\n$ sudo mysqladmin &ndash;p &ndash;u root versionmysqladmin&nbsp; Ver 8.42 Distrib 5.7.22, for Linux on x86_64Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Server version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5.7.22-0ubuntu18.04.1Protocol version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10Connection&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Localhost via UNIX socketUNIX socket&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /var/run/mysqld/mysqld.sockUptime:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4 min 28 secThreads: 1&nbsp; Questions: 15&nbsp; Slow queries: 0&nbsp; Opens: 113&nbsp; Flush tables: 1&nbsp; Open tables: 106&nbsp; Queries per second avg: 0.055\r\n\r\nYou have now successfully installed and configured MySQL for Ubuntu 18.04! Continue to the next part to install PHP.\r\n&nbsp;\r\nPart 5: Install PHP on Ubuntu 18.04\r\nPHP&nbsp;is a popular server-side scripting language used to generate dynamic content on websites. You can install&nbsp;PHP,&nbsp;PHP-FPM, and other modules for web development using the following command (the default version in the Ubuntu repos is&nbsp;PHP 7.2).\r\nStep 1: Install PHP and required modules\r\n$ sudo apt install php php-fpm php-common php-mysql php-gd php-cli\r\nStep 2: After&nbsp;PHP&nbsp;installation, the&nbsp;PHP7.2-FPM&nbsp;service should also start automatically, you can verify the service is running using the following command.\r\n$ sudo systemctl status php7.2-fpm\r\nStep 3: Next, configure&nbsp;PHP-FPM properly to serve PHP-based web applications or sites, in the configuration file&nbsp;/etc/php/7.2/fpm/php.ini by opening it with an editor, for this example, we are using vim.\r\n$ sudo vim /etc/php/7.2/fpm/php.ini\r\nStep 4: In the opened file, search for the&nbsp;cgi.fix_pathinfo=1&nbsp;and change it to the following.\r\ncgi.fix_pathinfo=0\r\nStep 5: Then configure&nbsp;PHP-FPM&nbsp;to process PHP scripts in Nginx default server block configuration file (/etc/nginx/sites-available/default) by opening it with a text editor.\r\n$ sudo vim /etc/nginx/sites-available/default\r\nStep 6: Uncomment the configuration section below to pass PHP scripts to&nbsp;FastCGI&nbsp;server.\r\nlocation ~  .php$ {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; include snippets/fastcgi-php.conf;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;}\r\nStep 7: After making changes, restart the&nbsp;php7.2-fpm and Nginx&nbsp;services to apply the recent changes.\r\n$ sudo systemctl restart php7.2-fpm\r\n$ sudo systemctl restart nginx\r\nStep 8: Now you can test your PHP setup by creating a simple&nbsp;info.php&nbsp;page in your web server document root, with this single command.\r\n$ echo  | sudo tee /var/www/html/info.php\r\nStep 9: Next, open a web browser, and enter any of the following URL to view the PHP information page.\r\nhttp://domain_name/info.phpORhttp://SERVER_IP/info.php\r\n&nbsp;\r\nAnd that&rsquo;s it, the LEMP stack should now be installed on your Linux server. LEMP can also be installed on other Linux distributions too such as Debian, here is a complete guide on installing LEMP on Debian.\r\n&nbsp;\r\nConclusion\r\nWe hope that by following all the steps outlined in this blog, you were able to successfully install the LEMP stack on your Linux server as well as learned a little about the stack itself. If you have any questions or suggestions please leave them in the comment section down below. You could also post your request if you wish to see tutorials for the installation of the LEMP stack on other operating systems, or the installation of other stacks on Ubuntu."
<https://monovm.com/blog/how-to-install-lemp-on-ubuntu1804/>