Installing and Basic Configuration of Apache on Debian 12
How to install Apache on Debian 12 and perform its basic configuration for a stable web server setup
🔧 1. Installing Apache
Step 1: Update the system
sudo apt update && sudo apt upgrade -y
Step 2: Install Apache
sudo apt install apache2 -y
🚀 2. Starting and Checking Apache
Step 1: Check Apache status
sudo systemctl status apache2
Expected output — a line containing active (running).
Step 2: Verify in browser
Open your browser and enter your server’s IP address:
http://your_IP
You should see the Apache2 Debian Default Page.
⚙️ 3. Basic Settings
Step 1: Enable Apache to start on boot
sudo systemctl enable apache2
Step 2: Open port 80 in the firewall (UFW)
sudo ufw allow 'Apache' sudo ufw reload
🌐 4. Creating Your First Site (Virtual Host)
Step 1: Create a directory for the site
sudo mkdir -p /var/www/mysite.com/public_html
Step 2: Set ownership
sudo chown -R $USER:$USER /var/www/mysite.com/public_html
Step 3: Create a starter page
nano /var/www/mysite.com/public_html/index.html
Insert:
<!DOCTYPE html> <html> <head> <title>Welcome to MySite!</title> </head> <body> <h1>It works!</h1> </body> </html>
📁 5. Configuring a Virtual Host
Step 1: Create a configuration file
sudo nano /etc/apache2/sites-available/mysite.com.conf
Insert:
<VirtualHost *:80> ServerAdmin webmaster@mysite.com ServerName mysite.com ServerAlias www.mysite.com DocumentRoot /var/www/mysite.com/public_html ErrorLog ${APACHE_LOG_DIR}/mysite.com_error.log CustomLog ${APACHE_LOG_DIR}/mysite.com_access.log combined </VirtualHost>
Step 2: Enable the site
sudo a2ensite mysite.com.conf
Step 3: Disable the default site (optional)
sudo a2dissite 000-default.conf
Step 4: Reload Apache
sudo systemctl reload apache2
🧪 6. Testing
Step 1: Add an entry to /etc/hosts (local testing)
sudo nano /etc/hosts
Add:
127.0.0.1 mysite.com
Step 2: In the browser
Enter:
http://mysite.com
You should see your It works! page.
📦 7. Optional: Installing PHP
Install PHP:
sudo apt install php libapache2-mod-php -y
Test PHP:
nano /var/www/mysite.com/public_html/info.php
Insert:
<?php phpinfo(); ?>
In the browser:
http://mysite.com/info.php
✅ Done!
File Structure:
/var/www/mysite.com/public_html/ ← your site /etc/apache2/sites-available/ ← virtual host configurations /etc/apache2/sites-enabled/ ← enabled sites (symlinks)
🛡 Security & Final Steps
- Remove the PHP test file after testing:
rm /var/www/mysite.com/public_html/info.php
- Add HTTPS with Let’s Encrypt (instructions can be provided if needed).
Order a dedicated server here.