Apache PHP and Mysql on Leopard

Leopard brings one big change to web developers working with Apache, PHP and Mysql on the Mac. Apache 2 comes with Leopard along with PHP 5.

Here is what to do to restore a test environment.

First, you need to enable PHP.

Apache’s .conf file moved from /private/etc/httpd/httpd.conf to /private/etc/apache2/httpd.conf

Open this file with your favorite text editor and uncomment the line:

# LoadModule php5_module libexec/apache2/libphp5.so

You don’t need to add the mime type for php, because it’s already done for you under leopard. The last line in the .conf file is:

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

The ‘other’ directory contains a .conf file for php5. That takes care of the mime type and the index.php configuration for php sites.

If you develop multiple sites and you need virtual hosting functionality, scroll down to the end of the .conf file and uncomment the following:

# Include /private/etc/apache2/extra/httpd-vhosts.conf

That’s all the modification that I had to make to to the httpd.conf file.

Next, you’ll need to setup whatever virtual hosts you have in the virtual hosts file /private/etc/apache2/extra/httpd-vhosts.conf

For example, for each line that you set up in your hosts file like so:


You need to make an entry in the httpd-vhosts.conf file like so:

<VirtualHost *:80>
   ServerName beta-site-1.com
   ServerAlias www.beta-site-1.com
   ServerAdmin webmaster@beta-site-1.com

   DocumentRoot "/Library/WebServer/beta-site-1"
   ScriptAlias /cgi-bin/ "/Library/WebServer/beta-site-1/cgi-bin"
   <Directory "/Library/WebServer/beta-site-1">
     Options FollowSymLinks MultiViews Includes
     AllowOverride All
     Order allow,deny
     Allow from all

One good thing is that the ‘upgrade’ install of Leopard does not mess with your hosts file, so whatever virtual domains you may have set up won’t be affected.

If you had Mysql installed previously, good news too, Leopard’s installer won’t touch it. I found mysqld running just like before the upgrade.

One thing changed with Leopard is the socket for Mysql. It moved to /private/tmp, so you may need to configure your php.ini file to point it to the new location.

To do so, open the file ‘/private/etc/php.ini‘, (if no such file exists, then make a copy of ‘/private/etc/php.ini.default‘ naming it ‘php.ini‘) and edit that.

You have two lines to modify:

mysql.default_socket =


mysql.default_socket = /private/tmp/mysql.sock

and mysqli.default_socket =


mysqli.default_socket = /private/tmp/mysql.sock

of course, from the sharing pref pane, stop the server and restart it and voila!

