LAMP in Leopard OSX 10.5 (PHP5 and Apache 2.2)

Following my how to setup your mac web development environment, and today moving to Leopard, my entire offline environment is broken – this is entirely due to the move from Apache 1.3 to Apache 2.2.

This article will discuss the changes required to get your multi-host mac dev environment running again with PHP5, MySQL, Apache 2 and Leopard.


Since we’re running Apache 2.2, it means a few files have new homes. Here’s a comparison:

/etc/httpd/httpd.conf => /etc/apache2/httpd.conf
/etc/httpd/users/ => /etc/httpd/users/

Get your virtual hosts back

Copy your .conf from your old httpd/users/ directory in to the new one (above). For example:

cp /etc/httpd/users/remy.conf /etc/apache2/users/remy.conf

If you restart apache (sudo apache restart) you should have the domains pointing to your sites.


PHP5 appears to come with Leopard (though I could be wrong, since I upgraded – please feel free to correct me). To re-enable it, within /etc/apache2/httpd.conf, around line 114 – you should find # LoadModule php5_module – uncomment this and restart apache.

Run a little PHP test, and you’ll find you’re running PHP again.


You have two options to get MySQL running again if you have the following error:

Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2)

  1. Reinstall PHP5 and compile it with the new path to the MySQL socket (/tmp/mysql.sock)
  2. Change MySQL’s conf to run the socket out of the old location

Since Leopard gave me PHP 5.2.4, which according to Entropy PHP, is the latest version for Apache 2.x, I went with option 2.

If you don’t already have the MySQL conf in /etc/my.cnf (I didn’t), then you need to copy a template out of the support files from MySQL. If you followed the instructions from my previous article – then you’ll need to run the following:

sudo cp /usr/local/mysql-standard-5.0.27-osx10.4-i686/support-files/my-small.cnf /etc/my.cnf

Replace small with whatever suits your setup best.

Now follow these steps:

1. Shutdown MySQL

mysqladmin -uroot shutdown

2. Change the conf

Change all occurrences of /tmp/mysql.sock to /var/mysql/mysql.sock

3. Create /var/mysql/

sudo mkdir /var/mysql
sudo chmod 777 /var/mysql

4. Start MySQL back up again

cd /usr/local/mysql/
sudo ./bin/safe_mysqld &

Wrap Up

That should be it. I’ve tried to document every change I made to get going again, but if you spot any mistakes or have trouble with these instructions let me know and I’ll try to help.

