I've officially reached the end of my wits on this problem. As someone who constantly works on several websites at a time (I'm sure I'm not alone here), it becomes frustrating renaming my "htdocs" directory whenever I want to work on a different site, so I decided to throw together a simple script.
My first approach was to reset the "DocumentRoot" variable in "httpd.conf" based on the directory input I provided, however, having a DocumentRoot outside of the main "/Applications/XAMPP/" directory has proven to be a bigger problem. As you can see, I'm running OSX with an XAMPP installation. Ideally, I'd like to have all my sites located at "/Users/Me/Sites/*". Even when I tried to move my sites within XAMPP's base directory, Apache does not want to load anything other than "htdocs" as my DocumentRoot.
My next approach was to simply add symbolic links to all the files/directories within each site I was working on at the time to "htdocs". This loads fine in the browser for basic html files, however, I work primarily with PHP and this does not appear to want to render (I can see the file but it will not display as a webpage).
Neither of these approaches in themselves sound too difficult, but from learning Xcode, to AppleScript, to Apache's httpd.conf documentation, I feel I've experienced enough headaches. I've played with permissions for each attempt I've gone through and nothing has panned out for me yet.
I'm sure there are plenty of other webdesigners out there who have faced this problem in the past, what's your solution?
This is actually really easily achieved, given that you are using XAMPP, I am not 100% but if you go under /bin/apache2/conf/extras/
you should see a file called httpd-vhosts.conf
in this file you can add as many virtual hosts as you want. Make sure you set the ServerName
to be something unique. Once that is done, make sure that the Include Vhosts is enabled in the httpd.conf
Now, you just edit your hosts file. I am not sure where this is on OSX, since it is linux based I would say /etc/hosts
but google will help you. Add a line for each of your sites like so:
127.0.0.1 site1.dev
127.0.0.1 site2.dev
etc. Now restart apache and in your browser type site1.dev
and apache should understand it and take you to that site. Pretty simple.