93 thoughts on “Apache PHP and Mysql on Leopard”

  1. That’s an odd one.

    Can you access the index.php file from the machine serving it?

    If PHP wasn’t working, you would have received the source code for the ‘index.php’ file. Getting an error message means that there was an error while processing the page and PHP produced garbage.

    try the following command in the Terminal (/Applications/Utilities/Terminal.app):

    curl -I “”

    and see what the output is.

    You can also try:

    curl -G “”

    That bypasses any interference from the browser and shows you exactly what the server is producing.

  2. Thanks.

    Somehow in trying to hack my way through this my mysql installation degenerated into a steaming pile of worthlessness. I am cleaning up the mess and starting over.

    My theory now is the mysql and php installation was working fine, and that the issue was the way wordpress was handling the php calls.

  3. It blows me away that apple hasn’t got their stuff together. It’s all about Apache, mysql and this does not come working by default. Even installing mysql…there’s nothing about adding these two lines of code anywhere in the installs or on apple.com…ludicrous!

  4. Does anyone have a definitive, step-by-step solution to setting up a PHP, MySQL development environment in Dreamweaver CS3 on Leopard.

    I was so proud of myself for setting this up in Tiger… only to upgrade to Leopard and find out that I had to start all over.

    I second John Wry’s comment above. It is ABSURD that this is not easily turned on. Why not just have a System Pref area where you turn these things on and off with the click of a button? Or at least have an application that permits the easy activation and/or addition of various development tools.

    I am just starting as a PHP/MySQL developer, but it sure seems like I need to be an advanced developer just to get things set up! Not the kind of Catch 22 I would expect from Apple.

    Again, if any one can point me to a comprehensive, step-by-step tutorial-one that puts together many of the trials and errors that appear to have been revealed in the posts above– I would be most grateful.

  5. Does anybody know help me how to start mysql in leopard???Ive tryed evrithing is mention here but no luck.Ive instoled mysql and add icon to system preferences and try to start up manulay by pressing button…but no luck….in terminal getting massage permition denied…???any help please :-)

  6. It could be permission problem with mysql’s ‘data’ directory.

    The default installation of mysql is at /usr/local/mysql

    there should be a folder/directory called ‘data’ inside mysql’s folder.

    Check its owner and group, they should be _mysql (note the underscore) and wheel.

    if they’re not, then you need to fix those permissions. You can do that with the terminal; just type:

    sudo chown -R _mysql:wheel /usr/local/mysql/data

    it will ask you for your admin password, just supply it and that should fix the problem. If it doesn’t, then I don’t know what the problem could be.

  7. thanx for replaying back…unfortunatly your advice is not fixing problem :-(…if I go to data folder as u recomended that folder is lock for access have a one way sign on it (dont know how to access) and when i put that text code it to terminal nothing is happening…just asked for password …after typing password is just repeat text line name of mac and name of user…any other sugestion???

  8. nothing is supposed to ‘happen’ when you enter your password after that line. It should simply give you the prompt.

    But, after it, if you restart, mysqld should be running.

  9. no i did restarted but no luck…BTW how do I know is running???it should show in system preference or sould i check in terminal?Cos in system preference is showing stopped

  10. Try ‘Activity Monitor’ in the /Applications/Utilities/ folder. Launch it and simply type ‘mysql’ without the quotes into the filter field (top right).

  11. Ok thenx …
    Ive sold this problem for those who has same problem just type in terminal;

    sudo /usr/local/mysql/support-files/mysql.server start

    and that will start mysql right ON…:-))

    all the best to all

  12. MAMP is worth a look – installs mySQL, PHP and Apache2 on a User account and does not touch your original OSX configuration.

  13. I’m new to programming. I’ve searched my mac up and down for these files but can’t seem to find them. I’m running Leopard on my Mac.

    Can you please explain where are these files located? Also, are these instructions for the client side or host side? As I’m interested on the client end.

    Thank you.

  14. You can’t use Spotlight to find the files mentioned in the article. They’re in the invisible folders of Mac OS X.

    You need to use the terminal for these kind of things. If you’re familiar with Terminal and its use, then the above should have been enough for you to get started.

    If you’re not familiar with the terminal and the intricacies of the Unix side of OS X, then you may be more comfortable with a package like ‘MAMP’.


    This package allows you to install all the needed software easily and use your Mac as a PHP development platform.

  15. Thanks again for this. Used it more than once as reference. Just had to use it again after a software update changed php.ini settings for the mysql.sock file. oh well.

  16. Thanks so much. I just tried to use my local development setup for the first time since upgrading to leopard and it was broken. Your instruction were so clear and it only took a few minutes to fix. I’m very grateful!

  17. Last night, I tried installing mySql, ver. 10.5 (5.0.51a (x86), on my MacBook Pro (unsuccessfully).

    Prior to installing mySql, I enabled php as per the instructions on the top of the page. I then followed the advise about creating a php.ini copy and setting:

    mysql.default_socket = /private/tmp/mysql.sock
    mysqli.default_socket = /private/tmp/mysql.sock

    Next, I installed mySql, however, I cannot seem to start mySql or set the password (as per post no. 7) as follows:

    /usr/local/mysql/bin/mysqladmin -u root password

    Can anyone help a poor sap like me out? Also, what directory is mySql installed to?

    Thanks so much in advance!


  18. Hi Dipesh. Got a MBP too running OS X 10.5.2 and the same problem as well. Here’s the solution in four simple steps:

    1.- download this
    and replace the PefPane.

    2.- Go to the Finder, press Command-Shift-G and type this:
    A window will open

    3.- Find and copy the MySQLCOM directory to Library/StartupItems/. If you get any error, simply copy the MySQLCOM folder to our desktop and then to the StartupItems folder. You will have to enter your administrator pasword to allow the MySQLCOM folder to be copied onto the StsrtupItems folder. Don’t worry, this is OK.

    4.- Restart your Mac and enjoy MySQL.

  19. Hello

    I just edited the conf file, but when i try a php test page with , but when I open it, i just see that code…



  20. Hey i changed the files as you said, (.conf file and the file to create virtual hosts). But wondering now how do i set this up to dreamweaver so i can use that to edit my pages and just connect to my site?

    any help would be appreciated

    thanks in advance

  21. Let me join in the chorus of THANK YOUs. I’ve been to so many places that say ‘just download this file and double-click and voila! you are running php & apache.’ but after lots of frustration, php and apache still were not talking. Your instructions were clear and simple and they work. For the first time, running the phpinfo() command actually returned a response. Many many thanks!!

  22. Adding my thanks, especially for the MySQL socket as I hadn’t seen that part elsewhere and was baffled!

    One hint if the virtual hosts aren’t working – in my old httpd.conf file I had just used * for the port instead of *:80. When I changed the port # in the entries it worked:

    [VirtualHost *:80]
    ServerName my.virtual.site
    DocumentRoot “/some/other/path”

    Also originally I did not have the DocumentRoot value in double quotes but adding the quotes did not make things work any better.

  23. Brilliant, absolutely phenomenal. A Wizard with enough knowledge to make it a one shot for the transition to Leopard from Jaguar!
    Thanks, and cheers aplenty!

  24. I have problem making php up and running.

    I tried the command “curl -I “http://localhost/~macbookpro/info.php”

    I get this results:
    HTTP/1.1 200 OK
    Date: Sat, 28 Jun 2008 12:56:15 GMT
    Server: Apache/2.2.8 (Unix) mod_ssl/2.2.8 OpenSSL/0.9.7l DAV/2 PHP/5.2.5 Phusion_Passenger/2.0.1
    X-Powered-By: PHP/5.2.5
    Content-Type: text/html

    But, if i run “curl -G “http://localhost/~macbookpro/info.php”

    I get this:

    Parse error: syntax error, unexpected ‘?’ in /Users/macbookpro/Sites/info.php on line 1

    Anyone can help me? Thank you.

  25. why are two lines the same?

    mysql.default_socket =


    mysql.default_socket = /private/tmp/mysql.sock

    and mysqli.default_socket =


    mysqli.default_socket = /private/tmp/mysql.sock

    of course, from the sharing pref pane, stop the server and restart it and voila!

  26. ; MySQL defaults.
    mysqli.default_socket =

    ; Default host for mysql_connect() (doesn’t apply in safe mode).
    mysqli.default_host =

    ; Default user for mysql_connect() (doesn’t apply in safe mode).
    mysqli.default_user =

    How do I configure it?

  27. Your post lives on! I wracked my head for 2 days reading everything on this and finally found your post.

    I had set up the Virtual Host, and permissions were fine, but still had a forbidden problem until I nested the in the httpd-vhosts.conf

    Yeah – I’m virtually dancing – pun intended.

  28. running G4 powerbook leopard 10.5 6 client
    cannot get apache default page
    error cannot find server

    edited http.conf for php
    tried most of the above still cannot get default page to appear

  29. I wonder.. like when i say //localhost bla bla. this apache thing pops up. and that made me wonder. like when I do //localhost~(username) all I have in the folder “sites” will pop up, and I wonder if I can change the //localhost “start up thingy” when it just sais Apache is Fully installed on this computer. blabla. U probably Don’t understand but I hope someone would Answer me As soon as possible, im really curious 😛

  30. THANK YOU for this post! I was stuck on the socket thing for a while and wouldn’t have figured it out if I didn’t find this.

  31. I’m sort of a newbie with php in general and on Leopard (10.5.7) in particular. Only got my Macbook Pro last month. If not for this post I would have still have been flailing away at windmills.

    There seems to be a difference from the version of Leopard/php5 that you describe to what I have. The reference to the php5.conf file in /private/etc/apache2/other/ was nowhere to be found in my httpd.conf file. I had to add the include at the bottom of the includes myself. I then restarted apache, flushed the Safari buffer/cache, and finally I got to work instead of just showing the source code.

    My sincere thanks!

Comments are closed.