Create a VHOST for a website in Apache

Create a VHOST for a website in Apache

Last updated:

This is what you should do if you want a certain url to point to a specific folder on your system:

create a new file under /etc/apache2/sites-available (for example's sake we will name that file foobar.yourhost.com so you can know what it points to.)

on that file, you must write the configuration. Here is an example:

<VirtualHost *:80>
    ServerName foobar.yourhost.com
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/foobar
     <Directory />
         Options FollowSymLinks
         AllowOverride None
     </Directory>
     <Directory /var/www/foobar/>
         Options Indexes FollowSymLinks MultiViews
         AllowOverride All
         Order allow,deny
         allow from all
    </Directory>
</VirtualHost>

activate the VirtualHost you've just created:

sudo a2ensite foobar.yourhost.com

Restart apache

DNS Issues

You still need to make that address point to your IP

Now everytime a user types in http:://foobar.yourhost.com, they will be redirected to the foobar directory. You still need to make that address point to your IP.

That's a DNS matter. However, once you've pointed http://foobar.yourhost.com to your IP, then Apache will know what to do with it, namely redirect to the foobar directory.

If you're just testing out on localhost, you just need to open /etc/hosts and add another line, like this:

127.0.0.1   localhost
127.0.0.1   foobar.yourhost.com
# other hosts