Running PHP on Apache on OSX
I've barely touched PHP. I've worked with ASP on a smattering of projects and worked with a handful or proprietary technologies, but PHP largely passed me by.
The only reason I turned to it was on a recent hack day project. I wanted to get something up and running, quick and dirty. I found something on t'interweb that did what I wanted. It was written in PHP.
Setting up PHP to run on Mac OSX for my demo was surprisingly easy once I'd found the relevant stuff. The googling took longer than the actual task of getting PHP running.
1. You'll need Apache to be running.
Apache is installed in Mac OSX by default, to enable it, go;
System Preferences > Sharing > Services
Now check the box labelled "Personal Web Sharing"
Now just throw your HTML docs into the ”username/sites” directory and it’s running on the server.
Check this in a browser by going to http://localhost/~username/
("username" is the name of your Mac - if you open a finder window it's the text next to the house icon in the left column)
2. Enabling PHP5 (on Leopard)
PHP5 comes bundled with Leopard too, it's just disabled by default.
To enable it, in /etc/apache2/httpd.conf, around line 114 - you should find
#LoadModule php5_module
The hash character means the line is commented out. Remove the hash, save the file, restart apache (just uncheck and re-check the aforementioned 'web sharing' checkbox) and you're away...
A note on editing the http.conf file
You may have a problem with the httpd.conf file being a read only file. I edited it using VI in the Terminal window. prefixing the VI command with the super-do instruction.
Launch your terminal window.Switch to the right dir:
cd /etc/apache2
Edit the httpd.conf file in VI:
sudo vi httpd.conf
Get your cursor to the right line and enter the "insert" mode by hitting the i key.
Delete the hash char.
Exit insert mode by hitting the Esc key.
Now save and quit by entering the command:
:wq
PHP4 on OSX Tiger
If you're running an older version of OSX you may have older versions of Apache/PHP pre-installed.
For Apache 1.3 the httpd.conf file is in a different folder (/etc/httpd/httpd.conf) and there's 2 lines you need to uncomment in the httpd.conf file:
#LoadModule php4_module
#AddModule mod_php4.c
Latest Posts
iPhone App: Flick Cricket
10:15a.m., 4 Sep
Cricket seems like a ridiculous sport to me. I like hitting the ball - hitting a ball as hard as ...Javascript from the wonderful world of online advertising
8:23p.m., 1 Sep
I had a right old rant about the quality of javascript that you find being served by major providers of ...Web performance - Analysing Heart.co.uk
5:17p.m., 26 Aug
A few weeks back I, together with m'colleague Jon Topper, delivered a presentation about the performance of heart.co.uk to the ...Installing MySQL and MySQLdb on OSX
10:19a.m., 19 Aug
I've just set up my dev environment for Django. Again. This is the fourth time I've had to do it. ...