How To Set Up Apache Virtual Hosts on Ubuntu 14.04 LTS

How To Set Up Apache Virtual Hosts on Ubuntu 14.04 LTS

How To Set Up Apache Virtual Hosts on Ubuntu 14.04 LTS

In this tutorial, we will learn how to set up Apache Virtual Hosts on Ubuntu 14.04 LTS. Virtual Hosts allow you to run multiple websites on a single server, each with its own domain name and content.

Prerequisites

To follow this tutorial, you will need:

  • An Ubuntu 14.04 LTS server
  • Apache installed and running
  • Basic knowledge of Apache configuration files

Step 1: Create the Virtual Host Directory

The first step in setting up a Virtual Host is to create a directory to hold the website files. This directory should be located in the /var/www/ directory.

For example, to create a directory for a website with the domain name example.com, run the following command:

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

Step 2: Set Permissions

Next, we need to set the correct permissions for the directory we just created. We'll give ownership of the directory to the www-data user and group, which is the user Apache runs as.

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

Then, we'll give the user group permission to write to the directory:

sudo chmod 775 /var/www/example.com/public_html

Step 3: Create the Virtual Host File

Now we need to create a Virtual Host file for our new website. Virtual Host files are located in the /etc/apache2/sites-available/ directory. You can create a new file with the domain name of your website:

sudo nano /etc/apache2/sites-available/example.com.conf

And add the following content:

<VirtualHost *:80>
        ServerAdmin webmaster@example.com
        ServerName example.com
        ServerAlias www.example.com
        DocumentRoot /var/www/example.com/public_html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
    

Save the file and exit the editor.

Step 4: Enable the Virtual Host

Now that we've created our Virtual Host file, we need to enable it:

sudo a2ensite example.com.conf

This will create a symbolic link from the /etc/apache2/sites-available/ directory to the /etc/apache2/sites-enabled/ directory.

Step 5: Restart Apache

Finally, we need to restart Apache

Комментарии

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

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