You are now on my Technical Blog. My other sites: Personal Blog - Genealogy Blog - Genealogy Site

DLMax Max Westen's ramblings on OSX and PHP

Blog Tags: hack

Installing PHP 5.2.8 on OSX Leopard 10.5.6

Dec 29, 2008

Because I travel a lot by train, it’s easy to have a local development environment with me. Because OSX Leopard contains Apache2 and PHP 5.2.6, I installed MySQL, ZF, PEAR, setup the vhost conf for apache and added the path to the ZF and PEAR libraries to /etc/php.ini. This seemed to work fine for a day or two, but after that I needed to use the PDO_MySQL library. This didn’t really work… The fact is that PDO_SQLite and PDO_SQLite2 are compiled along the installed PHP library, but PDO_MySQL isn’t… Big FAIL!.

So, we’ll have to setup a new PHP/Apache2 combo…..

Okay let’s start:

1. Install the Apple Developer tools

If you haven’t done it already, install the Developer Tools(XCode 3) from the OSX DVD

2. Install and update MacPorts

If you haven’t installed MacPorts on your system, do so by downloading it from the MacPorts website and running the installer. Now open a terminal window and update MacPorts:

sudo port selfupdate
sudo port sync

3. Install apache2

Create the following directory and symlink for the correct use of MySQL (the install searches there for libraries):

sudo mkdir /usr/local/mysql/lib/mysql
sudo ln -sf /usr/local/mysql/lib/lib* /usr/local/mysql/lib/mysql/

Install Apache2:

sudo port install apache2

Let the apache2 process be autostarted by the system:

sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist

Move the old Apache stuff out of the way:

sudo mv /usr/sbin/apachectl /usr/sbin/apachectl-leopard
sudo ln -s /opt/local/apache2/bin/apachectl /usr/local/bin/apachectl

Copy the sample conf file and make it the default

sudo cp /opt/local/apache2/conf/httpd.conf.sample /opt/local/apache2/conf/httpd.conf

Now you can modify your apache settings to your liking, but remember to use only the ones in the /opt/local/apache2/conf directory; the old configs(/etc/apache2/conf) are not used anymore.

4. Install the additional stuff needed

Then make sure we have everything installed we want in there; I want: GD libraries, iconv, PDO_MySQL, curl

sudo port install jpeg
sudo port install libpng
sudo port install freetype
sudo port install libmcrypt
sudo port install tidy
sudo port install libiconv

Rename the default iconv.h because it generates errors while compiling PHP

sudo mv /usr/include/iconv.h /usr/include/iconv.h.leo_orig
sudo ln -s /opt/local/include/iconv.h /usr/include/iconv.h

5. Download, configure and install PHP

Download the php5.2.8.tar.gz file from the PHP website. go to your download directory and run

tar xvzf php-5.2.8.tar.gz 

Then move this folder to the /opt/local/php-5.2.8 folder

sudo mv php-5.2.8 /opt/local/

Then create a symlink that you can compile against:

sudo ln -s /opt/local/php-5.2.8 /opt/local/php

Go into the newly created ‘folder’:

cd /opt/local/php/

Now configure PHP:

'./configure' \
'--prefix=/opt/local/php' \
'--with-apxs2=/opt/local/apache2/bin/apxs' \
'--with-xsl=/usr' \
'--with-tidy=/opt/local' \
'--with-ldap=/usr' \
'--with-kerberos=/usr' \
'--enable-mbregex' \
'--enable-ftp' \
'--with-iodbc=/usr' \
'--with-curl=/usr' \
'--enable-mbstring' \
'--with-gd' \
'--with-jpeg-dir=/opt/local' \
'--with-png-dir=/opt/local' \
'--with-zlib-dir' \
'--enable-sockets' \
'--enable-exif' \
'--with-mcrypt=/opt/local' \
'--enable-soap' \
'--with-mysql=/usr/local/mysql' \
'--with-mysqli=/usr/local/mysql/bin/mysql_config' \
'--with-pdo-mysql=/usr/local/mysql/bin/mysql_config' \
'--with-mysql-sock=/tmp/mysql.sock' \
'--with-freetype-dir=/opt/local' \
'--with-openssl=/opt/local' \
'--with-iconv=/usr' \
'--with-libxml-dir=/usr' \
'--with-xmlrpc' \

