Skip to content

Install Apache, PHP, MySQL, and phpMyAdmin on Mac OS X 10.6 Snow Leopard

mac-os-x-snow-leopardMac OS X 10.6 Snow Leopard comes with Apache and PHP installed by default. However, the Apache HTTP server is not configured to use PHP and is not set to run by default. This post will provide instructions on configuring and starting the built-in Apache server. In addition, this post will provide instructions to install MySQL Server and phpMyAdmin.

Enable PHP and Start the Apache HTTP Server

  1. Make sure that PHP support is enabled on Apache
    • Open “/etc/apache2/httpd.conf” and search for:
      #LoadModule php5_module        libexec/apache2/libphp5.so
    • Uncomment the line by removing the # character at the beginning.
    • Save the changes.
  2. Start the Apache Server
    • Go to System Preferences > Sharing and check/uncheck Web Sharing to start/stop Apache server. Note that this setting will persist even if you reboot the mac.
    • Or by command line, execute either of the following commands:
      sudo apachectl start
      sudo apachectl restart
  3. The Apache docroot is set to the “/Library/WebServer/Documents/” folder. In addition, a relative home page (ex: http://localhost/~yourusername”) is set to the “~/Sites” or “/Users/yourusername/Sites” folder.
  4. To verify that PHP is working under Apache, create a file “/Library/WebServer/Documents/phpinfo.php” with the following content:
    <?php
    // Show all information on PHP
    phpinfo();
    ?>
  5. Browse to the PHP info script using http://localhost/phpinfo.php. You should see a bunch of info concerning your PHP installation if Apache is configured to use PHP correctly.
  6. If you have problems, check the Apache “error_log” in the “/var/log/apache2” directory.

Install and Start MySQL Server

  1. Download the latest MySQL Server distribution; I selected the “Mac OS X ver. 10.6 (x86, 32-bit), DMG Archive” package.
  2. Double-click to mount the “mysql-5.1.46-osx10.6-x86.dmg” downloaded disk image file. Double-click on the resulting “mysql-5.1.46-osx10.6-x86.pkg” package file to install MySQL Server.
  3. The MySQL Server will be installed under the “/usr/local/mysql-5.1.46-osx10.6-x86” directory. In addition, a symbolic link to that directory is created as “/usr/local/mysql”.
  4. Install the “MySQLStartupItem.pkg” package file also to facilitate starting and stopping the MySQL Server. This will also configure MySQL Server to start on bootup.
  5. Start the MySQL server by running “sudo /Library/StartupItems/MySQLCOM/MySQLCOM start”. (You may be prompted to input a password; this password is the Mac OS X admin password, not the MySql root password which is blank by default.) Later, you can stop the MySQL Server with “sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop”.
  6. Add the following line to the end of your “~/.profile” to facilitate executing mysql commands:
    export PATH=$PATH:/usr/local/mysql/bin
  7. Connect to the MySQL Server by trying out these commands in a terminal:
    mysql -u root --version
    mysql -u root -p
    mysql> show databases;
    mysql> use mysql;
    mysql> show tables;
    mysql> quit

Install phpMyAdmin

  1. phpMyAdmin requires that the PHP mcrypt extension be installed for performance and for 64-bit operating systems such as Snow Leopard. We will have to compile it from source.
    • I think you will need to install Xcode from Apple in order to compile the mcrypt extension. If you run into problems below without Xcode, try installing Xcode and then repeating the procedure.
    • Download the latest libmcrypt .
      • Unpack the downloaded file “libmcrypt-2.5.8.tar.gz” by double-clicking it in the ~/Downloads directory.
      • Run the following commands in a terminal:
        cd ~/Downloads/libmcrypt-2.5.8/
        ./configure --disable-posix-threads --enable-static
        make
        sudo make install
      • Input your Mac OS X root password if you are prompted to input a password.
    • Download the PHP source code so we can generate the mcrypt PHP extension.
      • First determine your currently installed PHP version by opening Terminal and running “php -version”.
      • Unfortunately for me, the latest PHP source version on the website is 5.3.2 and my installed version is 5.3.1. To get the source for my specific version, I copied the link out, which is “http://www.php.net/get/php-5.3.2.tar.bz2/from/a/mirror”.
      • I manually edited the link to change “5.3.2.tar” to “5.3.1.tar”, pasted the modified link back into the browser, and downloaded the source for 5.3.1.
      • Unpack the downloaded file “php-5.3.1.tar.bz2” by double-clicking it in the ~/Downloads directory.
      • Run the following commands in a terminal:
        cd ~/Downloads/php-5.3.1/ext/mcrypt
        phpize
        ./configure
        make
        cd modules
        sudo cp mcrypt.so /usr/lib/php/extensions/no-debug-non-zts-20090626/
      • Input your Mac OS X root password if you are prompted to input a password.
    • Configure PHP to load the mcrypt extension.
      • Create the “/etc/php.ini” file if it doesn’t already exists (copy from “/etc/php.ini.default”) and edit it.
        cd /etc
        sudo cp php.ini.default php.ini
        sudo vi php.ini
      • Input your Mac OS X root password if you are prompted to input a password.
      • Search for “;extension=” in php.ini. When you find the “Dynamic Extensions” section, add the following line to the end of that section like so:
        ;extension=php_xsl.dll
        ;extension=php_zip.dll
        extension=mcrypt.so
      • MySQL Server under Mac OS X puts its socket file under “/tmp/mysql.sock”. We’ll need to adjust the php.ini to point at this location instead of the default “/var/mysql/mysql.sock”. Search for and set the following variables in php.ini:
        pdo_mysql.default_socket=/tmp/mysql.sock
        mysql.default_socket = /tmp/mysql.sock
        mysqli.default_socket = /tmp/mysql.sock
      • Enable php error logging by searching for and enabling these variables in php.ini:
        error_log = /tmp/php_errors
      • Do not create the php_errors file; PHP will create it with the appropriate permissions. Note that putting php_errors log file in a directory other than the “/tmp” directory (like “/var/log/apache2”) may not work due to permission issues.
    • Restart the apache server by running the “sudo apachectl graceful” command.
    • Browse to the PHP info script using http://localhost/phpinfo.php. Search for “mcrypt” and you will now see a section containing info concerning it. You should see that the “mcrypt support” row has an “enabled” value. phpinfo_mcrypt.png
    • Search for “mysql” and double-check that three “default_socket” variables are using “/tmp/mysql.sock”, instead of the default “var/mysql/mysql.sock”. phpinfo_msock.png
  2. Download the latest phpMyAdmin.
  3. Unpack the downloaded file “phpMyAdmin-3.3.3-english.zip” by double-clicking it in the ~/Downloads directory.
  4. Copy the resulting “phpMyAdmin-3.3.3-english” folder to “/Library/WebServer/Documents”. I suggest renaming the folder to just “phpMyAdmin”.
  5. Make a copy of “/Library/WebServer/Documents/phpMyAdmin/config.sample.inc.php” in the same directory and name the copy as “config.inc.php”.
  6. Edit “config.inc.php” and change the “AllowNoPassword” variable to true. This will allow us to login with MySQL user “root” and a blank password.
    $cfg['Servers'][$i]['AllowNoPassword'] = true;
  7. Browse to http://localhost/phpMyAdmin/. Log in with user “root” and leave the password field blank.

Alternatively, you could just use XAMPP or MAMP which also includes MySQL. However, I have a preference not to install software if I don’t have to.

Content above derived from the following online resources:

12 Comments

  1. Dave

    Thanks so much!! I was looking all over the past couple days and this is what finally worked for me. I already had PHP 5.3.1 installed and was getting the missing mcrypt error in phpMyAdmin. This did the trick! Cheers!!!

    Now I just need to figure out how to activate the additional features for working with linked tables, not that I’m even sure that or mcrypt, but it’s nice to see that message go away in phpMyAdmin.

  2. Thanks for the guide.

    For some reason my phpinfo is now only displaying a blank white page after trying your steps to install the mcrypt extension.

    No php error log in tmp either. Any suggestions? I had never “maked” before and had to install xcode to compile. Wondering if that fdup my php.

    Also cd ~/Downloads/php-5.3.0/ext/mcrypt
    should read cd ~/Downloads/php-5.3.1/ext/mcrypt

    THX

    • Chanh

      Thanks for the catch about 5.3.0. I corrected it.

      If you don’t see any error logs, then I would suggest commenting out the changes you have made and then adding them back in one by one, each time trying the phpinfo. When you get the point where you see the blank phpinfo page, then most likely, the last change is where the issue is.

      I don’t think the make should corrupt your system or apache/PHP as it only makes the mcrypt library. Good catch on having to install xcode… I had it pre-installed so didn’t noticed.

  3. Gareth

    I get as far as downloading the libmcrypt file, unpacking it, but when I get to the step:

    ./configure –disable-posix-threads –enable-static

    I get the following error:

    C++ compiler default output file name… configure: error: C++ compiler cannot create executables

    The “Make” and “sudo make install” commands then don’t work. Any suggestions?!

    • Chanh

      Hi Gareth, do you have Xcode installed? I think that the mcrypt make requires Xcode. You can download it from Apple; I have updated the instructions with the link to Xcode above. Regards.

  4. Yeah! You save my life.

  5. thank you so much u save my day from less sleeping ^^…. an it is works with virtual host too :-BD

  6. Dave

    Muchas Gracias!

    I tried 4 tutorials before yours and screwed up my whole php/mysql-Setup. After setting everything back to normal i followed your steps – and – hooray – it works! I never got mcrypt to work 🙂

    You, sir, are truly legendary.

    Br

  7. daniel

    you’re rock man…
    really cool

  8. steve bryson

    Seriously good guide, easy to follow and well written.

    Thank you, saved me a lot of research and time.

    • Chanh

      I’m glad it was helpful and really appreciate all the thank-you’s from everyone.

  9. bo

    Hi, I have an error I do not understand while using the make command:

    /Users/bo/Desktop/php-5.3.15/ext/mcrypt/mcrypt.c:283: error: ‘PHP_FE_END’ undeclared here (not in a function)
    make: *** [mcrypt.lo] Error 1

    .. and the modules folder is empty so I cannot copy the mcrypt.so file…

    Any help will be appreciated.

    I am using XCode version 4.2 Build 4C199 on a Mac OS X 10.6.8

Leave a Reply

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