Bastian's Blog

Bastian's Blog

Info | HTML | Text | RSS

Howto setup a MacBook for PHP development (part 1)

After some research I learned that there are an Apache in version 2.2.11 and a PHP version 5.2.8 preinstalled on MacOsX 10.5.

Starting the Apache webserver

There are two ways to start the Apache on Mac. The most preferred on might be the Settings dialog.

Therefore open the Settings dialog from the dock and open the Sharing section. Here you will find a topic named Websharing. After activation of the checkbox and applying your changes the default web addresses of your computer are displayed. Click on one of these to verify the apache is running.

The second way is to use the terminal, but this is much more difficult for people not familiar to use a console. Nevertheless the example will show you what to do.

$> sudo apachectl start

Making PHP available from Apache

Next thing was to see if PHP works. I looked up the DocumentRoot, which turned out to be

/Library/WebServer/Documents

and added the usual phpinfo.php to get information about the installed PHP. Sure, this can be done by typing

$> php -i

into a terminal, but the php-cli uses another php.ini then the webserver by default and I did not want to test the cli but the PHP enabled in Apache.

Opening the file with the browser a nicely formatted php source code was presented instead of the rendered output of phpinfo(). So unfortunately apache is not configured to identify PHP files to execute them with the php interpreter. To make them talk to each other I only had to delete the comment mark in front of the mod_php module in the httpd.conf and restart the apache. VoilĂ .

The phpinfo() told me that there is a PHP in version 5.2.8 with mysql, sqlite, pdo, and many more extensions build in. The other useful information is the location of the php.ini file.

Anything missing?! Damnit yes, I do need the GD libraries.

After some research I fortunately found Marc Liyanage's website about Mac Os X PHP packages. The best of all the packages Marc provide, do include every library I need to develop in PHP 5. Marc wrote an impressive howto leading you through the installation procedures.

!! NOTICE !!

You have to undo the previous made settings to the httpd.conf before installing Marcs' package. If you don't it will probably lead to problems running the apache webserver.

After I followed his instructions not only the PHP version was upgraded, the apache was already configured, too - brilliant!

Last but not least, if you want this PHP setup as the default version - the 'original' PHP is still installed - you need to adapt the $PATH environment variable in your .bashrc or .profile file. Just add the install path of the recently installed PHP followed by a silicolon in front of the '/usr/bin;' in the PATH declaration.

After starting a new terminal

$> php -v

should show the new php version.

Next Session

The next episode of the series will show you how to install and configure the PHP debugger xDebug.

If you like this article, I'd be very pleased if you'd flattr me.

Trackbacks

Comments

Add new comment

Fields with bold names are mandatory.

Blogroll