Friday, March 20, 2009

As unexpected as it seems right now... I can't complain how life has turned out.

Tuesday, March 17, 2009

php 5.2.9 + mysql + pdo_mysql on leopard



** Click here for PHP 5.3.0 **

This is a brief explanation of how you might be able to get pdo_mysql working on Leopard (OS X 10.5.6 and 10.5.7) with the stock Apache installation, on a Core 2 based Mac, while conveniently updating PHP as well. I was able to scrape this together from a few blog posts, mostly this one, and also some guess work.

This installation only covers 64-bit capable Intel Macs: those with the Core 2 processor. I might be able to guess at 32-bit (original Core) instructions; comment here if you need them.

1. Make a backup copy of this file: /usr/libexec/apache2/libphp5.so

2. Download and install MySQL from the MySQL website. Make sure to download the x86_64 package.

3. Download and unzip the PHP source code from the PHP website. I used the latest, PHP 5.2.9, at the time of this writing.

4. Open a terminal window and move to the unzipped directory, then execute the following commands.

MACOSX_DEPLOYMENT_TARGET=10.5 \
CFLAGS='-O2 -arch x86_64' \
LDFLAGS='-O2 -arch x86_64' \
CXXFLAGS='-O2 -arch x86_64' \
./configure '--prefix=/usr/local/php-5.2.9' \
'--with-apxs2=/usr/sbin/apxs' \
'--with-ldap=/usr' \
'--with-kerberos=/usr' \
'--enable-cli' \
'--with-zlib-dir=/usr' \
'--enable-exif' \
'--enable-ftp' \
'--enable-mbstring' \
'--enable-mbregex' \
'--enable-sockets' \
'--with-iodbc=/usr' \
'--with-curl=/usr' \
'--with-config-file-path=/etc' \
'--sysconfdir=/private/etc' \
'--with-mysql-sock=/var/mysql' \
'--with-mysqli=/usr/local/mysql/bin/mysql_config' \
'--with-mysql=/usr/local/mysql' \
'--with-openssl' '--with-xmlrpc' \
'--with-xsl=/usr' \
'--without-pear' \
--enable-pdo=static \
--with-pdo-mysql=/usr/local/mysql


make

sudo make install

sudo apachectl restart

Take a look at your phpinfo(), and if all went well, you will see MySQL listed in the drivers under PDO. If it doesn't work, the bailout is to put the original libphp5.so back into place... you know, the one you backed up in step 1... you did back it up, right?

PHP CLI users: If you are getting this warning:
PHP Warning: PHP Startup: Unable to load dynamic library './pdo_mysql.so' - (null) in Unknown on line 0

Comment out the following line in /etc/php.ini:
extension=pdo_mysql.so

Sunday, March 15, 2009

php is scalable

Back in the day I had plenty of stuck-in-their-ways Java and J2EE developers tell me that PHP isn't scalable. They were wrong, and I politely told them that. It was a classic case of people reciting opinions without really having explored the truth. I never heard anything like it from any developer that had actually used PHP for developing a project.

PHP's interpreter is written in very fast C; it has an extremely low memory footprint, and its execution leaves no traces behind. What's there that won't scale? Slap an opcode cache on the server, parameterize your SQL queries, and it gets even better.

Today, thankfully, I don't hear much of that nonsense anymore, but I felt compelled to reiterate the point today when I was reminded that Wikipedia is built on PHP and MySQL, both major open-source projects. As of this writing, Wikipedia is the 7th most popular website in the world according to Alexa. I believe a great deal of Facebook is also PHP, if not all of it.

PHP is definitely not the answer to everything, and as an architect I generally rather prefer the rigidity of a Java or a C# when creating a system. But to say that PHP is not scalable is absolute nonsense.