Apply for Free VPS

Install Apache on Ubuntu

Updated 27 Nov 2026 ubuntu apache

Install Apache, add a virtual host and listen on the right port.

Install

sudo apt update && sudo apt install -y apache2
systemctl status apache2

Shared IPv4: listen on a forwarded port

Add to /etc/apache2/ports.conf (replace 20002 with your server port):

Listen 20002

A virtual host

/etc/apache2/sites-available/site.conf:

<VirtualHost *:20002>
    ServerName example.com
    DocumentRoot /var/www/site
    <Directory /var/www/site>
        Require all granted
        AllowOverride None
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/site-error.log
    CustomLog ${APACHE_LOG_DIR}/site-access.log combined
</VirtualHost>

Use *:80 on a dedicated address.

Enable

sudo mkdir -p /var/www/site
echo 'Hello' | sudo tee /var/www/site/index.html
sudo a2ensite site
sudo apache2ctl configtest
sudo systemctl reload apache2
sudo ufw allow 20002/tcp

Hide version details

Set ServerTokens Prod and ServerSignature Off in /etc/apache2/conf-available/security.conf, then reload.

Was this helpful?

Report outdated or incorrect information