How to change the domain name of a virtual host in Apache

This instructions will be useful for you if you have a webserver with Ubuntu 12.04 (I have not tested this solution with other versions) running Apache 2.2.

Starting point:

You have a domain configured as a virtualhost. For example:

Ending point:

You want to change it to

These are the steps you have to follow:

1. Modify /etc/hosts

The line
should be changed to

2. Rename the file /etc/apache2/sites-available/ to

mv /etc/apache2/sites-available/ /etc/apache2/sites-available/

3. Rename the folder where you have the public content, that is the DocumentRoot Apache configuration.
E.g. in my case, this is /var/www/
mv /var/www/ /var/www/

4. Disable the former site and enable the new one:


On one hand, this will remove the symlink in /etc/apache2/sites-enabled that refers to /etc/apache2/sites-available.
And on the other this will create a new symlink for the new site.
Further details about a2ensite and a2disite here:

5. When you are done, restart Apache

service apache2 restart


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s