37 Responses to “LAMP in Leopard OSX 10.5 (PHP5 and Apache 2.2)”

  1. Great timing! Everything went smooth on my Leopard upgrade except for MySQL (and the lack of NetInfo Manager). This was the info I needed.

  2. [...] « LAMP in Leopard OSX 10.5 (PHP5 and Apache 2.2) [...]

  3. Thank you for posting this! Your notes where exactly what i needed to get my offline webdev setup back after a leopard install.

  4. [...] for backup (enter Richard) to get it back to normal. If you need help with this one, head over to Remy Sharp’s Blog for some [...]

  5. Great article, but the problem with Leopard’s PHP5 is that it comes with minimal modules support… like there’s no POSTGRESQL, which is the one that had me switching back to Tiger fro my pro machine.
    And Entropy’s PHP5 package does not work under Leopard, so I’m stuck.
    Any idea how I could get a PHP5 install with all the modules I need?

  6. @moose – I can’t say with certainty, but the way I would do it is to download the source for php and install the developer tools from the Leopard CD, and configure it to include the postgressql module.

    I’d give it a try myself, but I don’t have the developer tools install yet.

  7. Hi there,

    I had virtual hosts setup and working fine within the original /etc/httpd/httpd.conf in OS X Tiger.

    Now the /etc/Apache2/httpd.conf has the line;

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

    uncommenting this line and setting up virtual host containers in the /private/etc/apache2/extra/httpd-vhosts.conf file such as;

    ServerAdmin [email protected]
    DocumentRoot “/Users/sdalcorn/Sites”
    ErrorLog “/private/var/log/apache2/”
    CustomLog “/private/var/log/apache2/ common”

    seems to work – these domains no longer point at the main webserver directory. However the virtual servers are not working correctly.

    This would appear the easiest way to do it. But I must be missing something on the syntax or something.

    I have had Apache2 working before and I remember it being tedious. But once I got it working, it was just a matter of copying and pasting all the containers.

  8. @Remy – yeah I figured that out except I’ve never compiled anything and don’t really have time to play around at the moment, so I guess I’ll keep working in Tiger until someone comes up with a nice juicy binary .pkg, like an updated version of Liyanage’s installer…

  9. If it’s any help, here’s the lines from my remy.conf file which is now stored in /etc/apache2/users/

    <Directory "/Users/remy/Sites/">
        Options Indexes MultiViews
        AllowOverride all
        Order allow,deny
        Allow from all
    NameVirtualHost *:80
    <VirtualHost *:80>
        DocumentRoot /Users/remy/Sites/
        ErrorLog /Users/remy/Sites/
        CustomLog /Users/remy/Sites/ common

    I also have the following record in my /etc/hosts file:
  10. PHP5 should build from source on 10.5 as long as you have the developer tools installed.

    I needed PDO MySQL and started with the configure options which Apple used (copied from php -i). The openssl and iconv modules fail in non-obvious fashion and there’s still a bug in PHP 5.2.4 which causes the build to fail ( until you fix a few mistakes in the PHP source code.

    Once I got past that I was able to use the configure line below to install cleanly over the Apple-provided PHP5 – note that I’m using the MySQL 5 from MacPorts; you’d need to replace the /opt/local paths with /usr/local/mysql if you’re using the MySQL binaries.

    ./configure --prefix=/usr
  11. This will be helpful to some folks:
    Migrating MySQL 5.0.45 to Mac OS X 10 .5 Leopard

  12. Apple’s version of PHP5 misses out some key parts like gd. I guess I’m going to have to waste a few more hours of my time compiling it from scratch. Cocks.

  13. A thousand thanks …… my lord this was awesome. I wouldn’t have even attempted to upgrade my MacBook Pro before I saw this, and it sounded like I’d be ok…. and I was!

    10 minutes and my development environment is back to the way it was pre-leopard! W00t!

  14. [...] seguinte site é possível perceber como activar o ambiente xAMP no Leopard. Este outro site traz igualmente um método [...]

  15. [...] LAMP in Leipard OSX 10.5 (PHP5 and Apache2.2) [...]

  16. Thanks for the tips.

    I also had to make sure a few of my directories were executable (not just readable) by apache.

    I got MySQL working by explicitly setting the mysql.defaultsocket and mysqli.defaultsocket settings in php.ini.

  17. This is a great walkthrough. As a user trying to set this up for the FIRST time, however, some things can get confusing. For example, in your first tutorial, you have us create the log folder in /var/logs/httpd, but if at least /var/logs/ was there in Tiger, its not in my installation of Leopard. This much I got around. But I’m also getting permissions errors it appears in the Sites directory. Any file I put in there gives me 403 forbidden on every page. Do I need to add the Apache user to my user group?

  18. [...] LAMP in Leopard OSX 10.5 (PHP5 and Apache 2.2) setting up apache et al in os x leopard (tags: leopard osx apache mysql php) [...]

  19. @moose and others — I used Marc’s packages for years and they were great. But in the last 2 years I have gone completely with the Macports ( packages. The ui is simple and all though packages are install from source but are a breeze to install, configurable, easy to upgrade and downgrade, and there are so many other packages that can be installed in the same way that you can create all sorts of combinations that can be duplicated across many machines. Server admin work has never been so good (ok i am exaggerating a bit), and i will never look back.

    installing php5 once ports is installed can be as simpe as:

    port install php5

    Note that my macports installs even survived the upgrade from Tiger to Leopard. I also use it on many heavy production xserves.

  20. Alguém entendeu? Eu cheguei até esse post através de um outro que dizia que se vc não conseguisse instalar era pra vir aqui, seguir uns passos muito loucos, que tudo funcionaria. Resultado, não funcionou bosta nenhuma! Alguém sabe como fazer para reinstalar tudo (PHP+Mysql)?

    Valeu brazucas!

  21. After upgrading to Tiger and my apache setup got eaten I found that keeping out of the OS’s apache etc is the best solution.

    A friend on IRC suggested to me, MAMP.

    After playing for a couple of months I sprung the cash for MAMP Pro which provides virtuals etc GUI.

    But if you visit their forums, there is how-to’s on setting up virtuals without the pro.

  22. [...] The article LAMP in Leopard OSX 10.5 (PHP5 and Apache 2.2) [...]

  23. [...] opted to re-configure MySQL by following the instructions in the MySQL section of the blog post at [...]

  24. Thank you! Your explanations were perfect. I am now up and running once again thanks to you. I was stuck on the mysql.sock, but no longer!!!

  25. I need help. Running MacBook Pro Leopard and trying to get MySql working. Have the 64bit version. Keep getting “can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ I have been searching through all files and cannot find file with mysql.sock anywhere. Neither var or tmp have the mysql.sock files. Should there be? Havent done UNIX for ages or this level of manipulation.
    Did create a mysql folder in Var but what does the chmod to 777 do?

  26. Thanks a lot, was of gr8 hlp!

  27. I’m not sure you should chmod 777, rather just chown _mysql.


  28. Hey Guys,

    since my macbook is not working (for 1 year) and i´ve not the money for a new one I ´ve no actual information (espacially concerning OS X 10.5) but maybe the Tool mamp is worth the look.
    Works great brings a nice frontend and you have no stress about configuring.

    Greets from Germany

  29. Hey, you say ‘LAMP’ your lucky the os your talking about starts with an L.

  30. Entropy’s Leopard PHP Beta works just fine – in fact, I’m using it on my production servers at the office:

    Serious, running it on a 75+ website environment with mission critical websites; and the only reason I did it is because my developer friends at Apple admitted they were running it in production as well for their retail environment.

  31. hi – nice article on this. I had a similar article but was interested in PHP 5 and your method. Very clear explanation too. Love your jQuery stuff as well dude!

  32. Which conf file am I supposed to change while MySQL is shutdown and where can it be found?

  33. when i tried to access localhost/~min which is my username i got this message. How to solve it?


    You don’t have permission to access /~macbook on this server.

  34. Hey guys, i got around this problem by sending rather then ‘localhost’ to the thing that wanted to hook mysql up to (Joomla)

  35. ok i got it all wetup and running great. Now I’m trying to move my DocumentRoot to another partition at “/Volumes/files/localhost”. Is this possible? I just get a 403 when i change the DocumentRoot and locations. I did change it in my vhost also. whats wrong with my thinking?

  36. There is another, simpler solution to the problem with PHP looking for mysql.sock. In a terminal window, do the following:

    1) Create the /var/mysql directory: mkdir /var/mysql
    2) Change to the new directory: cd /var/mysql
    3) Create a symbolic link in the new directory that points to /tmp/mysql.sock: ln -s /tmp/mysqlsock $PWD/mysql.sock

    Voila! No messing with either the MySQL or PHP installation.

Leave a Reply
Not required

CODE: Please escape code and wrap in <pre><code>, doing so will automatically syntax highlight