Virtual Host Settings on CentOS 7
In this guide, you will learn how to install the Apache (httpd) web server on CentOS 7.
You will also securely manage multiple domain names on the same server with Virtual Host and SELinux permissions.
What Will You Learn in This Guide?
- Installing Apache on CentOS 7
- Opening HTTP/HTTPS access with Firewalld
- Apache service management
- Virtual Host configuration
- Setting SELinux log permissions correctly
Prerequisites
- A GenixNode server with CentOS 7 installed
- User with authority
sudo - The domain name must be directed to the server IP
firewalldmust be active
1. Apache Installation and Firewall Settings
Apache is available as a httpd package in the CentOS repositories.
sudo yum update httpd
This command updates Apache package information.
sudo yum install httpd
This command installs the Apache web server.
- Firewalld Settings
sudo firewall-cmd --permanent --add-service=http
- Opens HTTP traffic (80).
sudo firewall-cmd --permanent --add-service=https
- Opens HTTPS traffic (443).
sudo firewall-cmd --reload
- Applies firewall rules.
2. Starting and Controlling Apache Service
sudo systemctl start httpd
Starts the Apache service.
sudo systemctl status httpd
Verifies that the service is running.
Testing from the Browser
Visit the server IP address:
http://SUNUCU_IP
3. Managing Apache Service
sudo systemctl stop httpd
Stops the service.
sudo systemctl restart httpd
Restarts the service.
sudo systemctl reload httpd
Refreshes the configuration without breaking connections.
sudo systemctl enable httpd
It starts automatically at server startup.
4. Creating a Directory Structure for Virtual Host
Example domain name: rabisuproje.cloud
sudo mkdir -p /var/www/rabisuproje.cloud/html
sudo mkdir -p /var/www/rabisuproje.cloud/log
Creates site root and log directories.
sudo chown -R $USER:$USER /var/www/rabisuproje.cloud/html
sudo chmod -R 755 /var/www
Sets the correct ownership and permissions.
Creating Test File
sudo vi /var/www/rabisuproje.cloud/html/index.html
<html>
<head>
<title>rabisuproje.cloud</title>
</head>
<body>
<h1>Başarılı! Virtual Host çalışıyor.</h1>
</body>
</html>
5. Virtual Host Configuration
Create Apache Virtual Host directories:
sudo mkdir /etc/httpd/sites-available /etc/httpd/sites-enabled
Open Apache main configuration:
sudo vi /etc/httpd/conf/httpd.conf
Add the following line to the end of the file:
IncludeOptional sites-enabled/*.conf
Create the Virtual Host file:
sudo vi /etc/httpd/sites-available/rabisuproje.cloud.conf
<VirtualHost *:80>
ServerName rabisuproje.cloud
ServerAlias www.rabisuproje.cloud
DocumentRoot /var/www/rabisuproje.cloud/html
ErrorLog /var/www/rabisuproje.cloud/log/error.log
CustomLog /var/www/rabisuproje.cloud/log/access.log combined
</VirtualHost>
Enable Virtual Host:
sudo ln -s /etc/httpd/sites-available/rabisuproje.cloud.conf /etc/httpd/sites-enabled/
6. Setting SELinux Permissions (Recommended)
SELinux can prevent Apache from writing to private directories. Let's define the correct context for the log directory.
sudo semanage fcontext -a -t httpd_log_t "/var/www/rabisuproje.cloud/log(/.*)?"
Allows Apache to write logs.
sudo restorecon -R -v /var/www/rabisuproje.cloud/log
It implements the SELinux context.
7. Testing the Configuration
sudo systemctl restart httpd
Check log permissions:
ls -lZ /var/www/rabisuproje.cloud/log
If log files are created, the configuration is successful.
Test from browser:
http://rabisuproje.cloud
Frequently Asked Questions (FAQ)
Why is Apache called httpd?
Historically, the abbreviation HTTP Daemon is used.
Should SELinux be turned off?
No. For security, it must remain open and the correct context must be given.
What does Virtual Host provide?
It allows hosting multiple websites on a single server.
Where are Apache logs kept?
Usually:
/var/www/siteadi/log/
Result
It is now built on Apache CentOS 7, running securely and with multi-site support.
Thanks to this structure, you can easily host multiple websites on the same server.
With the GenixNode infrastructure, you can publish your projects quickly and safely.

