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

Mac OS X 3 Comments

Mac 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
    show databases;
    use mysql;
    show tables;
    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.
    • 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:

Installing Eclipse with Subversion for PHP and Javascript Development on Mac OS X

Mac OS X 3 Comments

Mac OS X 10.6 Snow Leopard comes with the 64bit version of Java 1.6 installed by default. Unfortunately, Eclipse 32bit and older subeclipse plugins are not 100% compatible with the 64bit version of Java 1.6. You may encounter errors when using Eclipse such as “Unable to load default SVN client” (which can be solved by installing JavaHL), and an unknown exception when creating a “project from svn” (you’ll need Eclipse 64bit to fix this). The best, simplest solution is to get the latest version of Eclipse Cocoa 64bit for Mac OS X, codenamed Galileo.

Installing JavaHL Library (Pre-requiste for Subclipse)

In order for subclipse to work on your Mac OS X machine, you will need to download and install the JavaHL which provides a JNI binding layer from Java to the subversion binaries. The quickest way is to just install the latest subversion binaries, which includes the JavaHL library.

  1. Double-check what is installed on your Mac OS X by opening a Terminal and running the following:
    java -version
    svn --version
    ls /Library/Java/Extensions
    

    The last should show a symbolic link to the JavaHL library if you have a version installed.

  2. To install the latest subversion and JavaHL, go to Collabnet Website.
  3. Select the appropriate subversion binaries for your Mac OS X version; currently “Subversion 1.6.9 Universal”.
  4. You can leave the contact info form blank and just hit the Submit button to download the .dmg image (ex: Subversion-1.6.9-10.6.x.dmg)
  5. Check that the /opt directory (which is a symbolic link to “/private/opt”) exists. If not, you can create it by running this command:
    sudo ln -s /private/opt /opt
    
  6. Launch the .dmg image and double-click on the subversion icon to install the binaries into the default “/opt/subversion” directory.
  7. Once installed, you will need to prepend “/opt/subversion/bin” to your PATH environment variable. Open up your bash environment profile “~/.profile” and add this line:
    export PATH=/opt/subversion/bin:$PATH
    

    Note that the path separator is a colon, not a semi-colon (used by Windows).

  8. Double-check that the JavaHL library is accessible. You should find a symbolic link (ex: “libsvnjavahl-1.jnilib”) for the JavaHL library in the “/Library/Java/Extensions” directory. This is the global location that the Mac OS X JVM will look for when loading libraries via JNI.

Install Eclipse Cocoa 64bit

  1. Get the Mac OS X Cocoa 64bit version of Eclipse.
    • Go to the Eclipse Downloads page.
    • Find “Eclipse IDE for Java Developers” and click on the Mac Cocoa 64bit link to the right.
  2. Unzip the downloaded .gz archive and copy the resulting expanded eclipse directory to your /Applications directory.
  3. Go to the “/Applications/eclipse” directory and run the “eclipse” program.
  4. Install Subclipse for Subversion integration
    • Go to Eclipse menu Help->Install New Software…
    • Input “http://subclipse.tigris.org/update_1.6.x” into the “Work with” field and the table will be updated with installation packages available at that location.
    • Check just the Subclipse package and keep clicking Next until the end. Half-way through, you will be asked to accept the license agreement.
    • If you wish Eclipse to remember the URL, hit the Add button and name it “Subclipse”.
  5. Install PHPEclipse, also known as PHP Development Tool (PDT), for PHP Development
    • Input “http://update.phpeclipse.net/update/stable/1.2.x” (evidently, “http://phpeclipse.sourceforge.net/update/stable/1.2.x/” is the same URL) into the “Work with” field.
    • Just pick PHPEclipse. If you want to debug, install DBG or XDebug. (I haven’t tried XDebug yet so I can’t recommend DBG over it.)
  6. Install JSDT (Javascript Development Tool) for Javascript Development
    • JSDT is a part of the Eclipse Web Tools Platform (WTP) repository. Input “http://download.eclipse.org/webtools/updates” into the “Work with” field.
    • Locate (but don’t check) the latest WTP (Web Tools Platform); currently “Web Tools Platform (WTP) 3.1.2″.
    • Click on the right-facing arrow (to the immediate right of the checkbox) to expand the packages inside the WTP.
    • Check just the “Javascript Development Tools” and click Next, etc.

