Lion Upgrade Killed My PHP Website – and How I Fixed It

After installing Mac OS X Lion, I found the PHP site I use for development stopped working. I’d just get an empty webpage when I went to the website. It’s a WordPress site, using both PHP and MySQL. Lion ships with PHP 5.3.6, the latest production release of PHP.

In WordPress’s wp-config.php file, I set the WP_DEBUG constant to true to see what is going on:

define('WP_DEBUG', true);

It turns out WordPress / PHP could not connect to the MySQL database on my Mac running Lion:

Warning: mysql_connect() [function.mysql-connect]: [2002]
No such file or directory
(trying to connect via unix:///var/mysql/mysql.sock)
in /Users/taz/Sites/smartwebdeveloper/wp-includes/wp-db.php
on line 1036

I checked my Apache config. The Lion upgrade process left my Apache config alone, so my virtual host was still intact and working. It put a new httpd.conf.default in place in case I Apache wanted to use an more up to date Apache configuration. Happily it had left my configuration that enabled the PHP 5 module in place.

I remembered that Mac OS X Server’s MySQL install puts the socket for communicating with MySQL at /var/mysql/mysql.sock. The install of MySQL I’m using, from, in order to not conflict with Apple’s MySQL, puts the socket at /tmp/mysql.sock. I’d configured PHP back when I was using Snow Leopard to talk to the MySQL socket in /tmp.

I created a quick PHP file calling the phpinfo() function in my website’s home directory to check the PHP configuration:

<?php phpinfo();

I went to that webpage through the web and found, sure enough that all three PHP MySQL extensions – MySQL, MySQLi and PDO MySQL were all expecting the MySQL socket to be in /var/mysql.

I checked the PHP configuration directory /etc/php. The reason why PHP wasn’t working properly (i.e. connecting to MySQL) was OS X Lion install had moved my PHP configuration file – php.ini – out of the way:

tazair:smartwebdeveloper taz$ ls -l /etc/php*
-rw-r--r--  1 root  wheel  69302 20 Feb 00:42 /etc/php.ini-5.2-previous
-r--r--r--  1 root  wheel  69337 21 Jul 12:20 /etc/php.ini.default
-r--r--r--  1 root  wheel  69060 16 Dec  2010 /etc/php.ini.default-5.2-previous

Lion renamed my php.ini file to /etc/php.ini-5.2-previous, and put a new sample PHP configuration file, /etc/php.ini.default. It makes sense to do this: Lion uses PHP 5.3 which has new options and defaults, compared to PHP 5.2 used on Snow Leopard.

I copied the example PHP configuration into place:

sudo cp /etc/php.ini.default /etc/php.ini

I edited the new PHP configuration to update all references to /var/mysql/mysql.sock to /tmp/mysql.sock. Before editing php.ini:

tazair:~ taz$ grep .default_socket /etc/php.ini
mysql.default_socket = /var/mysql/mysql.sock
mysqli.default_socket = /var/mysql/mysql.sock

After editing php.ini:

tazair:~ taz$ grep .default_socket /etc/php.ini
mysql.default_socket = /tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock

I also enabled two of the three MySQL extensions, which were configured off in the default php.ini in the Lion install. WordPress perhaps only needed one of three MySQL extensions:

tazair:~ taz$ grep mysql /etc/php.ini|grep ext

I needed to restart Apache for it to pickup the new configuration:

tazair:~ taz$ sudo apachectl restart

Happy days! PHP could talk to MySQL, and my WordPress site was working on OSX Lion.

By the way, if you need mycrypt working with PHP on Lion, Michael Gracie‘s written an excellent post on how to do this.

If you have any questions or comments about the process above, please leave a comment. If this article helped you, please click the Tweet or +1 buttons. Thanks for visiting!

Tagged , , , , , . Bookmark the permalink.

68 Responses to Lion Upgrade Killed My PHP Website – and How I Fixed It

  1. Tony says:

    I am having the same problem you were. I got the mysql sock directory changed, but the big problem I’m having is that all of my old extensions were .so files and not .dll files. I can’t find any information about this difference except a lot of info on how .dll files are for Windows apache servers while .so files are for the rest of the world.

    Do you have any info you can share with me on how I get these .dll extensions?


    • taz says:

      Tony, PHP extensions are compiled code. The compiled code for extensions are typically loaded by at PHP at runtime when it finds the extension requested in php.ini.

      On Mac, Linux & Unix, runtime-loadable code ends with “.so“, standing for shared object. On Windows, runtime-loadable code ends “.dll“, standing for dynamically linked library.

      PHP extensions on Mac should always end with “.so“.

      The configuration lines you’re seeing in /etc/php.ini like ;extension=php_bz2.dll are just examples of enabling PHP extensions on Windows.

      Many of the extensions in the Windows examples are already enabled for PHP by Mac on default, for example bz2, curl, mbstring and mysql. These extensions have already been linked with PHP executable, so there are no separate “.so” files for them. You can use the phpinfo() function to show what extensions are preloaded for you on Lion.

      The default directory for PHP extensions on Lion and Snow Leopard is /usr/lib/php/extensions/no-debug-non-zts-20090626. I’ve got only two extensions available there: and It is also possible to include an extension from another directory by giving the full path to it.

      If you want to use a PHP extension on Mac:

      (1) Check if the extension is already included using phpinfo().

      (2) If it’s not included, check if you already have the extension’s “.so“, usually in /usr/lib/php/extensions/no-debug-non-zts-20090626. If you do, enable it in php.ini.

      (3) If you don’t have the extension’s “.so“, install the extension. The standard way to do this is with pecl, but I don’t think I’ve tried this on Mac.

      Hope this helps!

  2. John says:

    I can’t even get to this point! Any virtual host I create redirects me back to the built in OS X page no matter where I store the web files for the custom site. Did you run into this problem at all? I can find no references to it anywhere, so either I am missing something simple, or its a bug only I am getting.


    • Tasman Hayes says:


      Thanks for your question. You are not alone! I can remember having problems getting virtual hosts working on Mac a few years back and getting frustrated. From memory the solution was very simple. Unfortunately this was before I took detailed notes! :-)

      You’re probably having an Apache configuration issue. Virtual hosts work fine on Lion – I’m using them right now.

      First off, have you restarted Apache after configuring your virtual hosts in Apache? Apache won’t pickup your new configuration until you restart it.

      Next, in httpd.conf have you uncommented the line Include /private/etc/apache2/extra/httpd-vhosts.conf? To uncomment it, delete the “#” at the beginning of the line. Without uncommenting this line, Apache won’t read the virtual hosts configuration file.

      Finally, have you configured your virtual host by modifying the file /private/etc/apache2/extra/httpd-vhosts.conf? Apple provides a template file here.

      Let me know if this helps John. If you still have problems, I can post my config for you to try.

      • John says:

        I’ve been trying the above on os x lion server and have had no luck :/. Everything still resolves to the default site.

        Also tried the below comment and haven’t had much luck. I normally use XAMPP but would like to get away from it if I can get this in working mode!

        • Tasman Hayes says:


          If I go to, the localhost address – without any directory or username – my mac shows “It works!” in my browser.

          Does Lion do the same for you?

          If so, try editing /Library/WebServer/Documents/index.html.en to show something like “It works more!”

          Will it work that far for you?

          • John says:

            Hey thanks for the reply. I can get that far but I’m unable to get the other 6 virtual sites I’ve got on my localhost to work :/. Not sure what else to try.

          • John says:

            Actually I don’t get the ‘It works’ page… I get the default site lion sets up located in /Library/Server/Web/Data/Sites/Default.

          • John says:

            If I don’t use the “Server” app to start apache then it it sets my default directory to /var/empty and I get a 403 forbidden obviously. But, the other part of this is it won’t read my virtual hosts :/

            They created a mess with this.

    • MG says:

      I’ve run into this problem in the past, particularly when trying to use the user folder. Instead of banging my head, I simply swap out the contents of /Library/WebServer/Documents and edit my host file with the respective domain name. Easy to test with a file containing nothing but in it pointed from “http://localhost/” (which should be the only usable item left in said host file after upgrade).

  3. Alí Suárez says:

    It worked!!!


  4. gareth says:

    You just saved me an afternoon, thanks so much!

  5. Shane says:

    Thank you! I would not have figured this out on my own.

  6. Daaaaad says:

    Yeah… really cool !

  7. Tom says:


    I am not able to connect to mysql throughout terminal. Any ideas?

    • Tasman Hayes says:

      Hi Tom!

      I assume you’re using the mysql distribution from, not the mysql that comes with Lion server or the one installed using MacPorts or Fink.

      Do you get a command not found error like the one below?

      tazair:~ taz$ mysql
      -bash: mysql: command not found

      If so, to fix this, tell the shell (bash) where to find the MySQL executable:

      export PATH=$PATH:/usr/local/mysql/bin

      Is the problem that you can’t connect to MySQL?

      tazair:apache2 taz$ mysql
      ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

      If so, check if MySQL is running. Go to the MySQL Preference Pane in System Preferences and click Start MySQL Server to start MySQL.

      MySQL should now be able to connect and login to your local MySQL database on your Mac:

      tazair:~ taz$ mysql
      Welcome to the MySQL monitor. Commands end with ; or \g.

      Does this help you Tom?

  8. Tom says:

    Thanks for this, worked like a charm. I’ve come to expect some PHP+MySQL cleanup every time I upgrade. This time it was less painful than previous OS upgrades!

  9. Chris says:

    You are the man. Thank you!

  10. Tasman Hayes says:

    Best comment ever!

    Thank you Chris! :-)


  11. Eric Katz says:

    Thank you so much for this write up!

  12. thedaniel says:

    Html works but I can’t get php to work. I renamed the php.ini.default to php.ini and restarted the server, but this made no difference at all. Php still is not working.

    Everything worked great ‘out-of-the-box’ in Leopard. Is there a path difference between Leopard and Lion? Do I need to edit something in the php.ini, or maybe somewhere else?


    • Tasman Hayes says:

      Hi Daniel!

      A few questions so I can help you get PHP working on your Mac:

      • When you say PHP “doesn’t work”, what actually happens when you go to a PHP webpage?
      • What’s the path to your PHP files? e.g. /Users/taz/Sites/index.php
      • Have you edited / customised your Apache configuration at any stage? For example to create a virtual host.
      • Please run the command grep php5_module /etc/apache2/httpd.conf in the Terminal and paste the output into your reply.

      My gut feel is PHP probably isn’t enabled yet on your Mac running Lion.
      Even with Snow Leopard it was necessary to enable PHP.


  13. Erik says:

    Thank you so much. It would have taken me forever to remember this– saved me a night’s work.

  14. Nguyen says:

    Thanks so much! You save my life ^ ^

  15. Lee Button says:

    Great job! I’d been struggling with this for a day or so… great to come across all this great knowledge.

  16. Chris Bird says:

    Thanks very much for this. I upgraded to OS X Lion 10.7.2 so I could start using iCloud and your post saved me a lot of time and frustration. The Lion upgrade was much easier than going from Tiger to Leopard.

  17. Pingback: Lokaler Webserver ohne MAMP, XAMPP & Co unter Mac OS Lion » senäh

  18. Rene says:

    Was having this same problem with a WordPress install. But thanks so much for this step by step. Fixed my problem.

  19. Adam says:

    thanks. saved the day.

  20. Jarrad says:

    Im having a devil of a time…I installed mysql but I can’t access it from terminal and I can’t connect to it from phpmyadmin. Im running lion server.

    • Tasman Hayes says:


      What’s the actual error message you get in Terminal when you try running mysql?


      • Jarrad says:


        I get “-bash: mysql: command not found” when I type in any mysql command. I tried setting the export path but that only saves it for that terminal session.


        • Tasman Hayes says:


          It sounds like MySQL is installed, but you just need a way to persistently set the PATH to the mysql executable.

          One way to do this is to edit the .profile file in your home directory, which is executed by bash every time you open a new Terminal window. You can add your export PATH statement there.

          Alternatively, you can set the path systemwide by editing /etc/paths or putting a new file in the /etc/paths.d/ directory.

          If you need help finding the mysql executable, or want specific instructions for setting the path using one of the ways above, let me know. :-)


          • Jarrad says:

            Since there is an alias in /usr/local/ for mysql, does that really need done? Im not sure where mysql was installed on 10.6 but when I installed it on 10.7, it was installed to /usr/local/mysql-5.5.19-osx10.6-x86_64 with an alias of mysql placed in the /usr/local folder.



  21. Tasman Hayes says:


    Yes, setting the bash shell’s PATH is needed to run the mysql command.

    You may find /usr/local/bin is in your PATH by default, but mysql isn’t in that directory.

    You need to add the directory /usr/local/mysql/bin to your PATH.

    tazpro:~ taz$ mysql
    -bash: mysql: command not found
    tazpro:~ taz$ echo $PATH
    tazpro:~ taz$ export PATH=$PATH:/usr/local/mysql/bin
    tazpro:~ taz$ mysql
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 2
    Server version: 5.5.11 MySQL Community Server (GPL)
    Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    mysql> quit
    tazpro:~ taz$ 


  22. Raphael Soetan says:


    I’m having a different problem. I have php, html, mySql working. My problem has to do with having html in a .php file like;

    HTML with PHP

    My Example

    I get a blank page in Safari and a dump of the .php in FF. If I change the extension from .php to .html, it works. This was never a problem in the past on Leopard. I’m I missing a configuration setting?


    • Tasman Hayes says:


      It sounds like PHP hasn’t been enabled in Apache yet.

      To do this, edit the Apache configuration file, for example by typing the following command in the Terminal app:

      sudo pico /etc/apache2/httpd.conf

      Find the line containing:

      LoadModule php5_module

      This line probably starts with a hash “#” character, disabling PHP loading. Delete the hash character and save the file.

      The restart Apache:

      sudo apachectl restart

      You will need to enter your Mac user’s password here.

      That’s it! Apache should be enabled now.

      Let me know if you have any questions or problems Raphael. :-)


  23. Raphael Soetan says:

    This is the example I am referring to. I forgot to remove the html tags from the original. I have removed the “” pairs.

    title HTML with PHP /title
    h1 Example h1

    //your php code here


  24. 1Earth says:

    After the whole upgrading to Lion thing I gave this a 2 hour fiddle, but with my limited knowledge couldn’t figure it out. Today I tried again – tried to find the solution by googling, that is.

    Your problem was exactly the same as mine, so after following your instructions – happy days!

    Thank you for sharing

  25. Paul says:

    Thanks for this, I knew there was something with Lion and WordPress but could not find the solution until now!

  26. marek says:

    Hi, Thanks a lot for your tutorial. It has saved me a lot of time.

  27. Aether says:

    I’ve got some different error.
    I installed a new lion, and enable php module(it works) , and install an order verion mysql (5.5.2), it works too, I can access mysql via client tools, and also in shell.

    but php always told me like below:
    ERROR – 2012-03-04 18:01:32 –> Severity: Warning –> mysql_pconnect() [function.mysql-pconnect]: No such file or directory /Library/WebServer/Documents/system/database/drivers/mysql/mysql_driver.php 91
    ERROR – 2012-03-04 18:01:32 –> Unable to connect to the database

    please help me… thank you.

    I’ve tried cp php.ini.default to php.ini , but it make the whole site down(can’t start apache) ….

  28. Aether says:

    I’ve fix it, thank you all.

    sudo mkdir /var/mysql
    sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

    which makes php can find mysql…

  29. SirCameron says:

    Dude, you are the king! Thanks so much for this!

  30. John says:

    Just a little update: I’m on Snow Leopard but I came across this page in Google.

    I was trying to get this to work and was getting nowhere. Today, 3-25-2012, I downloaded: mysql-5.5.22-osx10.6-x86_64.dmg from the Mysql site.

    Notice the little one increment update of the version? Well, using this with a system that I had deleted the previous installed, (not the stock default version) of MySQL Community Server, then updating the php.ini to point to: /tmp/mysql.sock, restarting the server (I just used the preferences panel).

    “And there was much rejoicing….” ‘yay…’

    Thank you for pointing me in the right direction and I hope my info might help someone else.

    -John (Not the ‘John’ above :))

  31. Evan McDaniel says:

    Thanks for much for this. You saved me a bunch of heartache :)

  32. Sam says:

    Works like magic, thank you very much!

  33. Tessa says:

    Lifesaver! Thank you so much!

  34. Jung says:

    This might help someone. But if you are using the latest mac with osx 10.7.4, do NOT uncomment the MySQL extensions in the php.ini. It looks like MySQL and sqli is already compiled with php.

  35. Tushar Joshi says:

    Thanks a ton!
    You saved a lot of frustation and time for me. Thanks for spending time to write this blog and sharing your findings with all. I followed all the instructions and got my site back on Mac (Mountain Lion)

    with regards
    Tushar Joshi, Nagpur

  36. Yag says:

    Thanks; it helped out a lot and worked on first try

  37. simon says:

    You are a bloody genius, son – worked brilliantly.


Leave a Reply

Your email address will not be published. Required fields are marked *