
Deploying a web server stack on Debian 11 is a fundamental step for hosting websites and web applications. The LAMP stack (Linux, Apache, MariaDB/MySQL, PHP) is a popular and robust choice, providing everything needed for dynamic web content. Here’s a comprehensive guide to getting it set up efficiently and correctly.
First, always begin by ensuring your system’s package list is up-to-date. Open your terminal and run:
sudo apt update
And it’s good practice to upgrade existing packages:
sudo apt upgrade
Next, install the Apache web server. Apache is a widely used, powerful, and flexible HTTP server.
sudo apt install apache2
Once installed, Apache should start automatically. You can verify its status:
sudo systemctl status apache2
To allow web traffic through your firewall (like UFW), permit the necessary profiles:
sudo ufw allow 'Apache Full'
or sudo ufw allow 'Apache'
depending on whether you need both HTTP and HTTPS or just HTTP initially.
Now, install the database server. MariaDB is the default MySQL variant on Debian and is highly recommended.
sudo apt install mariadb-server
After installation, secure your MariaDB instance. This is a critical security step. Run the security script:
sudo mysql_secure_installation
Follow the prompts. You’ll be asked to set a root password, remove anonymous users, disallow remote root login, and remove the test database. Say ‘Y’ for these options to enhance security.
Finally, install PHP, the scripting language that connects Apache with the database. You’ll also need the module that allows Apache to process PHP files and the connector for MariaDB/MySQL.
sudo apt install php libapache2-mod-php php-mysql
You might need other PHP modules depending on your application’s requirements (e.g., php-cli
, php-gd
, php-curl
). Install them as needed, for example:
sudo apt install php-cli php-gd php-curl
Apache should automatically enable the PHP module. If not, you might need:
sudo a2enmod php
(though libapache2-mod-php
usually handles this).
After installing PHP modules or enabling the module, restart Apache to apply the changes:
sudo systemctl restart apache2
To test your PHP installation, create a simple test file in the default web root directory, which is /var/www/html/
on Debian:
sudo nano /var/www/html/info.php
Paste the following code into the file:
<?php phpinfo(); ?>
Save and close the file. Now, open your web browser and navigate to your server’s IP address followed by /info.php
(e.g., http://your_server_ip/info.php
). You should see a page displaying detailed information about your PHP installation.
With these steps completed, your LAMP stack is successfully installed on Debian 11, providing a powerful platform for your web development projects. Remember to remove the info.php
file after testing for security reasons.
Source: https://kifarunix.com/install-lamp-stack-on-debian-11/