Students Tutorial – Install Ubuntu Linux, Nginx, MariaDB and PHP (LEMP)

This post is going to show students and new users how to put together a perfect system to power their websites or blogs. As you may already know, the LAMP or LEMP stack powers more websites and blogs online today than any other platform.

Some folks prefer LAMP, which is an acronym for Linux, Apache2, MySQL and PHP. However, more and more webmasters are now choosing LEMP over LAMP. LEMP is an acronym for Linux, Engine-X (Nginx), MariaDB or MySQL and PHP.

When you put Ubuntu Linux, Nginx, MariaDB and PHP together to power your websites, your users and visitors will notice and appreciate the capabilities of your websites or blogs.

To get started with installing and configuring the most efficient web stack, continue below:

Step 1: Install and Configure Ubuntu Linux

The L in LEMP stands for Linux and Ubuntu Linux is a great place to start. Fortunately, we’ve shown our students how to install Ubuntu on this blog and many tutorials online will show you steps to get Ubuntu installed on your machine.

After Ubuntu is installed, you should run the commands below to update it before installing other components of the LEMP stack.

Run the commands below to update Ubuntu server correctly.

sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get autoremove

The commands above update and upgrade all installed packages and remove obsolete software and kernel headers from your system. Once done, you may want to reboot your Ubuntu machine before continuing.

Step 2: Install Nginx Web Server

Nginx webserver has become one of the fastest growing webservers online. It’s lightweight and fast, more efficient with system resources and very easy to configure and manage. Nginx packages also are available in Ubuntu default repositories. So one only needs to run apt-get install nginx to have Nginx installed.

To install Nginx on Ubuntu run the commands below

sudo apt-get install nginx

The commands above install a more stable version of Nginx. To install the latest and greatest version of Nginx, read the post below:

Lesson 29: Installing Nginx Webserver Latest on Ubuntu

After installing Nginx, the commands below are useful to manage Nginx

sudo systemctl stop nginx.service
sudo systemctl start nginx.service
sudo systemctl enable nginx.service

Step 3: Install MariaDB Database Server

MariaDB database server is also one of the fastest growing opensource database servers online today. More and more Linux distributions are ditching MySQL in favor of MariaDB. To install MariaDB on Ubuntu, run the commands below:

sudo apt-get install mariadb-server mariadb-client

The commands above install the more stable version of MariaDB. To learn how to get the latest and greatest version of MariaDB, read the post below:

Lesson 28: Install MariaDB Latest Version on Ubuntu

After installing MariaDB, the commands below are useful to manage MariaDB

sudo systemctl stop mysql.service
sudo systemctl start mysql.service
sudo systemctl enable mysql.service

To secure MariaDB and create a password for the root user, run the commands below:

sudo mysql_secure_installation

When you run the above command, you’ll be prompted to create a root password, remove anonymous users, disable remote root access and delete the test database.

Follow this guide below in answering the questions:


In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): Press Enter since you haven't created a password
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB 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.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Step 4: Install PHP 7-FPM  and Up

PHP is probably the most used web framework to run powerful blogs and websites online. It’s required to run WordPress, Drupal, Joomla and other PHP based content management systems. To install PHP on Ubuntu run the commands below:

sudo apt-get install php-fpm

The commands above install the a more stable version of PHP. Although will be installed by running the above command, to get more PHP based applications to function efficiently, you need other PHP modules. The most used modules can be installed using the commands below:

sudo apt-get -y install php-mysql php-curl php-gd php-pear php-imagick php-imap php-mcrypt php-recode php-tidy php-xmlrpc

That’s it! You should now have a complete system to install WordPress, Drupal and other powerful content management systems.

Disable Apache2 on Ubuntu

Now that Nginx is our default webserver, lets stop and disable Apache2 webserver if it’s already installed. To do that, run the commands below:

sudo systemctl stop apache2.service
sudo systemctl disable apache2.service


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.