Macports: How to configure php5 for apache2

I guess I am spoiled with Redhat’s integration of all these packages where you simply install and away you go. Macports isn’t quite a polite in this regard. The default config files are incomplete and not enabled when it is installed.

So I have had to do some massaging to get php working.

The file /opt/local/apache2/conf/extra/mod_php.conf is missing some configuration parameters. I’ve changed mine to look like this:

<IfModule mod_php5.c>

AddType  application/x-httpd-php         .php
AddType  application/x-httpd-php-source  .phps

AddHandler php5-script .php
AddType text/html .php

DirectoryIndex index.php


I specifically had to add the handler and also load the module. Then in the /opt/local/apache2/conf/httpd.conf file, I had to add the line: Include conf/extra/mod_php.conf as there wasn’t even a commented out line that would include this module.  Also in the /opt/local/apache2/conf/httpd.conf file, also need to add the line LoadModule php5_module modules/ so that the php library is loaded into Apache.

A graceful on the server:

sudo /opt/local/apache2/bin/apachtctl graceful

and away we went.



Turns out that a message is printed at completion of the install, which was not apparent to me because I used a GUI to do the installation. The message states:

If this is your first install, you need to activate PHP in your web server.

To enable PHP in Apache, run
cd /opt/local/apache2/modules
/opt/local/apache2/bin/apxs -a -e -n “php5”

A useful tip I highlighted in a previous post helps to find this sort of information after installation.  This command simply adds a LoadModule option to the main httpd.conf file, but does not add the other configuration options above.  So you still need to make the above changes.

2 thoughts on “Macports: How to configure php5 for apache2

Add yours

  1. Good to see that the educational developers are focusing on learning and teaching issues. 😉

    I’m sure if you worked in IT and were using the MOE, you wouldn’t be having these problems.

    1. I seem to remember a former colleague banging out PHP code (BIM) in the name of learning & teaching not so long ago. I assume you had to make Apache & PHP play nice to achieve that. 😉

      Sure, there would be no problems with a “managed” operating environments because they are so flexible. 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at

Up ↑

%d bloggers like this: