How to Install LEMP Stack on Ubuntu 20.04

ubuntu focal fossa mysql 8

In this blog post, I want to share how to install LEMP stack on Ubuntu 20.04 since I already have Ubuntu 20.04 installed on my machine.

If you need a VPS hosting, I would like to suggest for you to use Upcloud VPS Hosting. You can get $25 free credit if you register from my affiliate link here.

For those who are unfamiliar with LEMP/LNMP, it is Linux, Nginx, MySQL, and PHP which is a technology stack for web development and hosting web application.

We will install Nginx web server, MySQL 8 and PHP 7.4 on Ubuntu 20.04.

How to install Nginx

You may connect to your ubuntu using SSH. Then run the install command:

sudo apt install nginx -y

After the installation done, you should get the Nginx default homepage as screenshot below:

Nginx default page

How to install MySQL 8

I actually have covered this topic in my previous post; How to Install MySQL 8 on Ubuntu 20.04. You also can install other MySQL 8 alternatives such as MariaDB or PerconaDB depending on your use case/requirements.

How to install PHP 7.4

Run the below commands to update your apt and install PHP 7.4-FPM.

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php7.4-fpm

# install module for mysql
sudo apt install php7.4-{mysqli,pdo_sql}

After installation is finished, run this command to verify your PHP version

php -v

To check what PHP module is currently enable/installed

php -m

You might need to install additional PHP modules based on your requirements. If you want to use this LEMP stack for Laravel application, the common PHP modules required by Laravel 7 are bcmath, ctype, fileinfo, json, mbstring, openssl, tokernizer, and xml.

And that’s it. You have successfully install LEMP stack on Ubuntu 20.04. The steps are almost the same no matter which VPS cloud hosting you are using.

Bonus

If you purchase the Upcloud VPS via my affiliate link, let me know and I’ll help you set up the LEMP stack for FREE.