Snow Leopard Development Server: PHP 5.3

With the database and web server in place, I can turn my attention to PHP 5, my tool of choice for web development. MacPorts recently made this a much cleaner process. In the past, you needed to search for ports and variants (and hope that the key variants you needed were available). Now, installation is modular. As always, update MacPorts itself before proceeding with any installation.

sudo port -d selfupdate
sudo port install php5-postgresql
cd /opt/local/apache2/modules
sudo /opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so

Finally, a slight change is needed to ensure that Apache 2 recognizes PHP files by uncommenting the following line near the bottom of /opt/local/apache2/conf/httpd.conf (comment added).

Partial Listing: /opt/local/apache2/conf/httpd.conf

# PHP Types
Include conf/extras-conf/*

PHP Configuration

The MacPorts installation includes a couple flavors of the PHP configuration file; by default, the development version is used. In a later article where I show how to properly install and configure a production server, I will delve more into the key componentos the PHP 5 configuration file: /opt/local/etc/php.ini.

PHP Debugging with XDebug

Since the process of debugging PHP through its included tools is generally an exercise in well-placed print_r() or var_dump statements, there is one freely-available extension to PHP that I find indispensible: xdebug.

sudo port install php5-xdebug

With all the configuration changes in place, and xdebug installed, Apache2 can be restarted and application development can commence.

sudo /opt/local/apache2/bin/apachectl restart