1. Prerequisites
Before you begin, you will need to have the following:
- A server running Linux operating system.
- Access to a user with root privileges on the server.
- A domain name for each website.
- A static IP address for each website.
2. Installing Web Server
The first step is to install a web server on your server. We will be using Apache for this tutorial. To install Apache, run the following command:
sudo apt-get install apache2
Once Apache is installed, you can configure it to serve your websites.
3. Configuring Apache
Apache can be configured to serve multiple websites from a single server. To do this, you need to create a Virtual Host for each website.
Open the Apache configuration file with the following command:
sudo nano /etc/apache2/sites-available/default
This will open the Apache configuration file in the nano text editor.
In the configuration file, add the following lines for each website:
<VirtualHost *:80>
ServerName website1.com
DocumentRoot /var/www/website1
</VirtualHost>
<VirtualHost *:80>
ServerName website2.com
DocumentRoot /var/www/website2
</VirtualHost>
Replace website1.com and website2.com with the domain names for your websites.
Save the file and exit the text editor.
4. Creating Website Directories
Next, we need to create the directory structure for each website.
Run the following command to create the directories for website1.com:
sudo mkdir -p /var/www/website1
Run the following command to create the directories for website2.com:
sudo mkdir -p /var/www/website2
5. Setting File Permissions
Next, we need to set the correct file permissions for each website.
Run the following command to set the ownership of the website1 directory:
sudo chown -R www-data:www-data /var/www/website1
Run the following command to set the ownership of the website2 directory:
sudo chown -R www-data:www-data /var/www/website2
6. Enabling the Virtual Hosts
Next, we need to enable the virtual hosts we created earlier.
Run the following command to enable website1.com:
sudo a2ensite website1.com
Run the following command to enable website2.com:
sudo a2ensite website2.com
7. Restarting Apache
Finally, we need to restart Apache for the changes to take effect.
Run the following command to restart Apache:
sudo service apache2 restart
Your websites should now be accessible at their respective domain names.