Home > Computers, Featured, Guides > Setting Up Apache, MySQL and PHP on OS X Leopard

Setting Up Apache, MySQL and PHP on OS X Leopard

January 3rd, 2009

mampI recently had to setup MySQL on Mac OS X Leopard (I was using 10.5.6). I can never find a guide that gets Apache, MySQL and PHP working using the binaries that come packaged with Leopard. I also don’t like using pre-packaged installers like XAMPP and MAMP. This guide is intended for advanced users as very little explanation is given for each step.

Please add a comment if you have any suggestions for improvement.

Apache

Apache comes with Leopard. Enable it by going to System Preferences > Sharing > check “Web Sharing”

Edit /etc/apache2/httpd.conf in your favorite text editor.
To change your root web directory from the default (/Library/WebServer/Documents), Modify your DocumentRoot on line 163:

DocumentRoot "/Users/yourUserNameHere/workspace"

… and change your Directory settings near line 190:


   ...
   AllowOverride All
   ...

To activate the PHP module, uncomment this near line 114:

LoadModule php5_module libexec/apache2/libphp5.so 

… and add this near line 383 to make Apache handle .php files:

AddType application/x-httpd-php .php

MySQL

Download and install MySQL. Install the MySQLStartupItem.pkg package as well. Go to System Preferences > MySQL, start MySQL and check the box to “Automatically Start MySQL Server on Startup”.

Change the MySQL root password:

$ mysqladmin -u root password NEWPASSWORD

Fix permissions for root account

$ mysql -u root -p
mysql> grant all on *.* to 'root'@'%' identified by 'NEWPASSWORD';

Fix the missing mysql.sock file:

$ sudo mkdir /var/mysql
$ sudo chown _mysql /var/mysql
$ sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

PHP

PHP is already installed at /user/bin/php.

Create a configuration file:

$ sudo cp /etc/php.ini.default /etc/php.ini

phpMyAdmin

Download phpMyAdmin and extract it to ~/workspace/pma. Rename config.sample.inc.php to config.inc.php and open it in a text editor.

Near line 17, change your blowfish secret.

PEAR

$ curl http://pear.php.net/go-pear > go-pear.php
$ sudo php -q go-pear.php
$ sudo mkdir /usr/bin/pear

In the installer, choose to edit option and change it to /usr/bin/pear

Edit line 469 in /etc/php.ini to add PEAR to PHP’s include path:

include_path = ".:/usr/bin/pear"

Sources

Guides I used to get this all straightened out

Computers, Featured, Guides , , , , , ,

  1. Dipesh
    February 6th, 2009 at 13:20 | #1

    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.

  2. Steven
    February 28th, 2009 at 12:58 | #2

    Hi,
    I just finished installing Apache, PHP and MySQL 5.1.31 on Mac OS 10.5.6.
    Everythings worked fine, except a little 403 error (permissions..).
    Thanks.

  3. bahodir
    March 19th, 2009 at 10:37 | #3

    Hi, thanx for a great tutorial.
    I just want to add that I found sequel pro (www.sequelpro.com) to be a better alternative to phpmyadmin.

  4. Auzigog
    April 28th, 2009 at 00:08 | #4
  5. Jono
    May 12th, 2009 at 00:48 | #5

    You are the man! Took me a while to get this going but finally worked with your tutorial. Only thing that hooked me up was the MySQL path problem… was getting this

    -bash: mysqladmin: command not found

    which was easily fixed by running…

    export PATH=$PATH:/usr/local/mysql/bin

    Thanks heaps man! It works perfectly.

  6. James
    October 20th, 2010 at 12:36 | #6

    You’re instructions are missing a step.

    Must double click MySQLPrefPane before you can “Automatically Start MySQL Server on Startup”.

  1. April 27th, 2009 at 00:51 | #1