Then make and install php:

sudo make
sudo make install

And rename the old PHP and create a symlink to the new binary:

sudo mv /usr/bin/php /usr/bin/php-leopard
sudo ln -s /opt/local/php/bin/php /usr/bin/php

copy the new php.ini file and edit it to your liking:

sudo cp php.ini-dist lib/php.ini

Note: The new php.ini file in use is the one located at: /opt/local/php/lib/php.ini

6. Restart the webserver

Up until now the old webserver was running. Shut it down and then start the new apache2:

sudo apachectl-leopard stop
sudo apachectl start

If all went well, Apache is running and PHP scripts get executed. Please check the installed features by calling a page with the following code on it, to ensure everything is installed.

In the next post we will add xDebug to the stack and later on the debugging environment is setup for different IDEs.

Part2: Installing xDebug on OSX

Themed Tab Terminal for OSX Leopard

Dec 28, 2008

If you’re working a lot with remote sessions like I do, you inevitably type a command in the wrong window… Most of the time it’s something harmless like an ls or an cd command, but if you’re trying to clean stuff up with an rm command things can get bad.

The easiest way to differentiate between local and remote sessions or different remote sessions is changing the background-color. When switching terminal, you immediately see/know where you are, without looking at the prompt or the window-title. So how do we implement this in the standard OSX Leopard ?

I like the terminal in OSX Leopard a lot but it doesn’t have support for some simple things like opening themed tabs or use the bookmark function like in iTerm. Because I prefer Terminal over iTerm, I tried hacking some scripts together

First I pick a theme I’d like to use on a daily basis from the Preferences - Settings window. In my case it’s "IR Black". Then I select the theme and duplicate it by pressing the small "cog" icon and selecting "Duplicate Settings". Duplicate the theme Rename the duplicated theme to something useful; I’m using one to connect to a server named "Pentagon", so I name it this way. Note that the duplicated theme automatically gets the Default theme being used when pressing ⌘T. You can select another theme and then click the "Default" button to set the original "IR Black" as default again. Set the default theme

Select the newly created "Pentagon" theme, go to the "window" tab and press the "Background Color" selector. Pick a color of your liking here. Because I like a darker background, I choose a very subtle tint of red in my black; just enough to notice it when in the terminal. Change the backgroundcolor Select the color

Right now we can manually open a new terminal window by going into the "Shell" "New Tab" menu and select the "Pentagon" theme there. If you like you can tweak the background color with the theme selected to see the changes immediately applied to your terminal screen.

Right now you have a different background-color, so you can start an ssh connection with the pentagon server, but I don’t like to use the mouse first and then start the ssh session manually. Create a tab with the new theme While looking around I came across a modification of Marc Liyanage’s "open terminal here" plugin, by Geoff using an applescript by Jacob Rus to open the menus and submenus from OSX apps programmatically.

I’ve mixed-and-matched the scripts and the ttterm (Themed Tab Terminal) script is the result. For the script to work, you need to enable "Access for assistive devices" on the "Universal Access" screen in "System Preferences". Access Assistive Devices If this script is placed in your path, it can be called in two ways:

1) Opens a new tab with the selected [themename]

ttterm [themename]

2) Opens a new tab with the selected [themename] and runs the [command] in the new terminal.

ttterm [themename] [command]

So if I want an ssh connection with pentagon, I can call:

ttterm Pentagon ssh max@pentagon

This is still quite long, so I add an alias to my .bashrc file and off we go.