Apache: install and virtual hosts
In this article you'll install the Apache web server on your mHost VPS, set up a virtual host (VirtualHost) for a site, check the configuration, and open the necessary firewall ports — ending up with a working Apache that serves your site over HTTP.
What you'll need
- SSH access to the server as
rootor as a user withsudo. - An mHost VPS on one of the supported OSes: Ubuntu 22.04/24.04, Debian 11/12, AlmaLinux/Rocky Linux 8/9.
- (optional) a domain name whose A record points at the server's IP — for testing, the IP alone works fine.
Step 1. Install Apache
Debian / Ubuntu
The package is called apache2:
sudo apt update
sudo apt install apache2AlmaLinux / Rocky Linux
The package is called httpd:
sudo dnf install httpdStep 2. Enable and start Apache
Debian / Ubuntu
sudo systemctl enable --now apache2
sudo systemctl status apache2AlmaLinux / Rocky Linux
sudo systemctl enable --now httpd
sudo systemctl status httpdThe --now flag both enables autostart on boot and starts the service right away. The status output should show active (running). Open http://<IP>/ (your server's IP address) in a browser — you should see Apache's default test page.
Step 3. Create a virtual host (VirtualHost)
A virtual host describes a single site on the server: its own DocumentRoot (file directory), domain name, and logs. Below is an example for the domain example.com — replace it with your own.
Create a directory for the site's files and a test page (the same on every system):
sudo mkdir -p /var/www/example.com/public_html
echo "<h1>It works: example.com</h1>" | sudo tee /var/www/example.com/public_html/index.htmlDebian / Ubuntu
Create the file /etc/apache2/sites-available/example.com.conf:
sudo nano /etc/apache2/sites-available/example.com.confand paste into it:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin admin@example.com
DocumentRoot /var/www/example.com/public_html
<Directory /var/www/example.com/public_html>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined
</VirtualHost>AlmaLinux / Rocky Linux
Create the file /etc/httpd/conf.d/example.com.conf:
sudo nano /etc/httpd/conf.d/example.com.confand paste into it (the log paths differ — there's no APACHE_LOG_DIR variable here):
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin admin@example.com
DocumentRoot /var/www/example.com/public_html
<Directory /var/www/example.com/public_html>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/httpd/example.com-error.log
CustomLog /var/log/httpd/example.com-access.log combined
</VirtualHost>Step 4. Enable the site and modules: a2ensite / a2enmod
Debian / Ubuntu
Debian and Ubuntu keep all sites in sites-available/ and enable them via a symlink in sites-enabled/; you don't need to create the symlink by hand — a2ensite does it (give it the site name together with .conf):
sudo a2ensite example.com.confApache modules are enabled with a similar command, a2enmod — for example, mod_rewrite (often needed together with AllowOverride All for .htaccess rules):
sudo a2enmod rewrite
sudo systemctl restart apache2AlmaLinux / Rocky Linux
There's no separate a2ensite equivalent here: any *.conf file you drop into /etc/httpd/conf.d/ is loaded automatically by Apache at startup — via the IncludeOptional conf.d/*.conf directive in /etc/httpd/conf/httpd.conf. Most standard modules (including mod_rewrite) are already enabled by default on AlmaLinux/Rocky — their LoadModule directives live in /etc/httpd/conf.modules.d/.
Step 5. Test the configuration and reload Apache
Always check the configuration syntax before reloading — the command is the same on every distro:
sudo apachectl configtestA valid configuration replies with Syntax OK; on an error, apachectl points to the file and line.
Debian / Ubuntu
sudo systemctl reload apache2AlmaLinux / Rocky Linux
sudo systemctl reload httpdYou can check that the virtual host answered with the right site even before the domain points at the server, using the Host header:
curl -H 'Host: example.com' http://localhost/The response should be your test page "It works: example.com".
Step 6. Open the firewall ports
Apache listens on port 80 (HTTP) and, once you add TLS, also port 443 (HTTPS); these ports need to be open in the firewall, or the site will stay unreachable from outside.
Debian / Ubuntu
The apache2 package registers the Apache Full ufw profile itself, which opens both ports at once:
sudo ufw app list
sudo ufw allow 'Apache Full'If that profile isn't in the list (on Debian, it isn't always registered), open the ports by number instead:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcpAlmaLinux / Rocky Linux
Ports are opened through firewalld:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reloadWhat's next
Apache is installed, the virtual host is configured, and the ports are open — the site is reachable over HTTP. From here you can:
- add another VirtualHost the same way (Step 3) — for a second domain on the same server;
- set up a TLS certificate so the site loads over HTTPS;
- if you haven't logged in to the panel yet, start with "How to log in to VMmanager 6"; the full list of ready-made recipes (including LAMP) is in "Ready-made VMmanager 6 recipes".