Installing Apache, MySQL and PHP on Leopard

Update 11/08/12: For an up-to-date guide as to how to install Apache, MySQL and PHP on OSX 10.8 Mountain Lion, I would like to refer you to you Neil Gee's excellent guide.

Working in Web Development means you have to have a development environment installed on your local machine, in order to test and develop dynamic pages, using a web server (Apache,), a database (MySQL) and a scripting language (PHP). There are ways of getting those components installed in a bundle, like WAMP, LAMP or MAMP. But as a developer, you are more the manual type, right? So as I had to go through that installation process recently, this article documents the steps I went through.

Apache

OSX already comes with Apache installed, it is just a matter of starting the server. You can do this if you go to System Preferences > Sharing and check “Web Sharing”. The Apache default page should now be displayed at

http://localhost

Later on, you can use the following commands to start, stop or restart Apache:

$ sudo apachectl start
$ sudo apachectl stop
$ sudo apachectl restart

If you would like to change the DocumentRoot of the server, you need to edit the httpd.conf file:

$ sudo vi /etc/apache2/httpd.conf

In here, you need to change the DocumentRoot setting:

DocumentRoot "/Users/myUser/myNewWebroot/"
<Directory "/Users/myUser/myNewWebroot/">
...
</Directory>

PHP

PHP comes bundled up with Leopard as well. The important things to know here are where it got installed and where to find the configuration file.

Most likely, it got installed to:

/usr/local/php5

The configuration file should be located at:

/private/etc/php.ini

You only need to make sure that Apache knows that PHP is available, so edit httpd.conf:
$ sudo vi /etc/apache2/httpd.conf

And add the following lines (in the appropriate sections, to keep things tidy):

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

LoadModule php5_module libexec/apache2/libphp5.so

Finished with that, restart Apache, empty the browser cache and then load a php file for testing if it is correctly interpreted.

MySQL

Download the most recent dmg image from the MySQL site.

Before actually installing MySQL, I found it helps to restart the computer before proceeding with the installation. When running through the installation wizard, MySQL will get installed to:

/usr/local/mysql-VERSION

So, for example:

/usr/local/mysql-5.0.51b-osx10.5-x86/

Also, a symlink should have been created:

/usr/local/mysql -> mysql-5.0.51b-osx10.5-x86

You should also install the Preference Pane, which comes with the installation package as MySQL.prefPane

To start MySQL manually, run the following command:
$ sudo /Library/StartupItems/MySQLCOM/MySQLCOM start

You should also add MySQL to $PATH:
$ vi ~/.profile
$ export PATH=$PATH:/usr/local/mysql/bin
$ source ~/.profile

To check whether that was successful, run:
$ echo $PATH

The default settings for the root user are:

  • Username: root
  • Password: [leave blank]

Add-on: PHPmyAdmin

To get PHPmyAdmin installed, which comes in handy for managing your database(s), download the latest package from their download page. Extract that package to a directory somewhere in your DocumentRoot.

Open config.sample.inc.php with an editor of your choice and add the following details for your MySQL installation:

/*
 * This is needed for cookie based authentication to encrypt password in
 * cookie
 */
$cfg['blowfish_secret'] = 'whatever'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

$cfg['Servers'][$i]['user']          = 'root';
$cfg['Servers'][$i]['password']      = ''; // use here your password

After you made those changes, save the file as config.inc.php.

PEAR

PEAR should also already be available on your Mac. The location is probably:

/usr/local/php5/bin/pear

It is a good idea to add the path to PEAR to $PATH, similar to setting the path for MySQL (see above). In addition, upgrade PEAR to the latest version like so:

$ sudo pear channel-update pear.php.net
$ sudo pear upgrade PEAR

Resources

23 Comments on “Installing Apache, MySQL and PHP on Leopard

  1. Thanks for linking to my site. I would like to point out that there is a new site with more up to date information on the subject. It’s also run by me and I’m kepping the new one up to date, the old one is still there but more as a reference.

  2. hey Klaus! alles roger!?`
    ich schreib grad das 2.te mal weil dein Formular beim Abschicken meinen Text gekillt hat nur weil ich keine email eingetragen hatte… :)
    Nützlicher Eintrag von Dir hier! Bin grad auch am Mac-Apache hacken… damit ich ein paar htaccess und mod-rewrite Geschichten lokal testen kann. Mamp hat da in der Tat rumgezickt. Bin jetzt übrigens auch zum Coder mutiert… allerdings hauptsächlich Actionscript… Also machs gut! beste grüße, Flo

  3. Pingback: Setting Up Apache, MySQL and PHP on OS X Leopard • Blog Archive • Blog of Auzigog

  4. Hello, after getting phpadmin up & running, I get the message:

    “Cannot load mcrypt extension. Please check your PHP configuration.”

    Do you see this and is it of any consequence?

    Thanks – any guidance is greatly appreciated.

    Cheers,
    Dipesh.

  5. Hi, Great guide, PHP works but after installing Mysql and pma I get the same error as @Dipesh and an Access Denied message.

  6. Hey there,

    I tried following your instructions, but ran into a hiccup:
    $ sudo /Library/StartupItems/MySQLCOM/MySQLCOM start

    That doesn’t run properly. Infact, StartupItems has nothing in it. Every step before that worked without a problem.

    Was/is XCode required for all of this to work?

  7. Woops.
    Make sure you double click the startup package. That fixed my problem.

  8. For phpMyAdmin — “Extract that package to a directory somewhere in your DocumentRoot.”

    I’m on an iMac running OS X 10.5.6. DocumentRoot for me is apparently /Library/Webserver/Documents

    What does ” … to a directory somewhere in your DocumentRoot” mean exactly? Do I need to create a phpMyAdmin directory and extract the files there?

    Thanks for your help. I’m new at this kind of thing.

  9. @Ed:
    Copy the phpMyAdmin directory to /Library/WebServer/Documents/phpMyAdmin if you want it to be accessed by all users, or just put it in your “Sites” folder so only you can access it.

  10. Pingback: Setting Up a Flash Development Sandbox: Part 2 | Free Tutorial 4 All

  11. Pingback: Kfirlog » Blog Archive » Installing Apache2, PHP5 and MySQL5 on OS X Tiger

  12. Pingback: Apache PHP MySQL na Mac OS X | Sławomir Jasiński

  13. Pingback: Andrew Colclough

  14. Pingback: The Three Golden Rules of Site Redesigns

  15. Pingback: The Three Golden Rules of Site Redesigns « gabriel catalano | in-perfección

  16. Pingback: The Three Golden Rules of Site Redesigns | MarketingTypo.com

  17. Pingback: The Three Golden Rules of Site Redesigns «

  18. Pingback: PHP, MySQL, PHPAdmin, PEAR – Manual Installation « Bernard's Technocratic Blog

  19. Pingback: Three Golden Rules of Site Redesigns | Kappa Techie's Tips and Tricks

  20. Might want to update that link to “the most recent version of MySQL”, as it points to a very non-recent version (5.0.x, while the current version ATM is the 5.5.x branch).

    Cheers! :)

  21. @Daniel: Thanks for pointing it out. I updated the post with a more generic link to the MySQL download site (instead of having to keep it up to date with every new version).

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>