This guide explains how to:
- Bind Apache to a specific IP address
- Run sites on multiple ports
- Host multiple websites using Virtual Hosts
- Use firewall and permission commands
Use netstat to see which IPs and ports Apache is using:
netstat -nltup | grep httpdThis confirms if Apache is running and which ports it's listening on.
Edit the main Apache config file:
vim /etc/httpd/conf/httpd.confMake the following changes:
# Listen 80 ← Comment out the default listen
Listen 192.168.29.24:80 ← Add this to bind only to a specific IPThis forces Apache to respond only on IP 192.168.29.24.
Save and exit:
:wq!
Apply the changes by restarting Apache:
systemctl restart httpdThen verify:
netstat -nltup | grep httpd🧪 Browser test:
http://192.168.29.24
To run Apache on additional ports:
vim /etc/httpd/conf/httpd.confAdd:
Listen 80
Listen 81
Listen 82This allows Apache to accept traffic on ports 80, 81, and 82.
Save and exit.
To allow access to these ports:
firewall-cmd --permanent --add-port=81/tcp
firewall-cmd --permanent --add-port=82/tcp
firewall-cmd --reload🧪 Test in browser:
http://192.168.29.24:81
http://192.168.29.24:82
Always check syntax after changes:
httpd -tIf output is Syntax OK, continue.
Go to Apache's web root and make separate folders for each website:
cd /var/www/html
mkdir site1 site2 site3 site4Set correct ownership:
chown -Rv apache:apache site1 site2 site3 site4
ls -lhFrom your home directory:
cd ~
# Download templates
wget <template-link-1>
wget <template-link-2>
wget <template-link-3>
wget <template-link-4>
# Unzip them
unzip template1.zip
unzip template2.zip
unzip template3.zip
unzip template4.zip
# Copy to site folders
cp -vr template1/* /var/www/html/site1/
cp -vr template2/* /var/www/html/site2/
cp -vr template3/* /var/www/html/site3/
cp -vr template4/* /var/www/html/site4/Replace
<template-link-x>with actual links.
To ensure Apache can access the files:
cd /var/www/html
chown -Rv apache:apache site*Edit Apache config:
vim /etc/httpd/conf/httpd.confAt the bottom of the file, remove any extra Listen ports if added earlier.
Then add these virtual host blocks:
<VirtualHost 192.168.29.24:80>
DocumentRoot /var/www/html/site1
DirectoryIndex index.html
</VirtualHost>
<VirtualHost 192.168.29.25:80>
DocumentRoot /var/www/html/site2
DirectoryIndex index.html
</VirtualHost>
<VirtualHost 192.168.29.26:80>
DocumentRoot /var/www/html/site3
DirectoryIndex index.html
</VirtualHost>
<VirtualHost 192.168.29.27:80>
DocumentRoot /var/www/html/site4
DirectoryIndex index.html
</VirtualHost>💾 Save and exit:
:wq!
httpd -t # Check for syntax errors
systemctl restart httpdEnsure these IPs are configured on your system:
ip addr add 192.168.29.25/24 dev eth0
ip addr add 192.168.29.26/24 dev eth0
ip addr add 192.168.29.27/24 dev eth0Open in browser:
http://192.168.29.24
http://192.168.29.25
http://192.168.29.26
http://192.168.29.27
Each IP should open a different site.
| Step | Description |
|---|---|
Listen IP:Port |
Binds Apache to specific IP and port |
VirtualHost |
Allows multiple websites on one server |
firewall-cmd |
Opens custom ports in the system firewall |
chown |
Assigns correct ownership to Apache |
httpd -t |
Tests Apache configuration for errors |