How to install Apache on Ubuntu
Updated 10/23/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 10/23/2026Web serversHow to deploy a Node.js app to production
Run a Node.js app reliably in production with PM2 and Nginx, with auto-restart and HTTPS.
Updated 10/23/2026Web serversHow to host multiple sites on one server
Use Nginx server blocks to run multiple domains on the same VPS, each with its own site.
Updated 10/23/2026