Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I have php and apache enabled and a folder test located in my ~/Sites. Is there anyway to access it thanks to the address http://test.dev instead of http://localhost/~user/test ?

share|improve this question

1 Answer 1

This is called a "Virtual Host". Here's how I set them up:

  • Edit /private/etc/apache2/httpd.conf, and change

    # Virtual hosts
    # Include /private/etc/apache2/extra/httpd-vhosts.conf

    to be:

    # Virtual hosts
    Include /private/etc/apache2/extra/httpd-vhosts.conf
  • Edit /private/etc/apache2/extra/httpd-vhosts.conf and add an entry that's something like this:

    <VirtualHost *:80>
        DocumentRoot "/Users/dave/Sites"
        ServerName test.dev
  • Edit /private/etc/hosts and add this entry: test.dev
  • Restart your webserver (I use sudo apachectl restart)

There are some example virtual host definitions in the httpd-vhost.conf file that are there to show you what the syntax looks like. They look like this:

# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/usr/docs/dummy-host.example.com"
    ServerName dummy-host.example.com
    ServerAlias www.dummy-host.example.com
    ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
    CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common

Add # signs to the beginning of those lines to comment them out.

An alternative to this is to use an app like VirtualHostX to do this for you ($35).

Edit 5 Dec 2011:

Here's a new blog post by the makers of Alfred on how they set this up:


share|improve this answer
This doesn't seem to be working... I also tried restarting by unchecking-checking the Web Share in the System Preferences, but it is also not working. –  Aliou Nov 12 '11 at 21:41
@aliouftw Run "apachectl -S" in terminal to see if you've misconfigured something –  Dave DeLong Nov 12 '11 at 21:44
it returns this –  Aliou Nov 12 '11 at 21:47
@aliouftw updated answer. –  Dave DeLong Nov 12 '11 at 21:51
also not working. apachectl -S is now returning this –  Aliou Nov 12 '11 at 21:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.