Bos Risman has mentioned creating PHP extensions in Windows for PHP4Live (Live extensions for PHP). I'm gonna build a .so equivalent in the *Nix world in this post:
- I'm part of the PHP4Live team, so when this project hits the first gear, you'll also be hearing from me.
- We all know that PHP is running more on *Nix machines than Windows, so I'll make sure for every .DLL's Pak Risman producing, I will build the equivalent .so too.
- I'll give you a shorter tutorial on creating PHP Extension on Mac OS X. Why Mac? Long time ago before I joined MS, one of my developer idol was Jordan Hubbard, one of the founders of FreeBSD, now working for Apple. He was so inspiring 'cos he only graduated from high school. Makes you think whether you really need a Computer Science degree to understand kernel stuff (oh, wait a minute, on the contrary, do Computer Science students nowadays understand kernel stuff?). That guy sparked my interest in FreeBSD 4.0 back then. Now that FreeBSD has been forked into Darwin and added with a finger-licking good GUI to become the Mac OS X, I'm sticking with this OS as my main machine.
So here are the steps into building .so for PHP extension on Mac OS X:
- Download and install MAMP.
- Download the skeleton code of Hello World PHP Extension.
- Extract the skeleton to ~/helloext.
- Open Terminal, "cd ~/helloext" , and then type these 4 commands inside the helloext folder:
- phpize
- ./configure -enable-hello
- make
- cp modules/hello.so /Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20050922/
- Edit your php.ini:
- vi /Applications/MAMP/conf/php5/php.ini
- Press Ctrl-F to scroll down until you see "; Extensions".
- Press i to switch to Insert Mode, then type extension=hello.so
- Press Esc to go back to command-mode, and type :wq (write & quit)
- From Finder, open widget MAMP in folder Applications.
Click the phpinfo button from the menu to check whether our hello.so is registered or not.
Now, write this PHP page:
Save it to /Applications/MAMP/htdocs/hello/hello.php
Browse to http://localhost:8888/hello/hello.php
Sweet, it works :)