0

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: http://developer.apple.com/mac/articles/internet/phpeasyway.html

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")
user_www=$HOME/Sites
filename=php-test
user_index=${user_www}/${filename}.php
user_db=${user_www}/${filename}-db.sqlite3
# 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'`
conf_old=$conf.$$
conf_new=/tmp/php_conf.new

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^[email protected]^<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

EOF

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 127.0.0.1...

(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
1
  • 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. Feb 16, 2010 at 7:55

4 Answers 4

0

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.

1
  • Thanks, Eric. I'll try that when I get home later today. Mar 29, 2010 at 10:40
0

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.

0

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 !

2
  • I would like to revert the changes I've made above though before I try another solution. Feb 15, 2010 at 20:34
  • MAMP is ok, definitely better than native, but has some headaches compared to a virtualised LAMP stack.
    – micmcg
    Feb 15, 2010 at 23:32
0

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.

http://kevin.vanzonneveld.net/techblog/article/how_virtualization_will_improve_your_code/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .