Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've recently purchased an Apple iMac. Unfortunately, enabling Apache and PHP has thrown up some problems.

I enabled Mac's built-in Web Sharing through System Preferences, at which point I got an output and could add HTML files to my user directory. However, PHP files were being displayed rather than interpreted. I then discovered this is because PHP isn't enabled by default on Mac's Apache set-up.

After a quick Google search, I came across this page:

I proceeded to the section, Enabling PHP in Apache, copying and pasting the following code snippet into a new Terminal window and hitting Return:

set admin_email to (do shell script "defaults read AddressBookMe ExistingEmailAddress")
# NOTE: Having a writeable database in your home directory can be a security risk!

conf=`apachectl -V | awk -F= '/SERVER_CONFIG/ {print \$2}'| sed 's/"//g'`

touch $user_db
chmod a+r $user_index
chmod a+w $user_db
chmod a+w $user_www

echo "Enabling PHP in $conf ..."
sed '/#LoadModule php5_module/s/#LoadModule/LoadModule/' $conf | sed
"s^^<b>\$admin_email</b>^" > $conf_new

echo "(Re)Starting Apache ..."
osascript <<EOF
do shell script "/bin/mv -f $conf $conf_old; /bin/mv $conf_new $conf;
/usr/sbin/apachectl restart" with administrator privileges


Unfortunately, this has completed thrown Apache and now nothing is being served; instead I'm receiving "Failed to open page" errors because it cannot connect to the server, despite Web Sharing still being active in System Preferences.

So therefore I guess my question is this: how can I undo the changes made by the copy-and-pasting of the above code snippet? Admittedly, I don't understand what the above did; I just thought it looked like a Terminal command and tried it. I have no experience in setting up Apache on Mac OS X (and I've only installed XAMPP and WampServer on Windows).

So any points on reversing the aforementioned, and then successfully enabling PHP would be great.

EDIT: I've discovered, via Console, the following error message is being recorded when trying to browse to

(org.apache.httpd) Throttling respawn: Will start in 10 seconds
no listening sockets available, shutting down
Unable to open logs
(org.apache.httpd[13453]) Exited with exit code: 1

Does this point any more to the issue?

EDIT #2: I'm now getting this in Console...

15/02/2010 21:24:14 osascript[3597] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types:  dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found.  Did find:
    /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper
share|improve this question
Well, I've installed MAMP. I didn't want to as it asks for my password every time I boot my Mac up, but at this point in time it's the only solution working, despite wanting to use Mac OS X's native version of Apache and PHP. – Martin Bean Feb 16 '10 at 7:55
up vote 0 down vote accepted

From the directions in the linked article (that look like they are for Snow Leopard Server) it looks like a backup copy of the config file was created.

Look in /etc/apache2/ for a httpd.conf.old file Copy that to /etc/apache2/ as httpd.conf

Go the easy route and just enable php inside of the config file.
- Remove the hash in front of the line: LoadModule php5_module

Restart apache and see how it's going from there.

share|improve this answer
Thanks, Eric. I'll try that when I get home later today. – Martin Bean Mar 29 '10 at 10:40
OMFG! It worked! Thank you so much! – Martin Bean Mar 29 '10 at 16:58

I would recommend using your Apache and PHP via MacPorts. It will take a bit of time to set it up, but it will easier to customize and maintain in the long run.

share|improve this answer

I guess this you machine won't be a production server. So if you don't want to argue with configuration and you can install MAMP. This is a "pre-made" webserver that includes Apache, PHP & MySql. It's a nice approach for a quick functional webserver, it should meet your requirements !

share|improve this answer
I would like to revert the changes I've made above though before I try another solution. – Martin Bean Feb 15 '10 at 20:34
MAMP is ok, definitely better than native, but has some headaches compared to a virtualised LAMP stack. – micmcg Feb 15 '10 at 23:32

I strongly recommend using virtualbox to set up a virtual production environment on your mac rather than butchering your desktop install to do it. Having tried setting up a native mac AMP stack, a MAMP installer and a virtualised LAMP stack, once you get the hang of it the virtualised LAMP stack is far and away the least headache. The other beauty is you can spin your development environment up and down just when you need it, and you can transport it easily between machines. This is a good guide for setting up a virtual ubuntu server on ubuntu desktop, its only a couple of tweaks to instead set up a virtual ubuntu server on OS X desktop.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.