How To Set Up Apache Virtual Hosts on CentOS 6

How To Set Up Apache Virtual Hosts on CentOS 6

How To Set Up Apache Virtual Hosts on CentOS 6

In this tutorial, we will be going through the process of setting up virtual hosts on Apache web server in CentOS 6.

Step 1: Install Apache Web Server

The first step is to install the Apache web server on your CentOS 6 machine. To do this, open up the terminal and type the following command:

sudo yum install httpd

Step 2: Create Virtual Host Directory

Next, you need to create a directory where your virtual hosts will be stored. You can create this directory anywhere you like, but for this tutorial, we will create it in the /var/www/html directory.

sudo mkdir /var/www/html/virtualhosts

Step 3: Configure Virtual Hosts

Now we need to create a configuration file for each virtual host we want to create. In this example, we will create two virtual hosts:

  • example1.com
  • example2.com

To create the configuration file for the first virtual host, run the following command:

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

And then add the following configuration:

<VirtualHost *:80> ServerName example1.com DocumentRoot /var/www/html/virtualhosts/example1 ErrorLog /var/log/httpd/example1_error.log CustomLog /var/log/httpd/example1_access.log combined </VirtualHost>

Repeat this step to create a configuration file for the second virtual host:

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

And then add the following configuration:

<VirtualHost *:80> ServerName example2.com DocumentRoot /var/www/html/virtualhosts/example2 ErrorLog /var/log/httpd/example2_error.log CustomLog /var/log/httpd/example2_access.log combined </VirtualHost>

Step 4: Create Virtual Host Directories

Now that we have our virtual host configuration files set up, we need to create the directories where our website files will be stored.

To create the directory for the first virtual host, run the following command:

sudo mkdir /var/www/html/virtualhosts/example1

Repeat this step to create a directory for the second virtual host:

sudo mkdir /var/www/html/virtualhosts/example2

Step 5: Create Website Files

Now that we have our virtual host directories set up, we can create our website files. For this example, we will create an index.html file in each directory:

To create the index.html file for the first virtual host, run the following command:

sudo nano /var/www/html

Комментарии

Популярные сообщения из этого блога

How To Modify CSS Classes in JavaScript

How To Backup MySQL Databases on an Ubuntu VPS

How To Backup PostgreSQL Databases on an Ubuntu VPS