sudo apt update && sudo apt install apache2. On AlmaLinux or Rocky Linux the package is called httpd: run sudo dnf install httpd and sudo systemctl enable --now httpd. Allow port 80 (and 443 for HTTPS) in your firewall, then open your server’s IP in a browser to see the default test page.
Before you start
- Connect with SSH as a user with
sudorights. If you areroot, leave outsudo. - Make sure nothing else uses port 80, such as Nginx. Only one web server can listen on a port.
apache2; AlmaLinux and Rocky call them httpd.
How to install Apache
- Ubuntu / Debian
- AlmaLinux / Rocky
1
Install the package
2
Check the service
active (running).How to open the firewall for Apache
- Ubuntu / Debian (ufw)
- AlmaLinux / Rocky (firewalld)
sudo ufw allow 'Apache Full' opens both ports.Where are the Apache files?
How to add a virtual host for your domain
A virtual host lets one Apache server answer for a specific domain. This example usesexample.com.
1
Create the web root
2
Create the config file
On Ubuntu / Debian create On AlmaLinux / Rocky,
/etc/apache2/sites-available/example.com.conf. On AlmaLinux / Rocky create /etc/httpd/conf.d/example.com.conf.${APACHE_LOG_DIR} is not defined. Use /var/log/httpd/example.com-error.log and /var/log/httpd/example.com-access.log instead.3
Enable the site (Ubuntu / Debian only)
a2enmod rewrite turns on mod_rewrite, which most PHP apps need for clean URLs.4
Test and reload
On AlmaLinux / Rocky with SELinux enforcing, files under
/var/www/ work as they are. If you put a site anywhere else, give it the httpd_sys_content_t label with semanage fcontext and restorecon. See SELinux on AlmaLinux and Rocky.How to check it worked
configtest should print:
AH00558: Could not reliably determine the server's fully qualified domain name is harmless. To silence it, add ServerName example.com to the main config.
List the sites Apache loaded (Ubuntu / Debian):
*:80 example.com (/etc/apache2/sites-enabled/example.com.conf:1). Once your domain’s DNS points to the server (point a domain), open http://example.com.
Frequently asked questions
What is the difference between apache2 and httpd?
They are the same Apache HTTP Server. Debian-based systems name itapache2; Red Hat-based systems name it httpd. Paths and helper commands differ, as shown in the table above.
Why does Apache fail with “Address already in use”?
Another web server, often Nginx, is using port 80. Check withsudo ss -tlnp | grep ':80' and stop one of them.
How do I run PHP with Apache?
Install PHP and the Apache module, or PHP-FPM. See install a LAMP stack.Does .htaccess work?
Yes, when the<Directory> block has AllowOverride All, as in the example. Without it, Apache ignores .htaccess files.
Related guides
VPS and dedicated server guides
Every server guide in one place.
Install a LAMP stack
Apache, MariaDB and PHP.
Free SSL with Certbot
Add HTTPS to Apache.
Install Nginx
The other popular web server.
Website not loading
Step-by-step checks.
Checked against the official Ubuntu Server documentation and Red Hat Enterprise Linux 9 Apache guide on 4 November 2026; install, virtual host and
configtest commands tested on Ubuntu 24.04 LTS (Apache 2.4.58). Commands can differ on other distributions or releases.Need Extra Help?
If you encounter any issues, our support team is ready to assist:- Live Chat: Quick assistance via our website.
- Support Ticket: Open a Ticket
- Discord: Join our Community
- Email: support@freakhosting.com
Last Updated: November 2026