Multiple Virtual Hosts on Mac


/ Published in: Apache
Save to your folder(s)

Instructions for enabling multiple virtual hosts on Mac OSX. Based on default Apple Apache install. If you don't want to be manually changing these files, checkout the very slick GUI application - VirtualHostX (http://clickontyler.com/virtualhostx/)


Copy this code and paste it in your HTML
  1. Open apache config (textmate has been used, but you can replace "mate" with "open -a TextEdit")
  2. mate /etc/apache2/httpd.conf
  3.  
  4. Find "Virtual Hosts". Add and uncomment the two lines below respectively
  5. # Virtual hosts
  6. NameVirtualHost *:80
  7. Include /private/etc/apache2/extra/httpd-vhosts.conf
  8.  
  9. Edit this file
  10. mate /private/etc/apache2/extra/httpd-vhosts.conf
  11. By adding this for each website (ensure the trailing "/" in the Directory tag path
  12. <Directory "/absolute/path/to/uniquename/website/files/">
  13. Options Indexes MultiViews FollowSymLinks
  14. AllowOverride All
  15. Order allow,deny
  16. Allow from all
  17. </Directory>
  18. <VirtualHost *:80>
  19. ServerName "unqiuename"
  20. DocumentRoot "/absolute/path/to/uniquename/website/files"
  21. </VirtualHost>
  22.  
  23. Edit this file
  24. mate /etc/hosts
  25. At the bottom add foreach site
  26. 127.0.0.1 unqiuename
  27.  
  28. Restart apache
  29. sudo httpd -k restart
  30.  
  31. You may also need to flush dns cache, commads for Leopard and before 10.5.1 respectively
  32. dscacheutil -flushcache
  33. lookupd -flushcache
  34.  
  35. Now visit in your browser
  36. http://unqiuename/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.