bioneural.net site preferences

Accessibility

Toggle width/ text size:

style

Default/Alternate

Suits visual impairment, mobile devices

Styling

Change the theme:

layout

NB: may reduce functionality

Link behaviour

Links with an icon are off-site:

links

Right-click any link to optionally open in a new window or tab


Apache 2 + PHP 5 + MySQL 4 under OS X 10.3.9

Following my earlier and (eventually) successful attempt to install PHP for OS X's built-in Apache 1.3 (the version in both Panther and Tiger), MySQL, and WordPress, I decided to have a go at installing an Apache 2 server. Not being overly comfortable with the command line, I first tried several Mac OS X binaries:

Now I'd like to tell you about the Mac OS X Terminal, my new best friend, and how it facilitated a working installation of Apache 2.0.54, PHP 5.0.4, and MySQL 4.1.11...

Web development platform

A clean installation of Mac OS X 10.3.9 with Developer Tools Software installed (as included with Mac OS X Panther) and with all Software Updates applied.

Download and install MySQL 4.1.11-standard

Download MySQL here and follow the installation procedure described under "Update" here.

Once installed, start the MySQL database server.

Download and build Apache 2.0.54

I am indebted to the excellent tutorial on PHPmac for these instructions, which I have modified slightly and illustrated.

Begin by launching Terminal to access the BSD environment. It normally lives within the Utilities folder inside Applications.

terminalicon

At the command prompt, type:

curl -O http://apache.mirrors.esat.net/httpd/httpd-2.0.54.tar.gz

Terminal will begin downloading the file to your Mac:

downloadapache2

Note that you may need to change the version number if 2.0.54 isn't the current version. When the download has finished, unzip it by typing:

gnutar -xzf httpd-2.0.54.tar.gz

Wait a moment until decompression is complete, then type the following commands:

cd httpd-2.0.54
sudo ./configure \
--prefix=/apache2 \
--enable-module=most \
--enable-shared=max

At this point lots of "checking..." lines will appear. Carry on when all the scrolling stops:

sudo make
sudo make install

When you are prompted to enter a password, use your OS X account password.

Download and build PHP 5.0.4

At the command prompt, type:

curl -O http://ie.php.net/distributions/php-5.0.4.tar.gz

When the download has finished, unzip it by typing:

gnutar -xzf php-5.0.4.tar.gz

Wait a moment until decompression is complete, then type the following commands:

cd php-5.0.4
sudo mkdir /apache2/php
./configure \
--prefix=/apache2/php \
--with-zlib \
--with-xml \
--with-mysql=/usr/local/mysql \
--with-apxs2=/apache2/bin/apxs

Once again, at this point lots of "checking..." lines will appear. If all has gone well when the scrolling stops you should see this:

phpcomplete

Now type:

make

Followed by (with password):

sudo make install

Configure Apache

Open the file "httpd.conf" using a text editor (e.g. TextWrangler); it's located in Macintosh HD/apache2/conf/.

You will see this dialogue:

httpdwarn

Click "Yes", then below the current file's contents, add:

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.html index.php

Use search-and-replace to change:

Directory "/apache2/htdocs"

to:

Directory "/Library/WebServer/Documents"

Now change:

UserDir public_html

to:

UserDir Sites

Because this file is owned by root, you will need to authenticate on saving.

Start Apache

First make sure that Personal Web Sharing (built-in Apache 1.3 server) in System Preferences is set to "Off". To start the Apache 2 server type:

sudo /apache2/bin/apachectl start

Exit the Terminal after typing... exit.

Did it work?

Type http://localhost/ into your browser; hopefully you'll see the Apache test page:

apache2ok

Create a text file called "test.php" in your Sites folder, containing the line:

<?php phpinfo() ?>

Now type http://localhost/~your_username/test.php (where your_username is your Mac OS X user name) to check your PHP installation:

php5ok

Update 02.04.06: If this looks like too much work, try MAMP which I can heartily recommend as a self-contained web development environment for Mac OS X. This site was migrated from iBlog, put together and tested using MAMP, then moved wholesale from localhost to a "live" server.

10 responses to Apache 2 + PHP 5 + MySQL 4 under OS X 10.3.9


  1. 1 Jordan Kaufman

    I AM DESPARATE IN NEED OF HELP! I have tryed to run the command:

    
    curl -O http://apache.mirrors.esat.net/httpd/httpd-2.0.54.tar.gz
    

    which seems to work fine but then when I try to decompress it:

    
    gnutar -xzf httpd-2.0.54.tar.gz
    

    it says the following:

    
    jordan-kaufmans-Computer:~ jordankaufman$ gnutar -xzf httpd-2.0.54.tar.gz
    
    gzip: stdin: not in gzip format
    gnutar: Child returned status 1
    gnutar: Error exit delayed from previous errors
    jordan-kaufmans-Computer:~ jordankaufman$
    

    PLEASE HELP

  2. 2 Bruce

    I'm sorry Jordan, but I don't know the answer to that one. I'm no expert in these things, but record here what did work for me to save having to re-discover it should I need the knowledge in future. That's fine when things work as they should, but when there are problems...

    I've since used MAMP which I'd recommend to you as a self-contained server environment (if that's what you need).

    By the way, what's with the capitals?

  3. 3 Jordan Kaufman

    Bruce,

    Thanks for your help. When I couldn't get the command line working I downloaded one of the OS X binaries that your referenced above (Complete Apache 2 (2.0.52) with Complete PHP (4.3.9)) and it worked beautifully for what I needed. It was a one click installation (actually 2 clicks on for apache one for php), so I was only up until 3 AM getting everything done.

    By the way, thanks for the tip about the ALL CAPS. I didn't realized how rude I've been in the past.

    So thanks for posting this page in the first place. Everyone else talked about non-command line binaries but you were the first one who linked to ones that actually worked on my 10.3.9 mac.

    Thanks,
    Jordan

  4. 4 Bruce

    No problem Jordan; glad it all worked out for you in the end.

  5. 5 Luis

    Hi... I know this is old but I'll post it here anyways as it may help someone out there.

    I'm on a MacBook Pro running Tiger.

    First, the problem Jordan had, I go too. I worked around it by simply clicking the download and getting the system figure out how to uncompress it. Simple enough.

    The problem I got was that, after following the instructions outlined here, PHP's ./config returned an error while performing some checks. After looking arround for possible solutions, I realized the "/apache2" directory was not autmatically created when installing apache and therefore, apache was not installed. So, when trying to install PHP, it would throw an error b/c of some missing libraries.

    If you get the same problem simply make sure you create the /apache2 directory and re-run apache's installation steps. It solved my problem.

    See ya...

  6. 6 Bruce

    Luis, thanks for sharing that solution and making the important point that the /apache2 directory must exist prior to an installation attempt.

  7. 7 Jennifer

    Thank you so much for posting this article. It helped me tremendously!

  8. 8 Bob

    One more thank you for directions. I had installed Apache2 & MySQL previously in different locations. Simply changing the paths in your instructions had everything running first try. I was using MAMP until now for PHP, but now I'm set up on my own!

  9. 9 Bruce

    Glad it worked for you Bob. Can I ask why you prefer a DIY installation to MAMP?

  10. 10 scott

    Thanks for a very useful summary. I was having trouble adding mysql to an existing Apache2 + PHP5 install. Your article was great help. I simply needed to configure, make and install php using the "-with" directives you listed. NOTE for others, if your apache and mysql are installed in other locations then modify the configure --with details to suit e.g. instead of --with-apxs2=/apache2/bin/apxs I was able to use my existing apache install directory --with-apxs2=/usr/local/apache/bin/apxs

Something to say?

Comments may be moderated (e.g. no commercial promotion), are subject to spam filtering, and should be relevant to this post—otherwise make contact.

Usable tags include <a href=""> <blockquote> <em>. Select any text and click to quote.