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 so you can know what it points to.)

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

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

activate the VirtualHost you've just created:

sudo a2ensite

Restart apache

DNS Issues

You still need to make that address point to your IP

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

Twitter Linkedin YC Hacker News Reddit

That's a DNS matter. However, once you've pointed 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:   localhost
# other hosts

Dialogue & Discussion