Saturday, 16 March 2013

Adding a virtual host on mac

Quickly adding a virtual host on mac (10.6) assuming your adding the host name "test".
  1. Add your host name to your hosts file
    • Open a terminal and type: sudo nano /etc/hosts
    • Add "127.0.0.1 test" to the bottom of your hosts file, without the quotes.
  2. Enable apache vhosts file
    • open your httpd.conf 
    • in a terminal type: cd /private/etc/apache2
    • then: sudo nano httpd.conf 
    • find the line #Include /private/etc/apache2/extra/httpd-vhosts.conf
    • remove the # at the beginning of the line (if it has one, if not, your good to go)
  3. Add the folder you want the host to reference to the httpd-vhost.conf file
    • back in the terminal: cd extra
    • then: sudo nano httpd-vhosts.conf 
    • add the following to the bottom of the file, changing the DocumentRoot, directory paths and log file names appropriately.
    • <VirtualHost *:80>
          ServerAdmin webmaster@dummy-host2.example.com
          DocumentRoot "/User/patrickc/www/test"
          ServerName test
          ErrorLog "/private/var/log/apache2/test-error.log"
          CustomLog "/private/var/log/apache2/test-access.log" common
          <directory "/User/patrickc/www/test/">
             Options Indexes FollowSymLinks
             AllowOverride All
             Order allow,deny
             Allow from all
          </directory>
      </VirtualHost>
          
  4. Restart apache
    • in your terminal; sudo apachectl restart (on some setups it might be; sudo apache restart)
  5. Then open a browser and type http://test
  6. That should be it, if you get a permissions error check the value in  <directory  />


No comments:

Post a Comment

 

Note: the opinions on this page don't represent that of my employer in anyway. And, actually only vaguely represent my opinions on the date of publication. (Unlike Ms T, I am very much for turning)