Hey folks, in this tutorial I will explain how to install LEMP stack in 10 minutes. Technologies we are going to use are Ubuntu 18.04, Nginx (custom build), MariaDB(an optimized version of MySQL), PHP7.x. Let’s jump into the tutorial. But the OS is not limited to Ubuntu 18.04. You can use Ubuntu 19.04 or Debian 9 (Debian 10 is supported but haven’t tested yet).
I’m pretty much sure that you know what LEMP stack is. Since the reason, you found this article is you need to know how to install LEMP stack. Anyway, here’s a brief introduction those who don’t familiar with this stack.
What is LEMP stack?
This is an acronym that describes a Linux operating system, with an Nginx (pronounced like “Engine-X”) webserver. The backend data is stored in the MySQL database (in this tutorial, we are going to use MariaDB ↱) and PHP handles the dynamic processing.
Sounds familiar? Perhaps, you have heard about LAMP stack ↱. It’s pretty much a similar stack of components as LAMP, except the Apache is being replaced by Nginx. There are some advantages and disadvantages when comparing both of these technologies. I will compare these two technologies in a future article.
Installing LEMP stack
Installing and configuring (fine-tuning) a server is not an easy task even for experienced developers. Thanks to awesome open source community, we can install the whole stack in few lines of commands. Big thumbs up hard work 👍. We are going to use WordOps ↱ to setup LEMP stack. There are so many features available in WordOps toolset. You can find out more information from their documentation ↱ page. Some parts of the docs haven’t updated yet for the latest version so you’d better follow my steps for proper installation. WordOps is originally developed for WordPress websites but we going to use it to host any PHP, MySQL website.
- ~100MB of storage
- 512MB RAM
- Multi-core CPU
- 20GB SSD storage
- 2GB RAM
Other than that, you are more than free to walk around GCP, AWS, and Azure.
|Ubuntu||18.04 LTS (bionic)||x86_64|
- Open up your terminal/putty window using SSH or you can use the integrated web terminal.
- Update your repositories
sudo apt update
- Make sure that you have installed wget ↱
wget --versionand hit enter, if you get a message like “Command ‘wget’ not found” first of all you have to install wget. If you can see wget description and version number, just skip this step.
sudo apt install wget -ythis command will install wget on your server.
- Enable UFW to enable necessary ports. (ufw might be enabled by default) Use
sudo ufw statusto check the status. If the status shows “inactivated” use the following command to enable
sudo ufw enableit.
You might see more than two records. If you see HTTP and HTTPS(Port 80 and 443) rules, you can skip step 5.
- Add HTTP and HTTPS rules
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
- Restart UFW
sudo systemctl restart ufw
- Setup is almost completed now we need to download and install WordOps installer
wget -qO wo wops.cc && sudo bash wo
After you hit enter the script will ask your name and email. Provide those details and wait for the installation. It will take up to 5 minutes.
Wola! You have successfully installed LEMP stack on your Ubuntu VPS. It wasn’t hard. Right? 🙂
Create a Webspace
You have done an amazing job so far. Let’s create your PHP 7.3 and MySQL webspace.
- Replace ‘site.tld’ with your domain name.
sudo wo site create site.tld --mysql --php73
This command will automatically configure Nginx and create a database for you.
Easy enough? 😇
Things to note :
- Make sure to point your domain to the server IP.
- Webspace location (htdocs)
- MySQL information
- If you navigate to your ‘site.tld’ it will show ‘403 Forbidden’ message until you add index file to ‘htdocs’.
- Need to learn more about WordOps CLI? Check their awesome Docs.
LEMP stack is very popular around the world and most of the popular websites powered by this powerful stack. Even my The Inspired Dev website uses the same stack. Everything made so easy thanks to WordOps team.
Let me know if you have any questions about this article in the comment section. Also, suggestions are warmly welcome.