Get 69% Off on Cloud Hosting : Claim Your Offer Now!
Apaches Virtual Hosts serve as the most effective way to host more than one website on a single computer. They help you to sign up on and operate multiple domains and control them with specific configurations either easily or professionally.
We'll approach this task by following each step of the process one at a time, beginning with setting up Apache Virtual Hosts on Ubuntu 20. 04.
Let’s get started!
1. Prerequisites:
First ensure that you have:
Access to an Ubuntu 20.04 server with Apache installed.
Administrative privileges or access to the sudo command.
2. Verify Apache Installation:
First, ensure that Apache is installed and running on your Ubuntu server by executing the following command:
lua Copy code sudo systemctl status apache2 |
If Apache is not installed, you can install it using:
sql Copy code sudo apt update sudo apt install apache2 |
3. Create Directory Structure:
Next, create a directory structure to store your website files. We'll create a directory for each virtual host:
css Copy code sudo mkdir -p /var/www/example.com/html sudo mkdir -p /var/www/test.com/html |
4. Grant Permissions:
Assign ownership of the directories to your user:
bash Copy code sudo chown -R $USER:$USER /var/www/example.com/html sudo chown -R $USER:$USER /var/www/test.com/html |
5. Create Sample HTML Files:
Create sample HTML files for each website:
css Copy code echo " echo " |
6. Create Virtual Host Files:
Create virtual host configuration files for each domain:
bash Copy code sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/test.com.conf |
7. Edit Virtual Host Files:
Open the virtual host files in a text editor:
bash Copy code sudo nano /etc/apache2/sites-available/example.com.conf |
Replace the content with:
bash Copy code ServerAdmin [email protected] ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/example.com/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined
|
Repeat the process for test.com.conf, replacing example.com with test.com.
8. Enable Virtual Hosts:
Enable the virtual hosts:
Copy code
sudo a2ensite example.com.conf
sudo a2ensite test.com.conf
9. Disable Default Site:
Disable the default site:
arduino Copy code sudo a2dissite 000-default.conf |
10. Restart Apache:
Restart Apache to apply the changes:
Copy code sudo systemctl restart apache2 |
Congratulations! You have managed to do the ASVS (Apache Virtual Hosts) service installation on your local Ubuntu 20. 04 server. Server now allows you to use the multi-user functionality for easy one-server configuration and each one of them could have its own domain and setup.
Such a powerful feature of Apache makes it possible to quickly and seamlessly conduct requirements for different projects that may host multiple websites at the same time. As a consequence, it is crucial for any web server administrator to master this skill. For more information-contact our VPS Hosting India experts today!
Let’s talk about the future, and make it happen!
By continuing to use and navigate this website, you are agreeing to the use of cookies.
Find out more