How to install Apache on Ubuntu
Updated 10/16/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 pricingRelated tutorials
Web servers
How to deploy a Laravel app to production
Deploy Laravel properly on a VPS: Nginx, PHP-FPM, permissions, optimizations and the queue worker.
Updated 10/16/2026Web serversHow to optimize Nginx performance: gzip, cache and HTTP/2
Make your site faster with gzip compression, static file caching and HTTP/2, a few lines of config.
Updated 10/16/2026Web serversHow to force HTTPS and redirect HTTP
After installing SSL, make sure every visitor uses HTTPS, with a permanent 301 redirect from HTTP.
Updated 10/16/2026