In the vein of some of Lorna's articles, this is more a note for myself than anything else. Not everything is explained in detail as it assumes you know how to use a command line...
These are the steps I take to get the Apple supplied PHP working with GD, PDO_MySQL and Xdebug working on OS X 10.5.
/usr/local
Ensure that the following directories exist:
sudo mkdir /usr/local/include
sudo mkdir /usr/local/bin
sudo mkdir /usr/local/lib
sudo mkdir -p /usr/local/man/man1
Run Apache in 32 bit mode
This saves us having to compile our own MySQL as MySQL doesn't offer a "fat" binary
- cd /System/Library/LaunchDaemons
- sudo vim org.apache.httpd.plist
- Immediately after the line containing <array> add:
<string>arch</string> <string>-i386</string> - Reboot
MySQL
- Download the 32bit version of MySQL 5.0.x for OS X 10.5 from mysql.com and install the pkg, the startup item and the pref pane.
- Add /usr/local/mysql/bin to the path: vim ~/.bash_profile and add:
export PATH=~/bin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH export EDITOR=vimat top of file. (Note that we set EDITOR whilst we are here so that svn is happy!)
- Set up MySQL root password:
mysqladmin -u root password {new-password} mysqladmin -u root -p{new-password} -h localhost password {new-password} mysqladmin -u root -p reloadQuit Terminal to flush the history to file. Restart Terminal and remove the history file: rm .bash_history so that {new-password} isn't in plain text on the disk.
- Set the correct socket information for PHP. Ensure MySQL is running via the System Preferences panel then:
sudo mkdir /var/mysql sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
Rest of Apache setup
- cd /etc/apache2
- sudo vim httpd.conf
- Find #LoadModule php5_module libexec/apache2/libphp5.so and remove the leading #
- Find AllowOverride None within the <Directory "/Library/WebServer/Documents">section and change toAllowOverride All so that .htaccess files will work.
- Restart Apache: sudo apachectl restart
- Open Finder and navigate to /Library/WebServer/Documents/
- Create a new folder called "orig" and place all files currently in the Documents folder into it.
- Create a new file called info.php with <?php phpinfo(); inside it.
- Use Safari to navigate to http://localhost/info.php and check that the PHP version is displayed (5.2.6 at the time of writing).
php.ini
- cd /etc
- sudo cp php.ini.default php.ini
- sudo chmod ug+w php.ini
- sudo chgrp admin php.ini
- vim php.ini (assuming your user is a member of the admin group) and change settings appropriately. Change:
error_reporting = E_ALL | E_STRICT extension_dir = "/usr/lib/php/extensions/no-debug-non-zts-20060613"You must set the extension dir correctly. (Commenting the line out also works...)
PHP extensions
The supplied PHP doesn't come with pdo_mysql, pear or gd, so fix it.
- Download the correct version of PHP from http://www.php.net/releases/. (5.2.6 at time of writing)
- Create a directory called src in your home directory and unpack the PHP source. This creates /Users/rob/src/php-5.2.6/ in my case.
pdo_mysql
- cd ~/src/php-5.2.6/ext/pdo_mysql.
- phpize
- MACOSX_DEPLOYMENT_TARGET=10.5 \
CFLAGS='-O3 -fno-common -arch i386' \
LDFLAGS='-O3 -arch i386' \
CXXFLAGS='-O3 -fno-common -arch i386' \
./configure --prefix=/usr --with-pdo-mysql=/usr/local/mysql - make
- sudo make install
- Edit /etc/php.ini and find the extension_dir line and add after it:
extension=mysql.so
- Restart apache: sudo apachectl restart and check in the phpinfo that pdo_mysql is now loaded.
GD
Installing GD onto the stock PHP install that is supplied with OS X is slightly more complicated than you'd expect because you need to install libjpeg first.
Libjpeg
Libjpeg is available from the Independent JPEG Group.
- Download the source code: http://www.ijg.org/files/jpegsrc.v6b.tar.gz
- extract to ~/src
- cd ~/src/jpeg-6b
- cp /usr/share/libtool/config.* .
- ./configure --enable-shared
- sudo make install
- Libjpeg is now installed in /usr/local/lib
GD extension
- cd ~/src/php-5.2.6/ext/gd
- phpize
- MACOSX_DEPLOYMENT_TARGET=10.5 \
CFLAGS='-O3 -fno-common -arch i386' \
LDFLAGS='-O3 -arch i386' \
CXXFLAGS='-O3 -fno-common -arch i386' \
./configure --with-zlib-dir=/usr --with-jpeg-dir=/usr/local/lib --with-png-dir=/usr/X11R6 --with-freetype-dir=/usr/X11R6 --with-xpm-dir=/usr/X11R6 - make
- sudo make install
- Edit /etc/php.ini and find the extension_dir line and add after it:
extension=gd.so
- Restart apache: sudo apachectl restart and check in the phpinfo that GD is now loaded.
PEAR
- cd ~/src/.
- curl http://pear.php.net/go-pear > go-pear.php
- Accept defaults, except for installation prefix (1) should be /usr/local
- Check that the include_path in /etc/php.ini is correct and includes the PEAR directory (/usr/local/PEAR).
Xdebug
Can't have a PHP development environment without xdebug!
- sudo pecl install xdebug
- Edit /etc/php.ini and add
zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so"
after the other extension lines.
- Restart apache: sudo apachectl restart and check in the phpinfo that xdebug is now loaded.
PHPUnit
- sudo pear channel-discover pear.phpunit.de
- sudo pear install phpunit/PHPUnit
It all works on this machines, anyway :)
Updatesee Marc Liyanage's PHP5 packages



