Dexter Evil Clone.

Alchemiclabs.ca


Welcome Demo

Setting up multiple websites on one Apache2 server is a common task in web hosting. This tutorial will guide you through the process of configuring Apache to host multiple websites on a single server using Virtual Hosts. We'll assume you have a basic understanding of Linux and have already installed Apache2 on your server.

Note: This tutorial is based on a Linux environment. The specific steps may vary depending on your distribution, but the concepts are generally the same.

Step 1: Prepare Your Server

Make sure your server is up-to-date and Apache2 is installed. You can do this by running the following commands:

sudo apt update
sudo apt upgrade
sudo apt install apache2

Step 2: Create Website Directories

Create directories for your websites. Each website should have its own directory structure. For example:

sudo mkdir -p /var/www/website1.com/public_html
sudo mkdir -p /var/www/website2.com/public_html

Step 3: Set Permissions

Make sure Apache can read these directories:

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

Step 4: Create Sample Web Pages

You can create simple HTML pages or copy your website files into the respective directories (e.g., /var/www/website1.com/public_html and /var/www/website2.com/public_html).

Step 5: Create Virtual Host Configuration Files

Create a Virtual Host configuration file for each website you want to host. These files will tell Apache how to handle each domain. You can create these files in the /etc/apache2/sites-available/ directory:

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

Inside the file, add the following configuration for website1.com. Customize it according to your needs:

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

Save the file and exit the text editor.

Repeat the process for website2.com:

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

And add similar configuration with the appropriate values for website2.com.

Step 6: Enable Virtual Hosts

Enable the virtual hosts you've created:

sudo a2ensite website1.com.conf
sudo a2ensite website2.com.conf

Step 7: Test Configuration and Restart Apache

Before you restart Apache, it's a good idea to test your configuration for syntax errors:

sudo apache2ctl configtest

If you receive a message that says "Syntax OK," you can proceed to restart Apache:

sudo systemctl restart apache2

Step 8: Configure DNS

Point the DNS records for your domain names to the IP address of your server. This can usually be done through your domain registrar's control panel.

Step 9: Verify Your Websites

In your web browser, visit http://website1.com and http://website2.com to verify that your websites are working correctly.

Congratulations! You have successfully set up multiple websites on a single Apache2 server using Virtual Hosts. You can repeat the process to add more websites as needed, following the same general steps.