Mac OS X Server 10.4: Issues connecting PHP to MySQL

When running MySQL and PHP on the same Mac OS X 10.4 server, you may find that PHP cannot connect to MySQL. When PHP is communicating with a MySQL server on the same host, it uses a socket file to communicate, and looks for it at /tmp/mysql.sock. On Mac OS X Server 10.4, MySQL creates this socket file at /var/mysql/mysql.sock.

This article has been archived and is no longer updated by Apple.

To resolve this issue, you can either change the location where MySQL creates its socket file, or modify the location where PHP looks for the file. Please note that the first option is less secure than the second. Before delving in, you should also review new information relevant to PHP and MySQL on Mac OS X Server 10.4.4 and later.

To change the location where MySQL creates its socket file, do this:

  1. Open your preferred text editor and create a plain text file.
  2. Type this text (on two lines as shown):


  3. Save the file as: /etc/my.cnf

To change the location where PHP looks for the socket file, follow these steps:

  1. In Terminal: sudo cp /etc/php.ini.default /etc/php.ini
  2. Open /etc/php.ini in your preferred text editor.
  3. Find the [MySQL] section, and change the mysql.default_socket directive:
         ; Default socket name for local MySQL connects.  If empty, uses  
    the built-in
         ; MySQL defaults.
         mysql.default_socket = /var/mysql/mysql.sock
  4. Change the permissions on /var/mysql so that www can read the socket, by executing this in Terminal:

    sudo chmod 775 /var/mysql
Last Modified:

Additional Product Support Information

Start a Discussion

in Apple Support Communities
See all questions on this article See all questions I have asked
United States (English)