Uninstalling Subversion and Eclipse

  • To uninstall Subversion, just remove the “/opt/subversion” directory, remove the /Library/Receipts/Subversion-1.6.9.pkg directory, and delete the JavaHL symbolic link at “/Library/Java/Extensions/libsvnjavahl-1.jnilib”.
  • To uninstall Eclipse, just remove the “/Applications/eclipse” directory.

Migrating from Windows XP to Mac OS X

Mac OS X No Comments

Recently, I got a Macbook Pro. It was high time to migrate away from the Windows XP running on my trusty but old Lenovo Thinkpad T60. I have to say it was interesting moving from Windows XP to Mac OS X 10.6 Snow Leopard. Below are some of the tips I recorded as I went through the process.

Configuring the Trackpad

For Windows two-button mouse users, the first thing to get used to is the Mac’s one-button mouse. The Macbook Pro’s trackpad is large and acts like a left-click button. There doesn’t appear to be a separate right-click button. How the heck does that work? The right-click button can actually be activated by tapping the trackpad with two fingers simultaneously or by clicking the trackpad’s button while holding the Control key down. Alternatively, the trackpad supports enabling a bottom-right corner click if you want the physical sensation of pressing a right-click button.

  1. Go to the apple icon (top-left), System Preferences, Hardware section, Trackpad
  2. Under “One Finger” section, check the “Secondary Click (Bottom Right Corner)” to enabling right-click by physically clicking on the bottom-right corner.
  3. Optionally, if you want to disable the two-finger right-click tap, you can just unselect “Secondary Tap” under the “Two Fingers” section.

When I first used the Mac trackpad, it was very stiff and required a lot of pressure to depress. Besides, I was used to the tap click support on my Thinkpad’s trackpad. To enable the tap click and other trackpad options on the Mac, do the following:

  1. Go to the apple icon, System Preferences, Hardware section, Trackpad
  2. Under the “One Finger” section, check the “Tap to Click” option.
  3. Also, check “Dragging” if you want to tap twice to drag.

Once I did the above, both the tap click and double-tap drag operations act the same on the Mac as on my Thinkpad laptop. Most importantly, my fore finger is saved from getting bruised.

Locking your Mac Laptop

Windows supports a Lock Windows feature which forces a login before someone can use your machine again. Under the Mac, the closest equivalent is to use the Screensaver which forces a login when stopped (by default).

  1. Go to the apple icon, System Preferences, Personal, Desktop & Screen Saver
  2. Select “Screen Saver” tab, click on “Hot Corners…” button on lower-left
  3. Click on the selection-box next to the bottom-right corner and select “Start Screen Saver”
  4. Click Ok

To lock your Mac, just move the mouse pointer to the bottom-right corner to activate the screen saver.

Location of Applications and Utilities

Windows has File Explorer, while the Mac has the Finder. The Mac uses the Finder application to explore the hard drive. The Finder can be launched from the dock; look for the blue/grey split face icon, usually it is the leftmost icon on the dock. The Finder is also launched if you open up any folder on your desktop.

The Finder doesn’t show the exact directory path of files and folders. To see the path, just select the file or folder, do a right-click, select Get Info, and the parent folder info will be shown in the Where field. You will see that all your files and folders will be located under your home directory, which looks like “/Users/yourname”.

The applications are located under the Application folder. Just find your program, select its icon, and then double-click on the icon to launch the program. Under the Application folder, there is a Utilities folder which contains some useful programs, such as the Terminal which is similar to the Command Prompt on Windows.

One Application Menu to Rule Them All

Strangely, on the Mac, there is only one application menu visible at any time and that is the menu bar located at the top of the screen with the apple icon. This menu will change to become the menu of the application which currently has the focus. The apple icon will always remain in the left-most position in the menu though. To the immediate right of the apple icon, the current program’s name is displayed as the program’s primary submenu; you can find the About and Preferences under this primary submenu.

Really Quitting an Application

Stranger still, when you close a program window, the program doesn’t quit; though there are some very rare programs which will really quit. You can tell that a program is still running by looking for a little blue light underneath the program’s icon in the dock. To quit a program, you can give focus to the program, click on the program’s name in the top menu, and select Quit. Alternatively, you can right-click on the program’s icon on the dock and select Quit.

If you’re a keyboard nut, just use the Command + Q shortcut to quit the current program with the focus and its name in the top menu bar.

Tabbing Between Applications

