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 pricingRelated tutorials
Web servers
How 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 7/20/2026Web serversHow to install phpMyAdmin to manage MySQL from the browser
Manage your MySQL databases from a web interface with phpMyAdmin, installed and secured correctly.
Updated 7/20/2026Web serversHow to host a static site or a React/Vue app
Publish a static site or a React/Vue build on Nginx, with correct routing for single-page apps.
Updated 7/20/2026