Earlier today, I wanted to setup a PHP development environment on my MacBook Pro. It was expected to be very simple. As many tutorials said, I just uncommented the “LoadModule php5_module libexec/apache2/libphp5.so”, enabled web sharing in system preferences, and expected to see PHP working by visiting http://localhost/~myusername/.
But no luck. Firefox just can’t connect to the web server. Then instead clicking the checkbox in system preferences window, I tried to type commands in Terminal – “sudo apachectl start”. But the execution of the command just completed with no output or any warnings. Also, nothing appeared in /var/log/apache2/error_log. That’s really weird – on Linux platform, there should be something if the server fails to start. But by appending an argument to the command:
sudo apachectl -k start -e debug
we can see more details. The error was:
httpd: Syntax error on line 116 of /private/etc/apache2/httpd.conf: Cannot load /usr/libexec/apache2/libphp5.so into server: dlopen(/usr/libexec/apache2/libphp5.so, 10): Symbol not found: _GetPrivateProfileString\n Referenced from: /usr/lib/libiodbc.2.dylib\n Expected in: flat namespace\n
Yes I once used iODBC to connect to a MS SQL Server but I don’t know how I installed it. I don’t know the underlying secret. I don’t know how to solve this problem either, except doing a fresh build of PHP.
I used the latest php 5.3.5 source and the configure parameters are like:
./configure ‘–prefix=/usr’ ‘–mandir=/usr/share/man’ ‘–infodir=/usr/share/info’ ‘–disable-dependency-tracking’ ‘–sysconfdir=/private/etc’ ‘–with-apxs2=/usr/sbin/apxs’ ‘–enable-cli’ ‘–with-config-file-path=/etc’ ‘–with-libxml-dir=/usr’ ‘–with-openssl=/usr’ ‘–with-kerberos=/usr’ ‘–with-zlib=/usr’ ‘–enable-bcmath’ ‘–with-bz2=/usr’ ‘–enable-calendar’ ‘–with-curl=/usr’ ‘–enable-exif’ ‘–enable-ftp’ ‘–with-jpeg-dir=/usr/local’ ‘–with-png-dir=/usr/local’ ‘–enable-gd-native-ttf’ ‘–with-ldap=/usr’ ‘–with-ldap-sasl=/usr’ ‘–enable-mbstring’ ‘–enable-mbregex’ ‘–with-mysql=mysqlnd’ ‘–with-mysqli=mysqlnd’ ‘–with-pdo-mysql=mysqlnd’ ‘–with-mysql-sock=/tmp/mysql.sock’ ‘–enable-shmop’ ‘–with-snmp=/usr’ ‘–enable-soap’ ‘–enable-sockets’ ‘–enable-sysvmsg’ ‘–enable-sysvsem’ ‘–enable-sysvshm’ ‘–with-xmlrpc’ ‘–with-iconv-dir=/usr’ ‘–with-xsl=/usr’ ‘–with-pcre-regex’ ‘–with-freetype-dir=/usr/X11R6’ ‘–enable-zend-multibyte’ ‘–enable-zip’
After configure, just run “make” and “sudo make install” and the libphp5.so file should be replaced with your own.
If the configure script fails to find jpeg/png libraries, you can follow instructions here to install them. You can also enable gd extension. But don’t use the flag “–with-iodbc” because that’s what caused us pain. If you do want to use ODBC with PHP, you should ignore this article :(