A fresh Debian 12 VPS needs Apache, MariaDB and PHP installed and configured before it can host PHP applications such as WordPress, Joomla or OpenCart. This guide takes you through each component of a LAMP stack on Debian 12, from package installation through to SSL certificate provisioning with Certbot.
By the end, your server will serve web pages over HTTPS and accept database connections from PHP applications.
Debian’s apt package manager can install all required components in a single pass. Updating the package list first prevents version conflicts between newly installed packages and existing system libraries.
sudo apt update
-y flag to skip the confirmation prompt.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 certbot python3-certbot-apache
sudo a2enconf php8.2-fpm
All packages are now installed. Next, configure Apache to serve your site correctly.
Apache needs two changes to work correctly with PHP applications: the default SSL virtual host must be activated, and .htaccess overrides must be permitted so that applications like WordPress can control their own URL routing.
sudo a2ensite default-ssl
sudo nano /etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80> tags. AllowOverride All permits .htaccess files to function; without this, permalink structures and application routing break.<Directory "/var/www/html">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
/etc/apache2/sites-enabled/default-ssl.conf and add the same Directory block inside the <VirtualHost _default_:443> tags.sudo systemctl restart apache2
Open your server’s IP address in a browser. You should see the default Apache page, confirming the web server is running.

MariaDB ships with insecure defaults, including anonymous user accounts and the ability to connect as root without a password. The mysql_secure_installation script removes these defaults and sets a root password in one interactive pass.
sudo mysql_secure_installation
exit to return to your shell when done.mysql -u root -p
MariaDB is now secured. PHP applications can connect to it using credentials you create per-database.
Certbot connects to Let’s Encrypt, verifies that your domain points to this server and installs a free SSL certificate automatically. It also updates your Apache configuration to redirect HTTP traffic to HTTPS.
sudo certbot --apache
Once complete, visit your domain over HTTPS to confirm the padlock appears. Certbot configures automatic renewal by default, so your certificate stays valid without manual intervention. For more detail on the process, see our guide on installing an SSL certificate with Certbot.
A syntax error in a virtual host file prevents Apache from starting. Test your configuration before restarting to catch errors early.
sudo apache2ctl configtest to check for syntax errors. The output shows the file and line number of any problem.sudo journalctl -u apache2 --no-pager -n 50 for the most recent entries.Certbot verifies domain ownership by making an HTTP request to your server. If that request cannot reach your server, the certificate is not issued.
If your browser downloads PHP files rather than executing them, Apache is not passing requests to PHP-FPM correctly.
sudo a2enconf php8.2-fpm again, then restart Apache.php8.2-fpm service is running with sudo systemctl status php8.2-fpm.sudo a2enmod proxy_fcgi, then restart Apache.Your Debian 12 server now runs a complete LAMP stack. Apache serves web pages, MariaDB stores application data, PHP processes dynamic content and Certbot has issued an SSL certificate so your site loads over HTTPS.
From here you can install a CMS or PHP application into /var/www/html. See our guides on switching users in Linux and managing your VPS for day-to-day administration tasks. For a parallel walkthrough on an RPM-based distribution, see our guide on installing a LAMP stack on AlmaLinux.
Our VPS hosting gives you full root access to run custom LAMP configurations on Debian, AlmaLinux and other distributions.
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