My recommended setup for web-developers on OSX
If you want to do any kind of web-development on the Mac that involves PHP and the Apache webserver, you have a few options:
- Use the Apple provided, built-in apache plus PHP. You can turn on the web-server (with PHP) in your system preferences menu as ‘Web Sharing’. From that point on your Sites directory will function as your web document root (~/Sites). The bad thing with this setup is that you cannot just install any kind of PHP module, or apache module. Or if you do, you will regret it once the next system update arrives from Apple (which - by the way - overrides all your changes…)
- Download and use MAMP. I have seen it used in lots of tutorials and books. The only bad thing with it, is that it is quite spartan, and has been updated quite a long time before (2008-08-27) - seems that its devs are abandoning it for good. Not recommended.
- My recommendation is to use XAMPP. The good thing with XAMPP is that it is more or less regularly updated with not so major breaking changes, but still keeping you on top of the almost very latest PHP / MySQL releases. XAMPP is also cross platform in the widest sense of the world. This is good mostly for Mac / Windows users, but some Linux users could also benefit. XAMPP is available for the Mac, Windows, Linux, and Solaris platforms.
I have been using XAMPP for almost 2 years now. I have just recently upgraded my previous pre1.0 version to its latest 1.0.1 version - which includes MySQL 5.1.33, PHP 5.2.9, Apache2.2.11 with mod_ssl support and tons of other modules. You can download the OSX version from here.
If you use XAMPP you will just unpack its files into your /Applications folder (the path must be this, otherwise all the scripts will break inside), then drag /Applications/XAMPP/XAMPP Control to your dock and you can start enjoying it.

I do have a few recommendations for OSX users though.
None are too important, it’s just my way of thinking.
First, create a directory for your database files, that is not in /Applications. The way to do that is e.g. create a directory (mkdir) somewhere under your home dir, e.g. mkdir ~/mysql, and then move all the files from XAMPP/xamppfiles/var/mysql to its new home. symlink ~/mysql to XAMPP/xamppfiles/var/mysql (ln -s …xamppfiles/var/mysql ~/mysql), and make sure the owners and rights are correct (chown, chmod pair).
Test if mysql starts OK with the XAMPP Control application. It should start OK. If not check that you did everything as I wrote.
Now onto the website part. I like the XAMPP webserver to use the files from my Sites directory, as its the sole purpose of that system-supplied directory.
Remove /Applications/XAMPP/htdocs, and symlink it to your Sites dir by ln -s htdocs ~/Sites. Test it as well by starting it. Everything should be OK. If you face some problems use chown / chmod as needed (read man chmod, man chown if you have no idea about these two).
If everything works well, now is the time to use my optimizations. I have basically modified the php install in the XAMPP distro to have the APC and the XDEBUG extensions. APC has 64 mbyte cache, and the file upload progress function turned on, whilst xdebug can be used with most PHP ides-s for debugging your app (like netbeans, komodo, etc.).
I have also enabled SSL support (so you can test https://localhost/ as well), and a few good PHP extensions (gd, pdo, pdo_sqlite, mysql, curl, …) whilst also ramming up the PHP max_memory_size to 96MB.
There’s also an additional vhost-alias feature that I turned on. It basically allows you to have URLs like http://my-cool-site/ function on your machine if you put all its files into your ~/Sites/my-cool-site/ directory. If you do this, you need to edit your hosts file (sudo nano /etc/hosts) and add an alias for this name to point to localhost. Well basically add the line: 127.0.0.1 my-cool-site. Done. This makes working with several sites (especially if they use absolute URLs inside which many frameworks, etc. do) easy.
My optimizations can be downloaded from here.
This is a zip file, which contains some additional and some modified files (namely php.ini, httpd.conf, and two more extra confs to enable the above mentioned features, plus the php apc and xdebug extensions). Just unpack it, and copy / overwrite the files one-by-one (this is important!) from their respective folders to the original places in the XAMPP distro. Of course before you do that make sure none of XAMPPs services are running (so no mysql and no apache).
Happy days
Enjoy!
Questions can be addressed to me on the comment form.
Complete beginners please do not bother. You have to have some experience before you attempt to do this. …I mean in case some problems arise - and you’re on your own.
Recent Comments