Compiling 64 bit PHP on Mac OS X Leopard

My iMac ships with Leopard 10.5.2 and PHP 5.2.5 was integrated. As I was planning to build optional components into PHP, I decided to compile PHP 5.2.6 myself.

I have MySQL installed on /usr/local/mysql and to preserve the orginal settings of the preinstalled version, I used following configure options:

./configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info \
--disable-dependency-tracking --with-apxs2=/usr/sbin/apxs --with-ldap=/usr \
--with-kerberos=/usr --enable-cli --with-zlib-dir=/usr --enable-trans-sid --with-xml \
--enable-exif --enable-ftp --enable-mbstring --enable-mbregex --enable-dbx --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 --with-openssl --with-xmlrpc --with-xsl=/usr --without-pear \
--with-mysql=/usr/local/mysql

Then after building, make and install, apache failed to start as libphp5.so was in a “wrong architecture”.

Then I realized, the Apache shipped with Leopard was the 64bit version, so I have to build a 64 bit PHP.

so I added the following before configure:

MACOSX_DEPLOYMENT_TARGET=10.5
CFLAGS="-arch x86_64 -g -Os -pipe -no-cpp-precomp"
CCFLAGS="-arch x86_64 -g -Os -pipe"
CXXFLAGS="-arch x86_64 -g -Os -pipe"
LDFLAGS="-arch x86_64 -bind_at_load"
 
export CFLAGS CXXFLAGS LDFLAGS CCFLAGS MACOSX_DEPLOYMENT_TARGET

The last line seems redundant but strangely on my machine, the flags won’t work until I export them.

In order to configure a 64bit build, I have to install a 64bit version of MySQL, or you’ll fail the configure.

All files compiled successfully, but the linkage failed. The error was “Undefined symbol: _libiconv”. Well that’s a new one, didn’t see that when building the x86 version.

After googling for a while, I found the solution. Apple’s libiconv.dylib has a bug, it forgot to export _libiconv for both 64bit architectures (ppc64 and x86_64). The solution is to compile a universal binary libiconv yourself. (And do not forgot to install the header files too, or you’ll get other undefined symbol errors)

The flags of building universal binary is similar as the above ones. Just remember to put all four architectures (-arch i386 -arch x86_64 -arch pc7400 -arch ppc64) there.

Then finally I have the php built successfully and up n running.

Notes

To build a universal binary version of PHP, you need to build MySQL universal yourself as well, and all the libraries you used should be compiled as universal binary.

A universal binary looks like this :

$ file /usr/sbin/httpd
/usr/sbin/httpd: Mach-O universal binary with 4 architectures
/usr/sbin/httpd (for architecture ppc7400):	Mach-O executable ppc
/usr/sbin/httpd (for architecture ppc64):	Mach-O 64-bit executable ppc64
/usr/sbin/httpd (for architecture i386):	Mach-O executable i386
/usr/sbin/httpd (for architecture x86_64):	Mach-O 64-bit executable x86_64

- Update:
After this post I’ve been using php with Leopard for a while. I found that sometimes (probably after an OS update, but I haven’t confirmed this yet) the system restores old versions of php, which would fail to load the custom-built libiconv. So you have to run “make install” & “make install-cli” again to make the new version working again. (No recompilation, only reinstall)

MacBook Airror

Apparently some audio can’t be turned up to F11.

read more | digg story

The “SCP” implementation of WinSCP

SCP is a simple protocol for secure file copy. Only file-copy (bi-directional) is supported by scp.

However, the WinSCP implementation of “SCP” is actually a GUI for the remote shell.

WinSCP requires login access to remote server. After login, it make use of common *ix commands like ls, ln, mv, etc. The real scp client is only called when there’s a need to exchange files (i.e. download / upload). Other than that, the operations are indeed completed by the remote shell. And because of that, the implementation is rather platform-dependent. As different distributions have different output formats, especially with “ls”, the output varies among each other. (And that’s why WinSCP recommends to use bash on the server side as default shell for remote login).

So when you use “SCP” protocol in WinSCP, you’re actually using a SSH client with scp. WinSCP should name it like “SCP (with Shell)” or something to avoid misleading.

New External HDD

Finally the exams over. So I went to Mong Kok and bough a external HDD, 500G with FireWire 800 interface.

Hooked it up with my Mac easily, it is already pre-partitioned and has utilities available on disk. So I did a little benchmarking with XBench. The result was satisfactory, reading operations with proper block size is as fast as those on the internal HDD.

Mac HDD:

Results	66.90
	System Info
		Xbench Version		1.3
		System Version		10.5.2 (9C7010)
		Physical RAM		4096 MB
		Model		iMac8,1
		Drive Type		WDC WD3200AAJS-40VWA1
	Disk Test	66.90
		Sequential	96.08
			Uncached Write	114.83	70.50 MB/sec [4K blocks]
			Uncached Write	111.76	63.23 MB/sec [256K blocks]
			Uncached Read	63.28	18.52 MB/sec [4K blocks]
			Uncached Read	122.35	61.49 MB/sec [256K blocks]
		Random	51.31
			Uncached Write	20.46	2.17 MB/sec [4K blocks]
			Uncached Write	114.09	36.52 MB/sec [256K blocks]
			Uncached Read	79.85	0.57 MB/sec [4K blocks]
			Uncached Read	128.33	23.81 MB/sec [256K blocks]

External HDD:

Results	41.29
	System Info
		Xbench Version		1.3
		System Version		10.5.2 (9C7010)
		Physical RAM		4096 MB
		Model		iMac8,1
		Drive Type		LaCie d2 quadra
	Disk Test	41.29
		Sequential	72.25
			Uncached Write	81.06	49.77 MB/sec [4K blocks]
			Uncached Write	88.00	49.79 MB/sec [256K blocks]
			Uncached Read	42.36	12.40 MB/sec [4K blocks]
			Uncached Read	124.12	62.38 MB/sec [256K blocks]
		Random	28.91
			Uncached Write	8.97	0.95 MB/sec [4K blocks]
			Uncached Write	116.26	37.22 MB/sec [256K blocks]
			Uncached Read	90.91	0.64 MB/sec [4K blocks]
			Uncached Read	137.85	25.58 MB/sec [256K blocks]

Got a Mac

Just bought a Mac, like it much.

GTA IV “Liberty City Gun Club” Trailer

Well, I’ve never been much of a GTA fan, but this trailer surely speaks to me.

“If every citizen was armed, no one would be DUMB enough to shoot people !”