VPS Hosting

VPS Hosting

Buy Now

Initial Server Setup for Debian 12

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.

Install Apache, PHP, MariaDB and Certbot

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:

  • Apache: Web server software
  • MariaDB: MySQL-compatible database engine
  • PHP-FPM: Fast PHP handler
  • Certbot: For managing SSL certificates

Turn on PHP-FPM to improve performance and resource handling.

sudo a2enconf php8.2-fpm

Configure Apache on Debian 12

Enable the default SSL site:

sudo a2ensite default-ssl

Edit the Apache config to allow .htaccess overrides:

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>

Restart Apache to apply changes:

sudo systemctl restart apache2

It will look like the image below.

Default Apache Page in Debian 12
Apache Active on Debian 12

Run MySQL secure installation

To get MariaDB set up as your database you’ll need to run the mysql_secure_installation command.

  1. First off from your terminal window enter the command as shown above.
  2. Follow on with the installation prompts including entering a root password and choosing to keep or remove certain defaults i.e. anonymous users and remote logins.
  3. With that completed you should be able to login with mysql -u root and your password.

Activate Certbot

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