March 6th, 2009 at 10:12 #
Thanks for this Rob. Just for the record if anyone is looking for the "easy way" to get a zend framework dev environment working on osx leopard, I use xamp:-
http://www.apachefriends.org/en/xampp-macosx.html
it provides a "standalone" apache/mysql/php setup which includes pdo_mysql. click and run installer :)
Things can get a bit thorny if you have already installed mysql seperately, as things can get a bit confused with paths, but otherwise it is a convenient way to get going
March 6th, 2009 at 10:40 #
MacPorts makes this process a lot easier..
March 6th, 2009 at 14:09 #
Unless you are using the mac as the production environment I find it *much* easier to just use MAMP (http://mamp.info/en/index.html). Just drag it to your apps folder, start the services with the app they provide and you are all set to go spending time developing web applications.
March 6th, 2009 at 16:41 #
I don't doubt it :)
There is also BitNami and Zend Server CE options nowadays too.
Regards,
Rob...
March 6th, 2009 at 17:02 #
Rob, does this process keep the ability for the OSX GUI to control the start/stop process of Apache? That was the one hangup I had when I did this myself (albeit with different install path settings).
March 6th, 2009 at 21:17 #
Brendon,
Yes, I use System Preferences -> Sharing and tick/untick the Web Sharing box to start and stop Apache.
Regards,
Rob...
March 6th, 2009 at 21:30 #
Rob, thank you very much for posting this. It's very important for new developers to understand the innards of their PHP installation and how to build one properly, and it doesn't get explained well very often in a simple platform/version specific way. Because of all the shortcuts with good press, new PHP users (particularly Mac users) often become afraid of modifying their installations (and sometimes even applying patches and updates) because they think it's difficult. Providing details like these give them the confidence to tweak.
I would like your permission to duplicate these instructions on the DallasPHP.org User Group web site (fully linked and credited, of course), as part of a library of detailed installation instructions (both traditional and shortcuts) for all members on various platforms. With your permission, the article would go online with our next site revision (planned for late this month).
March 6th, 2009 at 21:37 #
MonkeyT,
Feel free :)
Regards,
Rob...
March 7th, 2009 at 09:45 #
A few corrections for my install running OS X 10.5.6:
pdo_mysql step #3, the configure command should be (the hyphens don't past well):
./configure --prefix=/usr -with-pdo-mysql=/usr/local/mysql
pdo_mysql step #6:
extension=pdo_mysql.so
Apache repeatedly crashed. After tailing the apache error log, I noticed this line:
dyld: Library not loaded: /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib
Sure enough the file didn't exist. However, I was able to find the file in the parent directory, /usr/local/mysql/lib
Creating a symbolic link named mysql in /usr/local/mysql/lib fixed the problem:
cd /usr/local/mysql/lib
ln -s ../ mysql
Thank you very much for this guide. The other guide online are much more intensive.
March 7th, 2009 at 09:48 #
Yikes, seems like your form data sanitizer escapes the hypens a bit too aggressively!
I meant to say:
./configure (double-hyphen)prefix=/usr -with-pdo-mysql=/usr/local/mysql
March 7th, 2009 at 09:59 #
Thanks Makea,
The double hyphens are correct when I edit it, so it must be WordPress' output layer that's the issue!
Rob...
March 7th, 2009 at 10:10 #
Hey Rob,
Nice how to, although I won't use it ;) What was the reason to install it manually instead of using xampp or mamp?
I myself have been using xampp for a while and really like it. I already used it on my windows machine and after going mac last year I stayed with my beloved xampp ;)
March 8th, 2009 at 09:36 #
Gauke,
No especial reason - they just don't "fit" for me.
One problem I've found with MAMP/XAMPP/ZendServer is that they all include more than I actually want. e.g. Xammp and Mamp still ship PHP 4!! ZendServer has some sort of weird optimizer included an old version of Zend Framework!
They all use weird places to store their htdocs - what's wrong with /Library/WebServer/Documents/ and ~/Sites?
Rob...
March 12th, 2009 at 15:19 #
The last time I upgraded OS X I found that everything in /Library/WebServer/Documents/ had #$%%^ disappeared!
So that's why I don't use the default location of anything and prefer to manually backup up stuff before an upgrade/move to new hardware instead of using their data/settings transfer process.
Just to be fair....
Back in Windows ME I booted my pc one morning and was met with the message "There is something wrong with your my documents folder. Windows is attempting to fix the problem."... or something along those lines. When I was finally able to log in I found my My Documents folder had reverted to the way it was after doing a fresh install. All MY files were gone. So I don't use that f#$^#$ location either.
March 12th, 2009 at 15:30 #
Rob, I see what you mean. You can just disable php4 though and use php5 (5.2.6 is shipped).
The htdocs thing is annoying, but can be changed to :) I use ~/htdocs which works fine. You can change these things in xampp-dir/etc/httpd.conf
And that's the end of my xampp promo tour :)
March 12th, 2009 at 15:34 #
vominoose,
Fair enough :)
Gauke Pieter,
True, but it's still sitting on my hard disk :)
Regards,
Rob...
March 15th, 2009 at 00:34 #
I'm going to translate that material to russian. I hope it will be interesting 4 my visitors, and i hope you don't mind...
March 15th, 2009 at 08:31 #
vlad,
Feel free.
Regards,
Rob...
April 3rd, 2009 at 22:36 #
Hi Rob,
Thanks for this but it doesn't seem to be working for me on Mac 10.5.6 here's what's happening when I try and configure mysql_pdo I get this error:
checking for mysql_config... /usr/local/mysql/bin/mysql_config
checking for mysql_query in -lmysqlclient... no
checking for mysql_query in -lmysqlclient... (cached) no
configure: error: Try adding --with-zlib-dir=. Please check config.log for more information.
Any help would be brilliant!
K
April 4th, 2009 at 13:21 #
Kieran,
Install MySQL first and ensure that it's working.
Regards
Rob....
April 4th, 2009 at 13:56 #
Hi Rob,
MySQL is installed as per your instructions and is functioning normally.
K
April 27th, 2009 at 10:48 #
Great article!
After curl pear i had to run:
php -q go-pear.php
to start the installation.
June 17th, 2009 at 17:16 #
There is a note at:
http://www.gigoblog.com/2008/10/08/install-gd-for-php-on-mac-os-x-105-leopard/
NOTE: Check the output of the last command. If you get an error similar to this –”/usr/X11/lib/libpng.3.0.0.dylib: No such file or directory” — you should create a symbolic link with a name matching the file referred to in the error message. For example, the above error indicates that no libpng.3.0.0.dylib file exists. Simply create a link named libpng.3.0.0.dylib pointing to libpng.3.dylib:
sudo ln -s /usr/X11/lib/libpng.3.dylib /usr/X11/lib/libpng.3.0.0.dylib
Likewise, if your error refers to libpng12.0.##.#, you should create a symbolic link to libpng12.0.dylib.
Then, recompile GD.
June 25th, 2009 at 00:16 #
Kieran,
It looks like you're compiling 64-bit. Changing 'i386' as the arch to 'x86_64' cleared up that error for me.