# Archive: Install Apache and Create Virtual Hosts in Ubuntu and CentOS

**URL:** <https://community.itbible.org/t/archive-install-apache-and-create-virtual-hosts-in-ubuntu-and-centos/2036>\
**Category:** Blog\
**Created:** [May 30, 2025, 11:21pm UTC](https://community.itbible.org/t/archive-install-apache-and-create-virtual-hosts-in-ubuntu-and-centos/2036 "2025-05-30T23:21:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://community.itbible.org/uploads/default/original/1X/14adcecb0b165506de5537ee487586ba0b28455f.png) [@system](https://community.itbible.org/u/system)\
**Post date:** [May 30, 2025, 11:21pm UTC](https://community.itbible.org/t/archive-install-apache-and-create-virtual-hosts-in-ubuntu-and-centos/2036/1 "2025-05-30T23:21:38Z")

</div>

🗒️

This is a re-post from a previous version of The Computer Crowd.

If you are reading this chances are you are looking on how to host multiple websites on a single server.

This guide is going to cover installing Apache2 and creating multiple virtual hosts, for different domains and / or subdomains. I will show examples in Ubuntu and CentOS. I started with a fresh install of both operating systems for this tutorial.

**Note:** &nbsp;_I never suggest logging in as root. I would also run the service as a non-root user._

## Ubuntu

**Step 1: Install Apache2**

```
sudo apt-get install apache2
```

**Step 2: Create Directory Structure** Personally I like the directory structure organized so I would do something like below.

```
sudo mkdir /var/www/domain1.com
sudo mkdir /var/www/domain2.com
```

**Step 3: Create/Edit Your Virtual Hosts** For this example you can just copy and paste the code below for each of your domains.

```
sudo nano /etc/apache2/sites-available/domain1.com
```

Be sure to change the information to your specific info.

```
<VirtualHost *:80>
        ServerAdmin [email protected]
        ServerName domain1.com
        ServerAlias www.domain1.com domain1.com
        DocumentRoot /var/www/domain1.com
        <Directory /var/www/domain1.com/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride all
                Order allow,deny
                allow from all
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/domain1.com-error.log
        CustomLog ${APACHE_LOG_DIR}/domain1.com-access.log combined
</VirtualHost>
```

Then repeat for additional domains.

**Step 4: Enabling Your Virtual Hosts** For each file you created above run the following command.

```
sudo a2ensite domain1.com
```

Once you have enabled all of your virtual hosts you then run.

```
sudo service apache2 reload
```

As long as your domains are pointed to your network and port 80 is open your domains should be directed to the correct virtual host.

## CentOS

**Step 1: Install httpd**

```
sudo yum install httpd
```

**Step 2: Have Apache Start at Boot**

```
sudo chkconfig -levels 235 httpd on
sudo service httpd start
```

or with CentOS 7

```
sudo systemctl enable httpd
sudo systemctl start httpd
```

**Step 3: Create Your Directory Structure**

```
sudo mkdir /var/www/domain1.com
sudo mkdir /var/www/domain2.com
```

Repeat for any additional sites.

**Step 4: Configure Your Virtual Hosts** Open the httpd.conf

```
sudo vi /etc/httpd/conf/httpd.conf
```

Add the following lines to the bottom of httpd.conf be sure to hit “i” to insert text.

```
<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName www.domain1.com
    ServerAlias www.domain1.com domain1.com
    Document Root /www/domain1.com
    ErrorLog logs/domain1.com-error.log
    CustomLog logs/domain1.com-access.log combined
</VirtualHost>
```

Repeat for each additional host you want to add.

Save the file by hitting Esc and typing:

`:wq`

**Step 5: Restart the Apache HTTPD**

```
sudo service httpd restart
```

or in CentOS 7

```
sudo systemctl restart httpd
```

* * *
This is a companion discussion topic for the original entry at [https://itbible.org/archive-install-apache-and-create-virtual-hosts-in-ubuntu-and-centos](https://itbible.org/archive-install-apache-and-create-virtual-hosts-in-ubuntu-and-centos)
