Using macport to setup php5 / apache2 on Leopard

by rp

As you can tell I got myself a new macbook and its pretty much ritualistic to install apache/php5 on it for me. I agree it comes with both of them pre-installed but really I just like to do it for the easy of configuration. I have written earlier how I compiled everything on Leopard in the past. This time I plan on trying something different.
I am using mac ports (possibly coz I am getting lazier). Here are a couple of quick start guides of port.

# Selfupdate
$sudo port selfupdate

# selfupdate, if you want to see what's going on.
$sudo port -d selfupdate

#search for a particular package
$sudo port search apache2

#search for variants like for instance, mysql and its server
$sudo port install mysql 

#search information about package
$sudo port info php5

#get info about dependencies for a package
$sudo port deps php5

#install package
$sudo port install apache2

#install package with variant like mysql and its server
$sudo port install mysql +server

#clean all the guff
$sudo port clean --all

#get the contents of a package
$sudo port contents apache2

#get installed packages
$sudo port installed

#upgrade package
$sudo port upgrade apache2

#update all outdated packages
$sudo port upgrade outdated

So back to setting up apache2 and php5

$sudo port install apache2

It does its standard business and then confirms the installation, similarly for installing php5, it has the following variants available that might interest you.

rp@busybox:~ rp$ sudo port variants php5
Password:
php5 has the variants:
	darwin_6: Platform variant, do not select manually
	darwin_7: Platform variant, do not select manually
	macosx: Platform variant, do not select manually
	no_web: Don't include any web server support
	apache: Add Apache 1 web server module
	apache2: Add Apache 2.2 web server module (default)
	fastcgi: Add FastCGI web server binary
	gmp: Add GNU MP functions
	dbase: Add dBase file format support
	imap: enable operation with IMAP protocol
	pspell: Add pspell spell-checking functions
	tidy: add Tidy support
	mssql: add support for MS-SQL server
	snmp: use Apple snmp
	macports_snmp: use MacPorts snmp
	mysql3: build MySQL 3 support
	mysql4: build MySQL 4 support
	mysql5: build MySQL 5 support
	oracle: Add Oracle oci8 database functions with the Oracle Instant Client
	postgresql82: provide postgresql82 support
	postgresql83: provide postgresql83 support
	sqlite: build sqlite support
	ipc: build IPC support
	pcntl: provide process control
	pear: add pear stuff
	readline: Add GNU readline functions
	sockets: Add socket communication functions
	t1lib: Add PostScript Type 1 font support with t1lib
	universal: Build for multiple architectures

I would go with just the basics.

$sudo port install php5 +apache2 +mysql5 +pear

With that done, now you can create your own copy of apaches httpd.conf

sudo cp /opt/local/apache2/conf/httpd.conf.sample /opt/local/apache2/conf/httpd.conf

Activate the php5 module.

cd /opt/local/apache2/modules
sudo /opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so
[activating module 'php5' in /opt/local/apache2/conf/httpd.conf]

and then you can play around with the config files as much as you like to set it up the way you prefer and then fire up the server using the following command:

apache2ctl start

and it should all work fine in your browsers. try out the config with the standard php testing function.

phpinfo();

Have fun, port is easy and simple, lets you get to the point where you can do something productive and creative.

Photo credit to my esteemed collegue: Neil Crosby.