LEMP is an acronym for Linux, Nginx (Engine-x) MariaDB and PHP. It’s based on a collection of opensource software that powers many popular websites and web applications.
One can use LEMP to run WordPress, Joomla, Drupal and other PHP-based content management systems on Linux machines.
This brief tutorial is going to show students and new users how to easily install the LEMP stack on Ubuntu 17.04 / 17.10 if you haven’t already done so.
To get started with install LEMP, follow the steps below:
Step 1: Ubuntu
The LEMP or LAMP stack always begins with the Linux systems. There are many Linux distributions in used today, however, the most popular is Ubuntu. For this post, we’re going to be using Ubuntu Linux as our LEMP based system.
This post also assumes that you have already installed Ubuntu and that you have administrative rights to install packages and make changes.
After installing Ubuntu, run the commands below to update the Ubuntu machine.
sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get autoremove
You may want to restart the machine after running the commands above..
Step 2: Install Nginx
Now that the Ubuntu machine is updated, run the commands below to install Nginx web server. Nginx is an alternative to Apache2 and uses system resources very efficiently.
sudo apt-get install nginx
After installing Nginx, the commands below can be used to stop, start and enable Nginx webserver to always start up when the system boots.
sudo systemctl stop nginx.service
sudo systemctl start nginx.service
sudo systemctl enable nginx.service
To test whether Nginx is working, open your browse and browse to the server IP or hostname and you should see Nginx’s default welcome page.
Step 3: Install MariaDB
MariaDB is a fork and a drop-in replacement for MySQL. MariaDB is an alternative to MySQL and is rapidly gaining popularity. To install MariaDB, run the commands below.
sudo apt-get install mariadb-server mariadb-client
After installing MariaDB, the commands below can be used to stop, start and enable MariaDB to always start up when the system boots.
sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
Another thing to do after installing MariaDB is to secure it. To do that, run the commands below.
You’ll be prompted with series of questions, follow the guide below to answer
Enter current password for root (enter for none): PRESS ENTER
Set root password? [Y/n] Y
CREATE YOUR PASSWORD
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
To test whether MariaDB is functioning, run the commands below to logon to the server.
sudo mysql -u root -p
When prompted for the password, type the password you created above to logon. If you successfully logon, you should see MariaDB welcome message.
Step 4: Install PHP and Related Modules
PHP is the last component of LEMP. It allows dynamic websites and applications to be created. Majority of the CMS in used today are using PHP. To install PHP and related modules, run the commands below
sudo apt-get install php php-fpm php-mysql php-curl php-gd php-pear php-imagick php-imap php-mcrypt php-recode php-tidy php-xmlrpc
Running the commands above may also download Apache2 server. Run the commands below to disable Apache2
sudo systemctl disable apache2.service
To test whether PHP is installed and functioning, create a test PHP script in Nginx document root directory by running the commands below.
sudo nano /var/www/html/phpinfo.php
Then copy and paste the content below in the file and save.
After saving the file, open your browser and browse to the server IP or hostname.. and you should see PHP test info page.
This is how to install LEMP on Ubuntu.
This post shows students and users how to easily install Nginx, MariaDB and PHP on Ubuntu servers. It’s a beginning to running dynamic websites and applications based on PHP.
If you’re going to be running most content management systems, then this might be the first post to read.
You may also like the post below:
Installing Moodle on Ubuntu 17.04 / 17.10