In this article, we will have explained the necessary steps to install LAMP Stack on Debian 11. Before continuing with this tutorial, make sure you are logged in as a user with sudo
privileges. All the commands in this tutorial should be run as a non-root user.
LAMP stack is one of the most popular and leading development stacks among developers. This term is actually an acronym that represents the Linux operating system, with the Apache webserver. The site data is stored in a MariaDB database, and dynamic content is processed by PHP.
Install LAMP Stack on Debian 11
Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.
sudo apt update sudo apt upgrade sudo apt install software-properties-common dirmngr ca-certificates apt-transport-https nano wget curl
Step 2. Install Apache Web Server.
Apache webserver package is included in the Debian 11 default repository. You can install it by running the below command:
sudo apt install apache2 apache2-utils
Check the version of Apache:
apache2 -v
You can also start, stop, restart and get the status of the Apache webserver using the following systemctl
commands:
sudo systemctl start apache2 sudo systemctl enable apache2
Finally, check the Apache installation by browsing the URL http://your-server-ip
.
Step 3. Install MariaDB database server.
The tutorial will recommend installing MariaDB constantly over MySQL due to performance more than anything else. Install the MariaDB server using the following command:
sudo apt install mariadb-server mariadb-client
By default, you will find MariaDB status to be activated. If not, start MariaDB, use the following command:
sudo systemctl start mariadb sudo systemctl enable mariadb
After MariaDB is installed, it is recommended to run the following security script that will remove some insecure default settings and disable access to your database system:
sudo mysql_secure_installation
To create a database and grant your users permission to use databases, run:
[email protected]:~# mysql -u root -p
MariaDB [(none)]> CREATE DATABASE linuxtips_database; MariaDB [(none)]> GRANT ALL ON linuxtips_database.* TO 'linuxtips_user'@'localhost' IDENTIFIED BY 'strong-password' WITH GRANT OPTION; MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> exit
Step 4. Install PHP.
The last part of the tutorial will be to install PHP, which is the backend that communicates between Apache and MariaDB. Follow the below steps to install PHP on the server:
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
Then, enable the Apache module if not already enabled then restart the Web Server:
a2enmod php7.4
Once PHP is installed, verify the PHP version using the following command:
php -v
Step 5. Configure Firewall.
To enable HTTP and HTTPS connection through the firewall, follow the commands:
sudo ufw allow 80/tcp sudo ufw allow 443/tcp
Step 6. Create PHP Test Info Page.
First, create a sample PHP file in the document root folder:
sudo nano /var/www/html/info.php
Paste the following file:
<?php phpinfo(); ?>
Save the file and browse the URL shown:
http://my-server-ip/info.php
That’s all you need to do to install LAMP on Debian (Bullseye). I hope you find this quick tip helpful. For further reading of LAMP Stack on Debian’s system, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.