If you have decided to go with XAMPP on your OSX machine, then you have made the right choice as it works excellent on the Mac and has almost no limitations. Because of the file structure was not the typical WAMP or server setup I was used to it was a bit tricky at first. In case anyone else had trouble here's a quick tutorial on how to get it rolling.
I've got XAMPP installed in /Applications/XAMPP so for the rest of this blog I'll assume you did the same. Open up your Terminal which you can find under /Applications/Utilities/Terminal.
Enable Virtual Hosting (vhost)
To enable virtual host, navigate to the XAMPP folder by typing in:
This is the root for your XAMPP application, now navigate into the etc folder:
Here you'll find a bunch of files which is really the configuration for your localhost server. What you need to edit is the httpd.conf file. You do so with the vi editor. Next I'll show you the series of steps to do so and do a quick comment explaining them using the # sign (which means don't type in the # stuff). Some of you may have read/write problems so just tag sudo infront like I did and type in your computer password.
# Open the httpd.conf file with the VI editor sudo vi httpd.conf # Find where the vhost module is and include it /vhost # You'll end up with a line like this: # LoadModule vhost_alias_module modules/mod_vhost_alias.so # (which is commented out) # Hit i to go into edit mode i # Remove the hash at the beginning of that line # Once you're done hit [ESC] [ESC] # Now we look for the second vhost line /vhost # If the above command lingers in the line you just edited # keep hitting it until you find this # Virtual hosts #Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf # Hit i to go into edit mode i # Remove the hash at the beginning of the line with Include # hit [ESC] when done [ESC] # Now save and exit the file :wq
Creating Virtual Hosts
Ok now you'll be back in the etc directory, now you have to add some virtual host for your machine. Navigate into the extra folder:
Now we're going to edit the httpd-vhosts.conf file which tells the local which domains are virtual hosts. Once again we do so with the vi editor:
# Edit the httpd-vhosts.conf sudo vi httpd-vhosts.conf
At the top of the file you'll see a huge chunk of comments which is for you reference, navigate to the bottom by hitting Shift + G. By default you'll need this chunk of code:
Options Indexes FollowSymLinks Includes execCGI
Allow From All
If you have it then you're fine, if you don't hit [i] and paste it at the bottom. This block basically tells the localhost that the address http://localhost leads to /Applications/XAMPP/htdocs, which is that orange/white screen default for XAMPP. You'll need to change the address if you've installed it in a different directory.
Now after that chunk of code you can start creating virtual hosts. Instead of writing line by here's a chunk of code you can copy modify and paste in. This chunk is to define http://myhost.crankberry/ as my local Crankberry virtual host.
Options Indexes FollowSymLinks
Allow from all
There's four lines in there you'll need to change. The second and third which indicates your virtual host names. You can create anything but don't create something like google.com because then you won't be able to actually access google. Then you have to change the Document Root and Directory URL to point to where it physically sits. Once you're done:
# Hit [ESC] [ESC] # Save and exit :wq
Telling Your Machine You Have Virtual Hosts
Now your virtual host is almost done, you just need to tell your machine that you have these virtual hosts setup and they need to direct to those path. You will need to edit your computer's hosts file, do so by using the VI editor again:
sudo vi /etc/hosts # Notice the / in front of etc, that means I'm looking into # the root of the computer, not the etc folder in XAMPP
Now we're going to define the virtual host on the localhost port which is 127.0.0.1:
# Navigate to the bottom Shift + G # Hit i to insert i # Type in the IP and your vhost 127.0.0.1 myhost.crankberry # Hit [ESC] [ESC] # Save and exit :wq
After that you made need to restart your XAMPP, but for me if I navigate to http://myhost.crankberry on my browser it works like a charm. Give it a go.