A TEXT POST

Setting up VirtualHosts on Ubuntu 10.10

On my previous post I talked about setting a LAMP server on Ubuntu 10.10. It was a relatively easy process and it didn’t have any configuration to do.

But what happens if you’re developing a website and wanna use a more friendly domain that localhost?

On this post I’ll show you how to set virtual host and develop your website using a more realistic domain

Change from:

http://localhost/mysite

to

http://mydomain.com


Note that you can change mydomain.com to whatever you like. I’ll leave that part to you.

Editing /etc/hosts

Open your terminal and type in this:

sudo gedit /etc/hosts

It will ask for your password, write it and gedit will open:

Check where to write 127.0.0.1 mydomain.com www.mydomain.com

Save and close.


Sites-available

Write this on your terminal:

sudo gedit /etc/apache2/sites-available/mydomain

And just copy and paste this:

Note: You must know the absolute path of your site folder (SITE_ROOT). e.g. ‘/home/me/sites/mywebsite’

<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot PASTE_YOUR_SITE_ROOT_HERE
</VirtualHost>

Save and close.


Enabling sites

On the terminal:

sudo a2ensite mydomain

Will display a message telling us to restart apache.

So what should we do? let’s reload apache:

sudo /etc/init.d/apache2 reload

We’re done!! you can go now to http://mydomain.com


Other settings

That’s how you basically set VirtualHosts. There are still some things to do like fixing problems that may occur trying to use .htaccess rewrites, but I will talk about that on my next post.

  1. yamilurbina posted this