How to Install LEMP on Debian 10?

— Published on: August 6th, 2019

After a long-time Debian is finally released their latest built called Debian 10 Buster. As we collected some data about the latest build, it is clear that Debian 10 is featured rich with the latest stable software for a server. In this tutorial, we will see how to install LEMP (Linux, Nginx, MySQL, and PHP) stack on Debian 10, Buster.

Debian

Vultr (aff. link) is one of the most trusted Cloud VPS Provider. I personally use their servers for most of my tasks and they are reliable enough to compete with others.

First, all we need is a Debian 10 clean server. Make sure nothing is pre-installed. To get started ssh into the server and access the root user.

Just to make sure everything is updated run following command.

apt update
apt upgrade

Now we can move ahead to install our LEMP stack.

Install Nginx

Nginx will be our web server and it is very easy to install.

apt install nginx -y

Or you can choose to install latest available mainline nginx or stable nginx from the below link.

http://nginx.org/en/linux_packages.html#Debian

Install MariaDB (MySQL)

MariaDB is similar to MySQL but with better performance and stability.

apt install mariadb-server -y

Now we need to secure the default installation of MariaDB. Just run following command mysql_secure_installation and follow the instructions.

Enter current password for root (enter for none): ⏎ - Hit Enter
Set root password? [Y/n] ------------------------ Y
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

We have successfully secured the database access from remote logins. It will be accessible from localhost only. In case you need one for remote logins then create a new user with root privileges and secure it with hard to guess password.

mariadb
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' IDENTIFIED BY 'usersecret' WITH GRANT OPTION;
exit

Just make sure you use a different username and a strong usersecret password.

Install PHP

Debian 10 released with the recent PHP7.3 version which was the fastest version of itself. But here we will install the latest PHP7.4 version with some common and needed libraries too.

First install the prerequisites.

apt install lsb-release apt-transport-https ca-certificates wget -y

Download the SURY PPA for PHP 7.4 and then set up the apt repository for it.

wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list

Update the repository index.

apt update
apt install php7.4-{fpm,cli,common,gd,mbstring,mysql,xml,xmlrpc,imagick,zip} -y

By default, everything will be running without any issue. By any chance, if anything is not working then restart all the services once to make sure everything is running.

service mysql restart
service php7.4-fpm restart
service nginx restart

That is it. Your LEMP setup is complete on Debian 10.

Now you can use this setup as you want to.

You can further install and setup phpMyAdmin, WordPress CMS or anything else.

Related Tutorials:

Published in Tech Tutorials & Labeled with , , , , , , ,

About AtulHost

Hi, I'm Atul Kumar Pandey; also known as AtulHost on the web, a blogger by profession with an objective of sharing fresh and real contents in the business and technical topics; from contents to useful resources it's all here.

Leave a Reply