How to install LEMP on Debian 10?

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

Linode (ref. link) is one of the most trusted cloud VPS providers. I personally use their servers for most of my tasks and they are reliable enough to compete with others.

To be honest, this blog is also hosted on Linode’s VPS, and I never face any issue.

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 the following commands.

apt update
apt upgrade

If the upgrade was a big one, better reboot the server. You can skip this step, nothing will affect if you do not boot, but it is a good habit to avoid any future issue.

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 the 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 was 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

Now install PHP and some of its modules.

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 set up phpMyAdmin, WordPress CMS, or anything else.

Related Tutorials:

Leave a Reply

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