How To Install The LEMP Stack On Ubuntu Linux

0 Comments

The LEMP stack is a group of open-source software that is usually installed together to enable a server to host websites and web applications. The acronym represents L for the Linux Operating System, E for Nginx(Engine X) Web Server, M for MySQL, and P for PHP. In this tutorial, we will cover how to install the LEMP stack on Ubuntu Linux.

Update Software Packages

Before we start the installation it is a good idea to update software packages with the following command:

sudo apt update

Install Nginx Web Server

Next, we will install Nginx Web Server:

sudo apt install nginx

Once the installation is completed the Nginx service should be automatically started. Check Nginx’s status with systemctl:

sudo systemctl status nginx

If it is a case that Nginx is not running then run the following command:

sudo systemctl start nginx

Also, configure Nginx to start automatically when your server or instance boots up:

sudo systemctl enable nginx

Ensure that HTTP traffic is allowed through the firewall :

sudo ufw allow http

You can then type in your server IP address into a browser on your local network to see the default Nginx Web Server page.

Nginx Default Web Page

Install MySQL(MariaDB)

Once the webserver is up and running we will install MySQL(MariaDB) next. MariaDB is a community-developed fork of the MySQL relational database management system. Run the following command to start installing MariaDB:

sudo apt install mariadb-server mariadb-client

Once the installation is completed you should check the status to see if MariaDB is active with the following command:

sudo systemctl status mariadb

Sample output:

mariadb.service - MariaDB 10.1.34 database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2018-09-08 11:13:27 UTC; 21s ago
     Docs: man:mysqld(8)
           http://mariadb.com/kb/en/library/systemd/
 Main PID: 3473 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 27 (limit: 505)
   CGroup: /system.slice/mariadb.service
           └─3473 /usr/sbin/mysqld

If it is not running you can start the MariaDB server with the following command:

sudo systemctl start mariadb

The next step is to enable MariaDB to start automatically at system boot:

sudo systemctl enable mariadb

Once the MariaDB service is up and running, the next step is to start the MySQL installation script:

sudo mysql_secure_installation

When it prompts you for the MariaDB root password you can go ahead and press enter and then enter y to set the root password for the MariaDB server. Next, you can press enter through the remaining steps which will remove the anonymous user, disable remote root login, and remove the test database.

Install PHP

The last step is to install PHP on your Ubuntu Linux server or instance:

sudo apt-get install php-fpm php-mysql

Once PHP is installed create a script info.php under the webroot directory:

sudo vi /var/www/html/info.php

The script will create a blank file and then we will add the following PHP code inside the file:

<?php
phpinfo();
?>

Once all the above steps are completed view the info.php page in the web browser using the server IP:

http://<server_ip_address>/info.php

The page will look similar to the one below:

PHP Info Web Page
Donation:

We are passionate Opensource and Linux bloggers. We enjoy writing articles, maintianing the website and hosting it for free for anyone looking to read some of our listicles and how to blog articles. If you enjoy reading our blogs kindly consider making a donation as appreciation.

Chad Crouch

DevOps Engineer experienced in multiple enterprise environments. Has a huge passion for the open-source world specifically Linux and Opensource Software.

Comments