SiteCrafting Blah Blah Blog

Oct. 26, 2007 at 2:05pm

Apache, MySQL, and PHP on Leopard (Mac OS 10.5)

I just finished installing Leopard on my computer, and my first impressions are that it's very slick and well thought out. One of my necessities as a developer is that I must have a webserver running on my personal computer, so I was dismayed when it wasn't functional after the upgrade. The main reason is that Leopard uses a different version of Apache than 10.4 did, and so some things get wonky. But it's easy to fix. Apache and PHP are included in Leopard, so the only thing missing is MySQL. To install that, go to MySQL's site, and download the latest copy for OS X. It's incredibly simple to install.

After that comes setting up Apache. Open up a terminal window, and type in "sudo pico /etc/apache2/httpd.conf". (Note that you must be a computer administrator to access the files in etc/) OS X 10.4 had Apache in /etc/httpd/, and that's part of why it didn't work after the upgrade. Find the line in httpd.conf that looks like "#LoadModule php5_module        libexec/apache2/libphp5.so", and remove the # sign at the beginning. Then search for AddType, and put the following somewhere around it.

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

Save the file, and exit. Then open up System Preferences in Finder, and click on Sharing. Then turn on Web Sharing. That's all you need do to to setup a webserver on Leopard, or upgrade from OS 10.4. You should be able to open up a browser, and enter http://localhost/YOUR_USERNAME/ and see that the server is running.

Posted in MySQL, PHP by Dave Poole

Comments (30)

JFYI:

It's not necessary to AddType on Leopard as it's build-in.

Check the last line of httpd.conf

