Skip to content

How To Set Up Apache Virtual Hosts on CentOS 6

Netcloud24
Cloud Infrastructure Expert
NetCloud24 Expert Guides Open the dedicated video page

Video transcript: NetCloud24 Expert Guides. Practical knowledge for a reliable cloud. Cloud and VPS expertise, security, performance, and step-by-step tutorials. Learn, deploy, and keep building with NetCloud24.

 

Apache Virtual Hosts allow you to host multiple websites on a single server. This guide will walk you through setting up virtual hosts on CentOS 6.

1. Install Apache

If Apache is not already installed, you can install it using:

sudo yum install httpd

2. Create Your Website Directory

Decide where you want to store your website files. Typically, you might create a directory in /var/www/. For example:

sudo mkdir -p /var/www/example.com/public_html

Set the correct permissions for the directory:

sudo chown -R $USER:$USER /var/www/example.com/public_html

3. Create a Virtual Host File

Create a new virtual host configuration file in the /etc/httpd/conf.d/ directory. For example:

sudo nano /etc/httpd/conf.d/example.com.conf

Add the following configuration to the file, adjusting the values as needed:



    ServerAdmin [email protected]
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public_html
    ErrorLog /var/log/httpd/example.com-error.log
    CustomLog /var/log/httpd/example.com-access.log combined

    

Save and close the file (press Ctrl+X, then Y, and Enter).

4. Restart Apache

Apply the changes by restarting Apache:

sudo service httpd restart

5. Update Your Hosts File (Optional)

If you are testing on a local machine and want to access your site using example.com, update your local hosts file:

Visual overview of How To Set Up Apache Virtual Hosts on CentOS 6
Visual overview: How To Set Up Apache Virtual Hosts on CentOS 6
sudo nano /etc/hosts

Add the following line, replacing 127.0.0.1 with your server’s IP address if needed:

127.0.0.1   example.com

Save and close the file.

6. Verify Your Setup

Open a web browser and navigate to http://example.com. You should see your website’s default page or content.

7. Create Additional Virtual Hosts

Repeat steps 2 through 4 for any additional sites you want to host. Just create new directories and virtual host files as needed.

8. Secure Your Sites

Consider securing your virtual hosts with SSL/TLS. You can use tools like Certbot to obtain and install SSL certificates for your domains.

Windows VPS Deutschland

Windows VPS España

Windows VPS Nederland

Windows VPS Italia

Key topics covered in How To Set Up Apache Virtual Hosts on CentOS 6
Key topics covered in this NetCloud24 guide.

Windows VPS Portugal

VPS Windows Italia

Windows VPS

Windows VPS

Windows VPS Sverige

Windows VPS Norge

Windows VPS

Windows VPS Türkiye

Practical checklist for How To Set Up Apache Virtual Hosts on CentOS 6
Practical checklist for applying the guidance in this article.

Windows RDS (Remote Desktop Services)

Windows VPS

How To Set Up Apache Virtual Hosts on CentOS 6
How To Set Up Apache Virtual Hosts on CentOS 6
Explore more

More on this topic

Netcloud24
Netcloud24
Cloud Infrastructure Expert · NetCloud24

Comments are closed.