In this tutorial, we will show you how to install LAMP Stack on Debian 11. For those of you who didn’t know, The LAMP Stack is a common set of open-source tools used to host websites and applications on the web. LAMP Stack is a web development platform that uses Linux as an operating system, Apache as a web server, MariaDB/MySQL as a database server, and PHP as a scripting language. It is so widely used and provides a proven set of software for delivering high-performance web applications.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of LAMP Stack on a Debian 11 (Bullseye).
Prerequisites
- A server running one of the following operating systems: Debian 11 (Bullseye).
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install LAMP Stack on Debian 11 Bullseye
Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt
commands in the terminal:
sudo apt update sudo apt upgrade
Step 2. Installing Apache Web Server.
By default, the Apache webserver package is included in the Debian repository. Run the following command to install it:
sudo apt install apache2 apache2-utils
Check apache build and version:
apache2 -v
Once Apache is installed, check the service status using the following command below:
sudo systemctl status apache2
You can also check the Apache installation by browsing the URL http://your-ip-address
. You should see the Apache test page on the following screen:
Step 3. Installing MariaDB database server.
To get started with MariaDB installation, follow the below steps:
sudo apt install mariadb-server mariadb-client
Once the installation is complete, check whether the database server is running by issuing the command:
sudo systemctl status mariadb
By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation
script. you should read and below each step carefully which will set a root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MariaDB:
mysql_secure_installation
Configure it like this:
- 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
To log into MariaDB, use the following command (note that it’s the same command you would use to log into a MySQL database):
mysql -u root -p
Step 4. Installing PHP.
By default, the version of PHP is available in the Debian 11 Bullseye. You can install PHP with other commonly used extensions with the following command:
sudo apt install php libapache2-mod-php php-cli php-fpm php-json php-pdo php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath
Next, enable the Apache module if not already enabled then restart the webserver:
a2enmod php7.4
Once PHP is installed, verify the PHP version using the following command:
php -v
Step 5. Configure Firewall.
Allow Apache HTTP server via the firewall:
sudo ufw status sudo ufw allow 80/tcp sudo ufw allow 443/tcp sudo ufw reload sudo ufw enable
Step 6. Test LAMP Stack.
To test the LAMP stack, we will place a PHP file on the default document root of the Apache server:
echo "<?php phpinfo(); ?>" > /var/www/html/info.php
Save the file and exit. Then open your browser in your system and type http://your-ip-address/info.php
Congratulations! You have successfully installed LAMP. Thanks for using this tutorial for installing the latest version of LAMP Stack on Debian 11 Bullseye. For additional help or useful information, we recommend you check the official LAMP website.