Apache, PHP and MySQL - Segmentation faults
My experience of Snow Leopard so far has been very positive, with the exception of this one problem: Apache segfaults when serving a PHP page that accesses a MySQL connection.
I am not using any custom builds of PHP or Apache. The segfault appears using the Snow Leopard bundled PHP 5.3.0 and Apache 2.2.11.
The problem manifests when connecting to either a local or remote database, and with or without the MySQL Community Server installed. I have tested this on my own MacBook Pro which has MySQL 5.1.38 x86_64 installed, and also a 12-month old iMac upgraded to Snow Leopard which has never had MySQL installed.
*Steps to reproduce:*
1. Create a php.ini file by copying */etc/php.ini.default* to */etc/php.ini*, since one is not installed by default.
2. Modify */etc/php.ini* with the following settings:
*mysql.default_port = 3306*
*date.timezone = "Europe/London"*
The MySQL port number is blank by default, causing PHP to use port 0 when trying to access a database connection. Also, unless a timezone is set PHP issues a warning. It's not critical, but it's a log-filler.
3. Open */etc/apache2/httpd.conf* and uncomment the following line to enable PHP (ie, remove the # at the start of the line):
*#LoadModule php5_module libexec/apache2/libphp5.so*
4. Go to "System Preferences > Sharing" and check "Web Sharing" to start Apache, or type "sudo apachectl graceful" in a terminal to restart it if it's already running.
5. Create a new file called "mysql.php" in ~/Sites and paste the following:
*<?php*
*$database = 'localhost';*
*$username = 'root';*
*$password = '';*
*mysql_connect($database,$username,$password);*
*mysql_close();*
*?>*
Obviously if you do not have MySQL Community Edition installed you should replace "localhost" with the location of your database server. Also replace the username/password with correct credentials.
6. Produce the segfault with one of the following:
a. Type *cd ~/Sites ; php mysql.php* in a terminal. You will see "Segmentation fault".
b. Accessing the page in a browser at * http://localhost/~yourshortusername/mysql.php* produces a plain white page with no error.
In both cases an error is logged to */var/log/apache2/error_log* that looks something like this:
*\[Thu Sep 03 16:01:11 2009\] \[notice\] child pid 2518 exit signal Segmentation fault (11)*
Doing some quick googling reveals others are having the same or similar problems, and also with extensions other than the MySQL one. Workarounds exist in compiling your own Apache/PHP, but I want to avoid this on my own setup.
Hopefully this information will help Apple to fix the problem in a Software Update.
Thanks for reading,
Conan
MacBookPro5,2, Mac OS X (10.6), 2.93GHz Core 2 Duo, SSD