Hosting multiple websites on Apache2

Creating Virtual Hosts


1. Make a new “sites-available” file

In the /etc/apache2/sites-available/ directory, you will see a default file called “default”. Use this as a template for your virtual host files. To to this, simply make a copy of it, that is renamed something else. For example:

cp default test.nawras.com

For clarity, it is a good idea to name the file to be the same as the domain name of the website that will be hosted. This will allow easily identifying the files on your server. You can call them anything you want however.

2. Edit the new “sites-available” file

Now you need to edit the file you have just created so that it will work for the website you want to host on your server. Start by opening it in your favorite text editor..

nano test.nawras.com

…and edit it so that it contains the name of the website you want to host. In this case, let’s say I want to host test.nawras.com’s website. Below is an example of how the beginning of the edited new “sites-available” will look:

<VirtualHost *>
      ServerAdmin nawras@2sna3.com
      ServerName test.nawras.com
      DocumentRoot /var/www/test.nawras/
      <Directory />
              Options FollowSymLinks
              AllowOverride None
      <Directory /var/www/test.nawras/>
              Options Indexes FollowSymLinks MultiViews
              AllowOverride None
              Order allow,deny
              allow from all


You can remove the first line NameVirtualHost * that is copied from the default file.

Be sure to add the ServerName line, which is not in the default file.

The DocumentRoot line is where you specify the directory the web pages of your friend will go on your server. You can make up anything you want to identify this, but be sure that you have made this directory. This is where the web pages for test.nawras.com will go.



There is no limit to how many websites you want to virtually host. All you need to do is to create a new file in the sites-available directory. This being said, the more websites that you host on your server, the slower your server will be. Therefore, if your Gandi server is handling the websites slowly, then you can simply add more shares in order to increase its power and speed up the websites.



Finally, you need to create a symbolic link to your file in the /etc/apache2/sites-enabled/ directory. To do this type:

cd /etc/apache2/sites-enabled

To move to the sites-enabled folder, and then:

ln -s /etc/apache2/sites-available/test.nawras.com

To create a link to your newly-created virtual host file.

Alternatively you can use a2ensite and a2dissite to enable an disable your new domain configuration.

To enable your new domain configuration, you can also create a link automatically using the command:

a2ensite test.nawras.com

And to disable the test.nawras.com configuration you can type:

a2dissite test.nawras.com

4. Restart apache

When done, be sure to restart apache so that your changes will be taken into consideration by your server. Do this by typing in the following:

/etc/init.d/apache2 restart

For minor changes in configuration you can just reload the configuration of Apache, this will have a smaller impact on your running site.

/etc/init.d/apache2 reload



That is all! Do not forget that you need to point the domains of the websites that you are hosting to your Gandi server.



5. Troubleshooting



Do not forget to restart apache after making changes to its configuration!



apache2: apr_sockaddr_info_get() failed for ubuntu

Solution: in etc/hosts, add the name of your machine before localhost like the following:       ubuntu localhost

Error: apache2: Could not reliably determine the server’s fully qualified domain name Solution: You need to add your server’s name in the /etc/apache2/httpd.conf file. If you don’t know yous server’s name, type the following in your terminal:


It will then return the name of your server; for example, ubuntu. Then, using your favorite text editor, add the an entry in your /etc/apache2/httpd.conf file as follows (replace ubuntu with whatever the name of your server is):

ServerName ubuntu
Share Button

Comments are closed.

ALl Rights Reserved @Nawras Tech2017
All Rights Reserved 2017 NawrasTech