January 05, 2006

Configuring apache for PHP

The next step I need is to get apache running on my machine. I need it for maintaining my website, not that I spend a lot of time maintaining this :)

I made a stupid mistake, I completely forgot that MAC OS X was based on FreeBSD. So, I installed apache and PHP via darwinports. Installation went great though!

sudo port -v install apache2
sudo port -v install php

In case you ever need to install them ;) I then struggled and suffered for a while until I realized that all I had to do was to enable the web server on my box, since it was already there!

The you'll have to update apache to run with PHP, if you need to do PHP stuff. Basically all you need to do is to remove the comments from the PHP parts of /etc/httpd/httpd.conf file.

You'll have to be super user to make this change so:
sudo emacs /etc/httpd/httpd.conf
Change emacs with your favorite editor, if you prefer.

The remove the comments from these lines:
LoadModule php4_module libexec/httpd/libphp4.so, and AddModule mod_php4.c

Usually you'll have to add the application types, but my file was born with the IfModule mod_php4.c section I didn't

Add the lines:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.html index.php

Now all you have to do a small PHP page to test your new PHP enabled web server.

The web server has two sets of sites enabled. These are available from the UI the first one is, the machines main website http://localhost present at the local path: /Library/WebServer/Documents/

The second one is http://localhost/~user/ present in your home directory under ~/Documents/Sites/

I never managed to get PHP enabled in my specific user space. Not that it matters much since I simply use the main website on the box anyway.

No comments: