sterlinganderson.net

26 Oct, 2006

Setting up your Mac for PHP web development.

Posted by: sterling In: Development

I found myself again having to install necessary web development tools on my MacBook Pro so I thought this time I’d actually document the process. After following these instructions your machine should be pretty well equipped for PHP web development. I had instructions for Ruby on Rails in here, but I’ll post those as a separate entry later.

Before you going any further you must have Xcode installed. You can get the most recent version from Apple here:
http://developer.apple.com/tools/xcode/

What we will be installing:
MySQL
Apache 2.2.3
Subversion
PHP 5.1.6
Before we do anything there is a variable that must be set for later on when we set up Apache and Subversion. Run the following command assuming you are using the bash shell that the OS X Terminal app uses by default:

$ ac_cv_func_poll=no; export ac_cv_func_poll

This sets the environment variable ac_cv_func_poll to no. If you are using a different shell the command would be different. It’s a good idea to keep all the source code you download in the same place. I place all mine in /usr/local/src/. Open a terminal and create that directory:

$ sudo mkdir /usr/local/src
$ sudo chown root:admin /usr/local/src
$ sudo chmod g+wrx /usr/local/src

The second and third lines give your admin group permission to the folder. You’ll be able to stick your source in there without having to use sudo for absolutely everything.
MySQL

This is nice and easy. Just go here and grab the latest version of MySQL 5.0. You most likely want to standard installer, unless you really know what you are doing. Install the database, the start up item, and the pref pane item.
Apache 2.2.3

I’ve created an OS X startup item that can be downloaded from this web site.

$ curl -O http://sterlinganderson.net/assets/2007/5/2/apache2startupitem.tar.gz
$ tar zxvf apachestartupitemtar.gz
$ cd apache2startupitem
$ sudo ./install.sh
$ cd ..

You also need to edit /etc/hostconfig. Add the following line: APACHE2WEBSERVER=YES Change to APACHE2WEBSERVER=NO to disable the startup item.

Subversion Server

Apache needs to be installed first. So if you skipped Apache go back and install it now.

$ curl -O http://subversion.tigris.org/downloads/subversion-1.4.0.tar.gz
$ tar zxvf subversion-1.4.0.tar.gz
$ curl -O http://www.webdav.org/neon/neon-0.25.5.tar.gz
$ tar zxvf neon-0.25.5.tar.gz
$ mv neon-0.25.5 subversion-1.4.3/neon
$ cd subversion-1.4.0/
$ ./configure --prefix=/usr/local --with-apr=/usr/local/apache2/ \
--with-apr-util=/usr/local/apache2/ --with-apxs=/usr/local/apache2/bin/apxs \
--with-ssl
$ make
$ sudo make install
$ cd ..

PHP 5.1.6

MySQL and Apache need to be installed first.

$ curl -O http://us2.php.net/distributions/php-5.1.6.tar.gz
$ tar zxvf php-5.1.6.tar.gz
$ cd php-5.1.6
$ ./configure --prefix=/usr/local/php5 --with-zlib --with-xml --with-gd \
--with-jpeg-dir=/usr/local --with-png-dir=/usr/local \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache2/bin/apxs \
--with-ldap --enable-thread-safety
$ make
$ sudo make install
$ cd ..

Configuration

We now need to edit the configuration files for Apache and PHP. Open /usr/local/apache2/conf/httpd.conf in an editor. Change the User and Group from daemon to www. This should be around lines 125 and 126. I also change the DocumentRoot(line 162) to my Sites directory. If you change the DocumentRoot make sure you change which is about 25 to your changed DocumentRoot. Change the code at line 223 from:


DirectoryIndex index.html

to


DirectoryIndex index.html

DirectoryIndex index.html index.php

We need to tell Apache to respect PHP file types if PHP is enabled (around line 390):


# If php is turned on, we repsect .php and .phps files.
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

For PHP do the following:

$ sudo cp /usr/local/src/php-5.1.6/php.ini-recommended /usr/local/php5/etc/php.ini

Edit /usr/local/php5/etc/php.ini, find the line that says display_errors = Off and change it to display_errors = On
The easiest way to get everything started is just to reboot. Now you are set to do some PHP web development on your Mac.

You’ve probably noticed I didn’t do anything with Subversion. I’ll post something on setting that up in the future.

3 Responses to "Setting up your Mac for PHP web development."

1 | Damon Stephenson

November 22nd, 2006 at 5:22 pm

Avatar

Hello, I tried to install svn. It moaned about me not habing berkley db installed… so I think something up there!

2 | sterling

November 23rd, 2006 at 2:37 am

Avatar

It may say something about Berkley DB not being installed, but you can safely ignore that.

3 | Tom

November 25th, 2006 at 2:15 pm

Avatar

Great article, very quick, clear and concise. Thanks for the Apache2 startup script too, it was just what I was looking for.

Comment Form

-->

Where Am I?

    Twinflower Dr, Madison, WI


What I'm Doing...

  • @dlanham You art is always just great. Thanksgiving Rocks is another win. 5 hrs ago
  • @frenzic I know you just came out, but is there going to be a way to merge my iPhone account and Mac account on web site? 1 day ago
  • 3 season of IT Crowd is starting up! http://tinyurl.com/642tp9 1 day ago
  • I accepted a new job yesterday. Coincidentally, I don't have that usual dread getting ready for work this morning... 1 day ago
  • @y0mbo Because Tina Fey was HILARIOUS. MSM wasn't running SNL clips 24/7. SNL kept it up because their ratings jumped. 2 days ago
  • More updates...