CloudLinux.ro
Web servers

How to install Apache on Ubuntu

Updated 7/20/2026

Apache is a mature, compatible web server, favored for PHP apps that use .htaccess. Here is how to install it.

1. Install

apt-get update -y
apt-get install -y apache2
systemctl enable --now apache2

2. Create a virtual host

Create /etc/apache2/sites-available/mysite.conf:

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /var/www/mysite
</VirtualHost>
a2ensite mysite
a2dissite 000-default
systemctl reload apache2

3. Enable URL rewriting

For .htaccess and friendly URLs:

a2enmod rewrite
systemctl restart apache2

Nginx or Apache?

Nginx is faster for static files and high traffic; Apache is simpler with PHP apps that rely on .htaccess. For new sites, see also How to install Nginx.

Put this guide into practice on your own VPS

EU cloud servers, billed hourly, ready in minutes, with one-click installs for dozens of apps.

See pricing

Related tutorials