Setting up a web server on Debian 12 allows you to host dynamic PHP applications such as WordPress, Joomla, Drupal, and OpenCart as part of a LAMP stack. In this guide learn how to install Apache, MariaDB, PHP, and SSL using simple commands giving you a secure and fully functional web server ready to deploy PHP-based applications in just a few steps.
Update your package list and install all required components in one go using the following command ( you can also add the -y flag to skip confirmation).
sudo apt update
sudo apt install apache2 mariadb-server mariadb-client php php-fpm php-intl php-mbstring php-gd php-xml php-curl php-mysql php-zip php-xmlrpc
These packages include:
Turn on PHP-FPM to improve performance and resource handling.
sudo a2enconf php8.2-fpm
sudo a2ensite default-ssl
Open both configuration files:
sudo nano /etc/apache2/sites-enabled/000-default.conf
sudo nano /etc/apache2/sites-enabled/default-ssl.conf
In the file navigate to the <VirtualHost> block and, insert:
<Directory "/var/www/html">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
sudo systemctl restart apache2
It will look like the image below.
To get MariaDB set up as your database you’ll need to run the mysql_secure_installation command.
Finally we can activate certbot with the following command, this will automatically configure using your virtual hosts and issue a free SSL certificate from Lets Encrypt.
sudo certbot --apache