How to Install a LAMP Stack on Debian 11

In this guide, we’ll set up a LAMP stack (Linux, Apache, MySQL/MariaDB, PHP) on a Debian 11 server. A LAMP stack is one of the most common foundations for hosting dynamic websites and web applications, and once it’s in place you’ve got everything you need to run anything from WordPress to your own custom app.

Step 1: Install the Apache Web Server

Start with Apache, then start the service and enable it so it comes back up automatically after a reboot:

sudo apt install apache2 apache2-utils -y
sudo systemctl start apache2
sudo systemctl enable apache2

You can confirm it’s running with:

systemctl status apache2

To check it’s actually serving pages, open a browser and go to your server’s IP address, where you should see the default Apache welcome page.

Step 2: Install the MariaDB Database Server

Next install MariaDB, then start and enable it the same way:

sudo apt install mariadb-server -y
sudo systemctl start mariadb
sudo systemctl enable mariadb

Check it came up cleanly:

systemctl status mariadb

A fresh MariaDB install ships with some insecure defaults, so run the built-in hardening script:

sudo mysql_secure_installation

Follow the prompts to set a root password, remove the anonymous users, disallow remote root login, and drop the test database. Saying yes to all of these is the safe default for a server you’re going to expose to any kind of traffic.

Step 3: Install PHP

Finally, install PHP along with the Apache module and the extensions most applications need. The php-mysql module in particular is what lets PHP talk to your new database:

sudo apt install php libapache2-mod-php php-cli php-mysql php-zip php-curl php-xml -y

Verify PHP is installed and check its version with:

php -v

That’s the full stack in place. Apache is serving pages, MariaDB is running and secured, and PHP is wired into Apache, so you’ve now got a solid base to build on. From here you can drop in an application like WordPress, or point a virtual host at your own project.

Related guides


Comments

Leave a Reply

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