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
Follow the prompts. Certbot handles the rest.
Want more control over SSL setup? Read how to install SSL certificates manually with certbot.
Lock down your server properly. Configure firewall ports to only allow necessary traffic through.
Create separate user accounts for different tasks. Switch users in Linux when you need to run commands as someone other than root.
Server setup is just the start. Regular maintenance, monitoring, and updates keep things running smoothly.
Check out our guide to manage your VPS for ongoing administration tips.
Get scalable resources with our VPS hosting with root access and optional software.
Get VPS HostingPerfect for websites and small businesses unlimited bandwidth with cPanel hosting.
Get cPanel Hosting