Updated: 11 October 2026 · Applies to: Apache 2.4.66 on Ubuntu 26.04 LTS and Apache 2.4.58 on Ubuntu 24.04 LTS; httpd 2.4.63 on AlmaLinux 10 (2.4.62 on AlmaLinux 9, same steps on Rocky Linux and RHEL); Certbot 4.0.0 and 2.9.0 (Ubuntu), 4.2.0 from EPEL (AlmaLinux 10)
Apache HTTP Server is in the standard repositories of every major Linux distribution, so installing it is one command: sudo apt install apache2 on Ubuntu and Debian, or sudo dnf install httpd on AlmaLinux, Rocky Linux and RHEL. To host a website you then open ports 80 and 443, put your files in a folder, add a virtual host for your domain, point the domain to the server and add a free Let’s Encrypt certificate. The steps below do this on Ubuntu, with the AlmaLinux differences in each step. Run them as a user with sudo rights.
Apache or another Linux web server? Apache reads .htaccess files, which many PHP applications such as WordPress use; Nginx does not. If you prefer Nginx, see Nginx configuration explained.
1. Install Apache
sudo apt update sudo apt install apache2 apache2 -v
On Ubuntu 26.04 the first line was Server version: Apache/2.4.66 (Ubuntu); on 24.04 it was Apache/2.4.58 (Ubuntu).
AlmaLinux, Rocky Linux, RHEL: the package and the service are called httpd, and the service is not enabled after installing, so start it yourself:
sudo dnf install httpd sudo systemctl enable --now httpd httpd -v
AlmaLinux 10.2 printed Server version: Apache/2.4.63 (AlmaLinux).
2. Start the web server and check it
systemctl status apache2
Look for Active: active (running) and enabled: on Ubuntu the package enables Apache at boot. If it is stopped, run sudo systemctl start apache2 (httpd on AlmaLinux). Open http://your-server-ip/ in a browser: Ubuntu shows Apache2 Ubuntu Default Page: It works, AlmaLinux shows Test Page for the HTTP Server on AlmaLinux. Stop, restart and reload commands are in how to start, stop or restart Apache.
3. Open the firewall
If UFW is active on Ubuntu, allow HTTP and HTTPS with Apache’s profile (Apache Full is TCP 80 and 443):
sudo ufw allow "Apache Full"
New to UFW? Read how to set up the UFW firewall on Ubuntu first, so you do not block SSH. On AlmaLinux with firewalld:
sudo firewall-cmd --permanent --add-service=http --add-service=https sudo firewall-cmd --reload
4. Create a folder for your site
sudo mkdir -p /var/www/example.com/public_html sudo chown -R $USER:www-data /var/www/example.com echo "<h1>example.com works</h1>" > /var/www/example.com/public_html/index.html
Replace example.com with your domain everywhere. Your user owns the files and Apache (www-data) can read them. On AlmaLinux the Apache user and group are apache, so use $USER:apache. Keep the site under /var/www there: SELinux labels that path httpd_sys_content_t, which Apache may read. A folder elsewhere needs the same label (semanage fcontext and restorecon), or SELinux stops Apache from reading it.
5. Create the virtual host
On Ubuntu, create /etc/apache2/sites-available/example.com.conf:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public_html
<Directory /var/www/example.com/public_html>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined
</VirtualHost>
AllowOverride All lets .htaccess files work. On AlmaLinux, save the same block as /etc/httpd/conf.d/example.com.conf (every .conf file there is loaded) and write the log paths as /var/log/httpd/example.com-error.log and /var/log/httpd/example.com-access.log. How the configuration files fit together: basic Apache configuration on Linux.
6. Enable the site and reload
sudo a2ensite example.com.conf sudo a2dissite 000-default.conf sudo a2enmod rewrite sudo apache2ctl configtest sudo systemctl restart apache2
Each a2 command tells you what to do next, for example Enabling module rewrite. followed by service apache2 restart. configtest must print Syntax OK. A new module needs a restart; for site changes alone, sudo systemctl reload apache2 is enough and lets requests in progress finish (it runs apachectl graceful).
On AlmaLinux there are no a2 commands: mod_rewrite is already loaded, so run sudo apachectl configtest and sudo systemctl reload httpd.
Both systems may show this warning (on AlmaLinux it starts with httpd:; the address is replaced here):
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 192.0.2.10. Set the 'ServerName' directive globally to suppress this message
It is harmless. On Ubuntu, remove it with:
echo "ServerName localhost" | sudo tee /etc/apache2/conf-available/servername.conf sudo a2enconf servername sudo systemctl reload apache2
On AlmaLinux, remove the # in front of the #ServerName www.example.com:80 line in /etc/httpd/conf/httpd.conf and set your server’s name.
7. Test the virtual host
Before DNS points to the server, test with a Host header and list the virtual hosts Apache loaded (httpd -S on AlmaLinux):
curl -H "Host: www.example.com" http://localhost/ sudo apache2ctl -S
The curl command should return your example.com works page. In our test, apache2ctl -S showed:
VirtualHost configuration: *:80 example.com (/etc/apache2/sites-enabled/example.com.conf:1)
According to the Apache documentation, a request whose host name matches no ServerName or ServerAlias goes to the first listed virtual host. With the default site disabled, that is your site, also for requests to the bare IP address.
8. Upload your website and point the domain
- Copy your files into the document root, for example from your computer with rsync over SSH:
rsync -av ./site/ user@SERVER-IP:/var/www/example.com/public_html/
An SFTP program works too. More options: rsync command examples. - At your DNS provider, create an A record for
example.comand forwwwwith the server’s IP address. - Once DNS has updated, open
http://example.com/.
9. Add HTTPS with Let’s Encrypt
With DNS pointing to the server, on Ubuntu:
sudo apt install certbot python3-certbot-apache sudo certbot --apache -d example.com -d www.example.com
On AlmaLinux, Certbot comes from EPEL and needs mod_ssl:
sudo dnf install epel-release sudo dnf install certbot python3-certbot-apache mod_ssl sudo certbot --apache -d example.com -d www.example.com sudo systemctl enable --now certbot-renew.timer
According to the Certbot documentation, it gets the certificate and edits your Apache configuration to serve it over HTTPS. Renewal is automatic: Ubuntu’s package installs certbot.timer (“Run certbot twice daily”), the EPEL package certbot-renew.timer. Our test servers had no public DNS, so we checked the packages, the Apache plugin (on Ubuntu 26.04, certbot plugins listed apache) and the timers, but did not issue a real certificate.
Useful next steps
- PHP:
sudo apt install php libapache2-mod-phpinstalls PHP 8.5 on Ubuntu 26.04 and PHP 8.3 on 24.04; AlmaLinux 10 offers PHP 8.3 (sudo dnf install php). - Logs:
/var/log/apache2/on Ubuntu,/var/log/httpd/on AlmaLinux. A blank page or error 500 is explained there: Internal Server Error 500. - Rewrites and redirects: how to use mod_rewrite. Faster HTTPS: enable HTTP/2 in Apache.
Official documentation: Apache HTTP Server: virtual host documentation.