Skip to content

How To Set Up Apache Virtual Hosts on Ubuntu 12.04 LTS

Cloud Infrastructure Expert
How To Set Up Apache Virtual Hosts on Ubuntu 12.04 LTS

 

Apache Virtual Hosts allow you to run multiple websites on a single server. This guide will show you how to set up virtual hosts on Ubuntu 12.04 LTS.

1. Install Apache

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

sudo apt-get update
sudo apt-get install apache2

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 file for your website in the /etc/apache2/sites-available/ directory. For example:

sudo nano /etc/apache2/sites-available/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 ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    

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

4. Enable the Virtual Host

Enable the new virtual host configuration using:

sudo a2ensite example.com.conf

5. Test Apache Configuration

Ensure that there are no syntax errors in the Apache configuration:

sudo apache2ctl configtest

If the test is successful, you should see Syntax OK.

6. Restart Apache

Apply the changes by restarting Apache:

sudo service apache2 restart

7. 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:

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.

8. Verify Your Setup

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

9. Create Additional Virtual Hosts

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

10. 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

Windows VPS Portugal

VPS Windows Italia

Windows VPS

Windows VPS

Windows VPS Sverige

Windows VPS Norge

Windows VPS

Windows VPS Türkiye

Windows RDS (Remote Desktop Services)

Windows VPS

Explore more

More on this topic

Netcloud24
Netcloud24
Cloud Infrastructure Expert · NetCloud24

Comments are closed.