1. Home
  2. Linux
  3. How to set up a lamp server on debian 11

How to set up a LAMP server on Debian 11

While many people think of Debian as a rock-solid workstation operating system, that’s not all it can be used for. Debian is also one of the most used Linux-based server operating systems.

There are a lot of server applications for Debian. However, one of the most popular things users set up is LAMP. LAMP is Linux, Apache, MySQL, and PHP, and it is essential for hosting web apps. Here’s how you can set up a LAMP server on Debian 11.

Upgrading to Debian 11

To get the most out of your LAMP server (Linux, Apache, MySQL, and PHP), you need to upgrade your Debian release to Debian 11. Debian 11 Bullseye is the latest version of the operating system and is ideal for hosting web apps using MySQL, Apache, and PHP.

To upgrade to Debian 11, ensure you have your data backed up. Once you do, open up a terminal window. Alternatively, connect to Debian over the SSH console and start the upgrade process by following the instructions below.

Log into your root account using the su command when you have terminal access. You must have root access to upgrade.

su -

Once logged in as root, use the sed command to change the codename of your Debian release from “buster” (Debian 10) to “bullseye” (Debian 11). The codename must be changed to upgrade.

sed -i 's/buster/bullseye/g' /etc/apt/sources.list

Next, run the apt update command, followed by the apt upgrade command. These two commands will refresh Debian’s software sources, check for new packages, and install pending upgrades.

sudo apt update
sudo apt upgrade

Finally, upgrade to Debian 11 Bullseye with the dist-upgrade command.

sudo apt dist-upgrade

Reboot Debian and log in to set up your LAMP server when all commands have finished.

Installing PHP and MySQL

PHP and MySQL are critical parts of a LAMP server. Do the following to set these two tools up onto your Debian 11 system. First, check for any updates that may be available for your system and install them.

sudo apt update
sudo apt upgrade

With all of the updates installed on your Debian 11 system, use the apt install command to set up the following PHP and MySQL packages.

sudo apt install mariadb-server php libapache2-mod-php php-zip php-mbstring php-cli php-common php-curl php-xml php-mysql

Upon entering the command above, Debian will ask you if you wish to continue with the installation. To confirm you want to install the PHP and MySQL packages on Debian 11, press the Y key on your keyboard to ensure that you wish to install the software.

Installing all of the MySQL and PHP packages on Debian 11 will take time to complete. When the process is finished, move on to the next section of the guide.

Configuring MySQL

Once MySQL is installed on your Debian 11 system, you must configure it with the mysql_secure_installation command. Open up a terminal window and start up the installation.

sudo mysql_secure_installation

Note: if you encounter “ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock,” run
service mysqld
start, then re-run the sudo mysql_secure_installation command.

The installer will ask you to “Enter current password for root when the command above is entered.” As SQL was just installed, there’s no need to enter a password. Press the Enter key to continue.

You’ll now be asked if you want to protect your root account. As the root is already protected, the installer instructs you to press n to continue. Do so.

MySQL will now ask you to change the root password. Press Y, then enter a secure, memorable SQL password.

After entering a new root password for MySQL, it will ask you to remove anonymous users. Press the Y button so users cannot log in anonymously with the test account.

Once the anonymous account is deleted, you’ll be asked if you want to enable remote root login. Leaving remote root login should only be done if you are an expert and understand the risks. Press N to disable remote login as root.

With remote root disabled, you must delete the “test” database. To delete it, press the Y key. Then, reload the privilege tables by pressing Y. When privileges tables are reloaded, MySQL is configured on your system.

Installing Apache2 web server

Some Apache2 web server packages were also installed during the PHP and MySQL package setup. However, you must still install the “apache2” package to use the Apache2 webserver on your Debian 11 system.

Using the apt install command, set up the Apache2 web server.

sudo apt install apache2

Once installed, Debian should automatically start up the default web server, running the Apache default web page. Navigate to /var/www/html/ and replace the “index.html” file with your files to customize your website.

You can access any webpage hosted on your computer in a web browser by accessing the following URL.




Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.