Unlike Windows, the Mac OS X has two levels of tabbing between open applications. The first is between different application types using the Command + Tab keyboard shortcut (like in Windows). The second is between different windows belonging to a single application type (the application currently selected with its menu showing on the top menu bar). The second level tabbing can be performed by using the Command + ` keyboard shortcut. The ` or ~ key is right above the Tab key.

Configuring Wireless Access

Wireless configuration on the Mac is as simple as the Windows wireless configuration if we avoid getting fancy. To configure wireless:

  1. Go to Apple icon, System Preferences…, and Network
  2. Click on the lockbox in the lower-left corner and input your password to allow changes
  3. Select AirPort on the left and click on the Advanced… button on the right.
  4. Click on the plus icon right under the Preferred Networks listbox
  5. Click on “Show Networks” and select an existing wireless network. Or just input the network name and security type.
  6. Input the requested wireless network password.
  7. Close the System Preferences dialog and subdialogs.
  8. Left-click on the Airport icon on the top right and select “Turn Airport Off”.
  9. Repeat and select “Turn Airport On”. The mac will then connect to the wireless network that you have just configured.

Select, Copy and Paste Keyboard Shortcuts

The select, copy and paste keyboard shortcuts work almost the same on the Mac as on Windows. Here are the common shortcuts on the Mac:

Action Shortcut(s)
Select a character to the right/left shift + right/left arrow key
Select a word to the right/left shift + option + right/left arrow key
Select to the end/beginning of the line shift + control/command + right/left arrow key
Select line above/below shift + up/down arrow key
Select to beginning/end of document shift + command + up/down arrow key
Copy selection command + C
Cut selection command + X
Paste selection command + V

Beware of Folder Overwrites

Unlike Windows, when you copy or move a folder to a destination which already has a folder with the same name, the Mac will delete that folder. Do not expect the Windows behavior where the contents of the two folders with the same name are merged. Instead the Mac will replacing the existing folder with the new folder. Unfortunately, the removed folder does not show up in the Trash bin and is totally gone. So be careful!

Accessing Windows Share

To access Windows shares from your Mac, just do the following:

  1. Launch the Finder, go to the application menu “Go->Connect to Server…”. Alternatively, you can right-click on the Finder icon in the dock (bottom left) and select “Connect to Server…”.
  2. Input your Windows share “\\host_ip\share” in the “Server Address” field like so: “smb://host_ip/share”.
    • “smb” indicates the network protocol (the language two computers should use when talking to each other) which Windows uses to share.
    • Mac OS X is unix-based and so uses the forward-slash / character, rather than the backward-slash \ character used by Windows.
  3. If the remote Windows machine is on a Windows domain or has a share password configured, you will be prompted to input the username and password.
    • To input the password for a domain user, input the username as “domain_name\username” and then the password. (The “domain_name” is case-insensitive.)
    • To input the password for a local user on the remote Windows machine, input the username as “machine_hostname\username” and then the password. (The “machine_hostname” is case-insensitive.)
    • If you want to pre-input the username, in the above step, you can input something into the “Server Address” field like “smb://domain_name;username@host_ip/share”.
    • If the above doesn’t work and you are using a hostname, you may want to try again using the IP address of the remote Windows machine, not the hostname. One way to get the IP address of the remote Windows machine is to go to that machine, open a Windows command prompt, and run “ipconfig”.

Re-installing Mac OS X

If you ever need to re-install your Mac OS X operating system from scratch, here’s how to do it.

  1. Your Mac should come with two or more DVDs: a Mac OS X Install DVD, a Mac OS X Application DVD, and optionally, the 3rd party vendor’s Recovery DVD.
  2. Insert the Mac OS X Install DVD into the DVD drive.
  3. Restart the system and hold the C key as the system starts up. This will cause the Mac to boot from the DVD drive.
  4. Follow the instructions to install the Mac OS X operating system.
  5. Once you have successfully installed the Mac OS X and rebooted into it, you can insert the Mac OS X Application DVD. If the installation wizard does not automatically launch, just open up the DVD to launch it. The Application DVD has non-core applications like Garage Band so it is totally optional.
  6. If your Mac comes with a 3rd party vendor’s Recovery DVD, you can insert that DVD to install any applications or Mac OS X customizations on it.

All in all, migrating from Windows to Mac OS X is not so bad. I’m surprised at how similar the two operating systems are, once you get used to the differences.