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

Mac OS X 12 Comments

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

Replace the System Drive With a Larger Hard Drive

Windows No Comments

harddriveNormally, to replace a hard drive with a larger hard drive, you would just install the replacement hard drive, copy the data over, and remove the old drive. Very simple. Unfortunately, if the drive you are replacing is the system drive (where the Windows operating system is installed), it gets more complicated.

After living with an 80GB system drive for many years and running out of space repeatedly, I decided to replace it with a 500GB drive. The goal was to do the replacement without re-installing my Windows XP operating system. The secret weapons are BartPE (to generate a bootable CD) and Ghost (to clone the system hard drive).

Create a BartPE bootable Windows XP CD which includes Ghost

  1. Pre-requisites:
    • Symantec/Norton Ghost 8.x (the version I have is 8.2)
    • Windows XP Installation CD
    • CD or DVD Burner drive
  2. Download BartPE builder. I picked the latest “PE Builder v3.1.10a – zip package”.
  3. Unzip the archive (ex: pebuilder3110a.zip) to a directory like “c:\temp\pebuilder”.
  4. Copy the ghost 8.x files to the “c:\temp\pebuilder\plugin\ghost8\files” folder. From my Ghost 8.2 distribution, I copied the following files: ghost32.exe, Ghostexp.exe, Ghostsrv.exe, and GhostCast.chm.
    • BartPE builder expects a file called “Ghostcdr.dll” which did not come with my Ghost 8.2 distribution. I managed to download it from the internet; you can download it from here.
    • Put “Ghostcdr.dll” into the same “c:\temp\pebuilder\plugin\ghost8\files” directory.
  5. Insert the Windows XP installation CD into your CD-ROM drive (say D: drive).
  6. Run “”c:\temp\pebuilder\pebuilder.exe”.
  7. In the first field, “Source: (path to Windows installation files)”, enter the CD-ROM drive letter which contains the Windows XP CD (ex: input “D:\”).
  8. Select “Create ISO image” or “Burn to CD/DVD”. In my case, I selected “Create ISO image” and then later burned the image to a CD using Nero Burning ROM.
    pebuilder.jpg
  9. Click on the “Plugins” button. BartPE builder will verify that your Windows XP CD is accessible and then show a dialog window.
  10. If you want a startup option to boot from the CD or not, then click to select “Boot Fix (Enabling “Press any key to boot from CD”)” and hit the “Enable/Disable” button. The Enabled column value for that entry will change from No to Yes.
  11. Click to select the “Symantec Ghost 8.0” entry at the bottom and hit the “Enable/Disable” button. The Enabled column value will change from No to Yes. If any required Ghost files are missing, clicking the Enable/Disable button will throw an error message.
    pebuilder_plugins.jpg
  12. Hit Close to close the dialog.
  13. Hit the Build button to create the ISO image or burn to CD/DVD.

Replace the System Hard Drive

  1. Shutdown the computer and install the replacement hard drive. Feel free to re-arrange the drives to connect the replacement hard drive to the first SATA or IDE interface.
    • If you have extra drives, to be on the safe side, you might want to connect only the system drive and the replacement hard drive.
    • Take note of the hard drive sizes so you can distinguish them later on.
  2. Boot the computer with the BartPE bootable CD that was created above.
  3. As BartPE loads, answer No to the “Start Network Support” prompt.
  4. Once BartPE has finished loading, select menu “Go->Programs->Symantic Ghost v8” and launch “Ghost32”.
  5. In the Ghost program window, select menu “Local->Disk->To Disk”.
  6. Select the Source Disk/Drive by clicking it and hit Ok. You can distinguish the source hard drive from the replacement drive by the smaller size information.
  7. Select the Destination Disk/Drive and hit Ok. The destination drive will be your replacement hard drive which should have a larger size information.
  8. Keep the default size selection and hit Ok.
  9. Double-check the source and destination drive info and click Yes to proceed with the disk cloning. Ghost will start cloning the hard drives. (It took 30 minutes for Ghost to clone my nearly full 80GB drive to the replacement 500GB drive.)
  10. Ghost will complete the process with a “Clone Completed Successfully” message.
  11. Hit Continue, Quit, and select menu Go->Shutdown to shutdown the computer.
  12. Remove the old system drive and make sure that your new replacement system drive is connected to the first SATA or IDE interface (which the BIOS will use as the boot drive). Or simply, connect the replacement hard drive to the interface cable that the old system drive was attached to.
  13. Start the computer and everything should work exactly the same as before, except now you have a lot of free space. Good luck!

Some content above derived from Setup Bart PE and Ghost How to.

No Comments