Filed under: How-tos, Freeware, Internet Tools, Open Source
Apache and PHP on a Mac
One of the very first cool things I
learned about the guts of OS X was the existence of Apache, an industrial-strength web server, built in to the OS.
O'Reilly has a nice piece on getting started with
Apache, so start there if you're new to web serving on your Mac. Imagine hosting your own pages for your own home
intranet. Now take that one step further, and imagine dynamic pages, ones capable of accessing data from the web or
your machine, on your home network (or using DynDNS, anywhere).I'm going to point out a few resources for getting started using Apache and PHP on your Mac. You'll find the combination powerful, and getting up to speed is relatively simple. There's some programming involved, so if you're scared of that sort of thing, check out How to Think Like a Computer Scientist: Learning with Python. Granted, you'll be learning Python, but guess what? You can use Python on your Mac as well. Python goes beyond web programming, and is a great language to get familiar with. If you want to learn PHP, check out Webmonkey's PHP section, or W3 School's PHP intro.
Apple has a page on getting PHP working on your Mac. It's a nice article too, with a step-by-step building of a page to view your iTunes library, complete with plenty of XML goodness as well. The problem here is the version of PHP that comes with your Mac is generally a version behind the current release. While PHP 4.3 was nice, version 5 adds some great stuff. The version of Apache shipping with your Mac probably isn't the latest rev of that either, so check out phpmac's tutorial on installing Apache 2.20 and PHP 5.1.2. It's only for OS X version 10.4.4, but it'll still work with 10.4.5 (no warranty expressed or implied, back up your data, etc.).
Once you have more current versions up and running, try out some of those programming resources, and try building apps. I think you'll find while Apache keeps your Mac acting like a great web page server, PHP can turn your private pages into real network apps. What's really great about setting up PHP on your Mac isn't just a home network, but being able to build and test web apps too, all from the comfort of your favorite OS.

![TUAW [Cafepress]](http://www.blogsmithmedia.com/www.tuaw.com/media/tuaw-cafepress-promo.png)


Reader Comments (Page 1 of 1)
Erik said 9:01AM on 2-20-2006
Just a quick site note - if you don't feel like going whole hog and tinkering with your active apache and php installation, I just found the excellent "MAMP" package which is a standalone application containing apache 2, php5 and mySQL.
Everything is all nicely bundled up in a Mac style application. Fire it up and you have a complete development environment with no fiddling under the hood, nor worries that all of your carefully fine tuned settings will get overwritten by the next OS update.
Not designed for hosting purposes, but if you want a quick and dirty development environment, it's hard to beat.
Reply
Christian said 9:05AM on 2-20-2006
If you want to install Apache/PHP/MySQL with just a few mouse clicks and without touching the original Mac OS X configuration then you should check out MAMP (Macintosh, Apache, Mysql and PHP).
Reply
Adrian said 9:45AM on 2-20-2006
As the Apple article suggest, getting the binary distribution pkg installer (http://www.entropy.ch/software/macosx/php/) is much more easy than compiling php yourself. And since you want it for personal use, you don't need that tad speed you could squeeze out of it anyway.
Reply
Sam said 11:11AM on 2-20-2006
Another really good set of installer packages is available from Server Logistics. They have packages for Apache2/PHP/MySQL/Tomcat/MapserverOSX.
http://serverlogistics.com/downloads.php
Reply
Ken R said 11:28AM on 2-20-2006
Yes, the Entropy installer is really great. I haven't used MAMP, and I don't really care what I do to my OS configuration :)
Reply
Israel Alvarez said 12:20PM on 2-20-2006
One other thing: PHP isn't just an Apache Plugin. It's also a stand-alone CGI (the Entropy version comes with it, available at /usr/local/php5/bin/php . What's cool about this is you can call this to run non-web scripts just like you would with Perl or Python or Ruby.
There's even a couple of apps that will let you attach user interfaces to your PHP scripts: Platypus (http://sveinbjorn.sytes.net/platypus) and Pashua (http://www.bluem.net/downloads/pashua_en/). I've had a blast with these.
Reply
Patrick said 12:33PM on 2-20-2006
One reason people commonly install Apache + PHP on their Macs is to test and develop websites on which they're working. To ensure absolute paths work properly as they would on a production server, virtual hosting needs to be employed. I have created a shell script that makes it easy to add as many virtual hosts as you want to your computer. Note that this script is intended for Apache 1.3.x:
http://patrickg.com/virtualhost
Reply
George Brett said 1:04PM on 2-20-2006
Last February, Ward Mundy at Nerd Vittles did a great series "how to" about setting up an "ISP in a Box" with the box being a Mac Mini. Still worth reading.
http://mundy.org/blog/index.php?p=23
Reply
Melvin Rivera said 3:59PM on 2-20-2006
this All Forces tutorial on WordPress on Mac covers installation of PHP and MySQL. Part 2 covers setting up local sub-domains.
Reply
Melvin Rivera said 4:03PM on 2-20-2006
sorry. i missed the url instructions. here they are:
step 1 - php and mysql : http://allforces.com/2005/08/22/wordpress-on-mac-phpandmysql/
step 2 - subdomains : http://allforces.com/2005/08/23/wordpress-on-mac-subdomains/
Reply
Robert Jung said 6:54PM on 2-20-2006
As long as we're geeking on Apache/PHP development on Mas, does anyone have a reliable way to activate Apache's mod_rewrite for the MacOS X's installation of Apache? I use that in a lot of the stuff I develop, but I have to use workarounds when on the Mac because I can't figure out how to enable it. (I'm using MacOS X 10.3.9, for what it's worth)
And another vote for Marc Liyange's binary distribution PHP package; not only is it easy-peasy to use, it includes the GD graphics library, which is a bonus for graphically-oriented web development.
--R.J.
Reply
Jack said 10:08PM on 2-20-2006
As much as I love tinkering with UNIX, what I don't like about Apple's built in Apache is how--with every update--the preferences revert to default preferences. It's tough enough to be a web developer without having to deal with stuff like that.
Instead--and as others have recommended--I highly recommend using MAMP as a development and serving platform. It comes with the lastest version of Apache and has PHP and MySQL built in. It even has phpMyAdmin already set. Simply download it, launch it and you have an instant setup.
I used to use the Entropy packages, but MAMP suits all of my needs.
Reply
Eric Kiel said 12:05PM on 2-21-2006
I've written an article for Securing MAMP on my site check it out.
http://machinaproject.dyndns.org/2006/02/19/how-to-secure-mamp/
Reply
maique madeira said 11:11PM on 2-22-2006
i'm also using MAMP as a testing ground.
it works just perfect and couldn't be easier to set up.
Reply