Include /private/etc/apache2/other/*.conf


1 | Left by chenggn | Oct. 26, 2007 at 4:15pm


Thanks! Very useful. I take it you did a fresh install, as I have just done an upgrade and MySQL is still installed (although I can't quite figure out if it's working properly yet...)
2 | Left by MakTheYak | Oct. 26, 2007 at 4:27pm


I don't think it is. It refuses to shut down in the System Preferences panel, and my (working) PHP installation can't talk to the server. Wasn't there something to do with the socket (changing the location) to get it to work way back when?
3 | Left by Stephen | Oct. 26, 2007 at 6:51pm


This guy seems to be on to something ...

http://forums.macrumors.com/showpost.php?p=4394679&postcount=8
4 | Left by Stephen | Oct. 26, 2007 at 7:19pm


I just upgraded yesterday and I've been trying to get my local instance working again, but I'm still having trouble. I tried the suggestions here, but I'm still getting a 403 when accessing my user sites. I can get to the root of my localhost and see that apache is running. I've tried granting permissions on my Sites directory, but still nothing. Any ideas??? TIA!
5 | Left by Heather | Oct. 27, 2007 at 7:03am


@ Heather

I am having the same problem. Leopard has knocked out all my virtual hosts and stopped be viewing my own homepage.
6 | Left by James@Hakoona | Oct. 27, 2007 at 8:56am


i'm having the same problem as heather and james. finder crashes when i try to grant permissions -- had to do a chmod in terminal. still the 403 though.

you can add the vhosts in /private/etc/apache2/extra/httpd-vhosts.conf but that doesn't help with the 403.
7 | Left by Josh | Oct. 27, 2007 at 9:30am


Nevermind. Got it fixed. I don't understand why this worked but it did:
> went into /private/etc/apache2/httpd.conf
> made the changes indicated in the post above
> changed DocumentRoot on line 163 to "/Users/josh/Sites"
> changed the Directory on line 190 to same
> changed AllowOverride on line 210 to All
> saved, restarted Web Sharing
8 | Left by Josh | Oct. 27, 2007 at 9:37am


It seems that Leopard has screwed up the permissions and it is creating and 'Unknown' user, which is causing problems.

I came across this fix at Apple Discussions, you do not need to change permissions, just create a new file in the apache2/users folder

http://discussions.apple.com/thread.jspa?threadID=1187457&tstart=15

It also details the settings required to get virtual hosts working again. Hope this helps
9 | Left by James @ Hakoona | Oct. 27, 2007 at 9:50am


Thanks Josh!! That worked for me too!!
10 | Left by Heather | Oct. 27, 2007 at 9:50am


I noticed that MySQL now only presents tar packages for Mac OS X. Does anybody know whether this is permanent. Are the .dmg downloads gone forever ?
11 | Left by Anon | Oct. 27, 2007 at 12:43pm


Changing the Apache DocumentRoot should not fix the user vhosts, rather change the default root to a specific users directory.

So....
http://localhost/
should display the same thing as ...
http://localhost/~josh/

So this should not really solve the problem, just work around it. Can you confirm this?
12 | Left by JP | Oct. 27, 2007 at 12:44pm


I've got a problem with virtual hosts in leopard:
In 10.4 I had to add a host entry in netinfo manager but this app isn't available in leopard anymore.
Just adding mywebsite.local in the httpd-vhosts.conf and pointing in to a folder eg /www/mywebsite/ doesn't work...

Anyone who can help?
13 | Left by orchid | Oct. 27, 2007 at 12:45pm


MySQL and Leopard don't play nice yet. A Bug has been reported:
http://bugs.mysql.com/bug.php?id=31889
14 | Left by JP | Oct. 27, 2007 at 12:51pm


@anon, i see PKG format mysql here: http://dev.mysql.com/downloads/mysql/5.0.html#macosx-dmg

@orchid, you need to edit your /private/etc/hosts file now that netinfo manager is gone.
15 | Left by Josh | Oct. 27, 2007 at 3:14pm


Dave says:

@chenggn - After I upgraded, Apache was still serving .php as text/plain, which is why the AddType is necessary. I didn't check the other .conf files, but if that works too, great!

@MakTheYak - Great name. I actually upgraded my install, and MySQL was still installed as well. I wanted to mention it here to help everyone.

@Stephen - I'm guessing that there's something else causing your error. If it doesn't work, try restarting Apache. Type "sudo /usr/sbin/apachectl restart" at the command prompt. Also, there's a configuration issue with the default MySQL install that stops connecting to named servers. If you get the sock error, try connecting with an ip address.

@Josh - Thanks for sharing how you fixed it. I'm sure that someone else will need that as well.


16 | Oct. 27, 2007 at 3:16pm


Josh what you did is re-target the server for your machine, so I suspect that something like 127.0.0.1/~josh still does not work.
I updated an existing system, and It seems that the installer does not create/copy the necessary files for users. You may find user files in:
/private/etc/httpd/users/
Copy your user file to:
/private/etc/apache2/users/
and restart web sharing.
17 | Left by dragonfly | Oct. 27, 2007 at 3:16pm


Dave says:

@JP - Thanks for the link. I hope it gets resolved quickly. In the meantime, running mysql from the command line seems to be the solution. (See the comments on the linked page.)
18 | Oct. 27, 2007 at 3:30pm


@orchid - just add a line to /etc/hosts in the format:
127.0.0.1 mywebsite
Then clear the cache:
sudo dscacheutil -flushcache

19 | Left by mrwalker | Oct. 27, 2007 at 5:24pm


How to fix the MySQL System Preference Control:

Running a chmod -R 777 on the whole mysql folder fixes the system preference control.. so the problems seems to
be with some permissions.. running this probably isn't recommended though for production
environments..

20 | Left by William | Oct. 27, 2007 at 7:50pm


The main problem happening with the 403 Forbidden messages is that the new Apache httpd.conf file defaults to 'Deny from all' instead of 'Allow from all'. If you change the line in the httpd.conf or override it in your custom conf file that should take care of the error messages. You shouldn't have to change directory or file permissions.

I ran into the same problem so I posted about it: http://www.aldenta.com/2007/10/28/getting-apache-php-to-work-with-leopard-os-x-105/

21 | Left by John Ford | Oct. 27, 2007 at 10:15pm


This worked fine for me, but it occurred to me that some people may have problems if web sharing is already turned on and they forget to turn it off and back on again.
22 | Left by Joel Falconer | Oct. 28, 2007 at 5:54pm


I have the solution for the 403 errors...

Create a file called .conf, where is your short user name.

The file should contain the following:

#
# Allow access to the users Sites directory for web clients.
#

Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all


I used my short user name here. Naturally, your config file will contain your short user name.

Restart Personal Web Sharing after adding the file and you should be good to go.
23 | Left by JP | Oct. 28, 2007 at 7:58pm


Sorry. The tags got striped out of the previous comment. Go here for the answer to you 403 problems..

http://forums.macosxhints.com/showthread.php?p=418528
24 | Left by JP | Oct. 28, 2007 at 8:02pm


If you're doing development work (not production) you could just run MAMP, which is easy to install and is totally self contained:
http://www.mamp.info/
25 | Left by Jordan314 | Oct. 29, 2007 at 2:58pm


I'm running into what is most likely a show stopper to using the Apple version of Apache and PHP - compatibility with postgreSQL. I need to use postgres at work - it is a hard requirement for me. Postgres support is built into php as a configure flag during install - is there a way to re-build the apple php to include the postgres flag?
26 | Left by Nick | Oct. 30, 2007 at 10:32am


Migrating MySQL 5.0.45 to Mac OS X 10.5 Leopard
http://blog.tomatocheese.com/archives/2007/11/1/migrating_mysql_to_mac_os_x_leopard/
27 | Left by Joannou Ng | Nov. 1, 2007 at 4:14pm


I did a fresh install of Leopard. Is it possible yet to do a fresh install of MySQL? If so, can anyone point me out how to do this?
Thanks in advance!
28 | Left by TriangleJuice | Nov. 5, 2007 at 3:20am


I've resolved the "403 problem" just changing the /Users/myuser permission from 750 to 751.


29 | Left by Giovanni | Nov. 10, 2007 at 4:03pm


Thanks a lot! This was easy and *very* helpful.
30 | Left by Aditi | Feb. 16, 2008 at 2:21pm


Remember me
Name: Email: URL: Comment: *   No HTML, http:// will auto-link
* required    Comment Guidelines