Mac OS X Server 10.6 and php 5.3 and MySQL
Mac OS X Server 10.6 Snow Leopard (SL) Server provides php 5.3 and updates to the MySQL database and Apache; specifically, Apache 2.2.11, php 5.3.0, and MySQL 5.0.5-dev. Unfortunately for local purposes, the defaults for php and MySQL and Mac OS X SL don't all exactly line up with the expectations of MySQL, and some configuration file changes can be required to get php-based database applications and database connections to function.
The usual error for this sequence is similar to the following:
mysql_connect : No such file or directory Error code :2002 Error connecting to mysql
To resolve this, launch Server Admin tool and stop the Apache web server, launch Terminal.app from an administrator account, and navigate to the /etc directory, and edit the php.ini file using pico or your preferred text editor.
cd /etc sudo pico php.ini
And then find the entries for mysql.default_socket and mysqli.default_socket and change them to look like this:
mysql.default_socket = /var/mysql/mysql.sock mysqli.default_socket = /var/mysql/mysql.sock
php 5.3 and deprecated features
A second change within php 5.3 to deprecate various php features can cause errors within Drupal and other php applications (errors akin to Function ereg() is deprecated), and these reports can be masked (though not resolved) by removing the deprecated flag from the php error_reporting setting:
error_reporting = E_ALL & ~E_DEPRECATED
This in your /etc/php.ini file, using pico or vim or emacs or your preferred text editor; via the sudo pico /etc/php.ini command. Alternatively, you can also replace the php call with an analog; to remove the deprecated feature. In the case of Drupal cited earlier, you can replace the ereg() call with a call to mb_ereg(). The latter function is a direct replacement for the former, and is not deprecated.
Restart your Apache web server using the Server Admin tool, and off you go.
MySQL database connection test
Here is some simple php test code that can be used to show the connection error (used to generate the above error text), or to test the changes to the php.ini file.
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$dbname = 'databasename';
$connection = mysql_connect( $dbhost, $dbuser, $dbpass);
if (!$connection ) {
echo "mysql_connect : " . mysql_error() . "<br />";
echo "Error code :" . mysql_errno() . "</pre>";
die('Error connecting to mysql');
}
if (!mysql_select_db($dbname)) {
echo "mysql_select_db : " . mysql_error() . "<br />";
echo "Error code : " . mysql_errno() . "</pre>";
die('Error selecting database');
}
echo 'Connection established';
mysql_close($connection);
?>Snow Leopard Server php includes gd
Of interest, the default php configuration shipped with Snow Leopard Server now includes gd 2.0.34 bundled and enabled, as well; there is no need to rebuild php to add this particular capability.