www.DwFAQ.info
Setup MAMP on Snow Leopard
Date Created: Friday, August 28, 2009 11:11 AM
Date Edited:

Tutorial Objective:


Preface

This tutorial will show you how to enable php on Snow Leopard. Then we'll install MySQL. After that we'll setup the virtual hosts configuration so that you can access your sites from your Sites folder on your Mac and enter http://site1 or http://site2 etc. in the URL to access each individual site locally. Then we'll setup phpMyAdmin so you can create and test dynamic web applications within a local database.

I've searched all over the web for info on how to setup PHP, Apache, MySQL, and phpMyAdmin locally on Snow Leopard (MAMP). Some have easy to follow info but some of it is spotty and incomplete. I had to fill in a lot of cracks and so I've decided to finally write a tutorial myself which shows how to do it.

Also I do not like using Terminal.app personally. It may sound silly but I always worry that I may perform a command that I will not know how to reverse, or at least that is what I think beginners may be thinking when setting something up that involves Terminal.app. For this reason I like to actually "see" what I'm doing when I do it. Unfortunately you have to work with a lot of hidden system files that are protected and hard to open, copy, and edit. I've found a few workarounds that avoid using Terminal.app as much as possible. I think it makes it easier to follow the steps since you "see" what you're doing instead of entering a terminal command, hitting return, and getting a blank screen where you don't actually know if the command was successful.

Anyway Without further ado let's start with the installation shall we?


Preface

1. Download apps to show/hide hidden files

This step is pretty easy. Like I mentioned earlier in the preface, you're going to have to access some hidden files on your Mac later on. So it's a good idea to get setup on how to see hidden files. I use Automator applications to accomplish this task.

Download the automator apps which will allow you to show and hide hidden files on your Mac. You can download the apps HERE then just unzip the file and click show-hidden-files.app to show hidden files or click hide-hidden-files.app to hide hidden files. It's really that simple. From this point on I will refer to show-hidden-files.app and hide-hidden-files.app in relation to the automator applications, respectively.

Once you download the file unzip it and you'll have each app to hide and show hidden files

Next thing you need to do is download TextWrangler.app. Text Wrangler.app is a text editing program that lets you open hidden files and unlock protected system files so you can work on them. You can download TextWrangler.app for Snow Leopard HERE


1. Setup Finder to show/hide hidden files

2. Initiate PHP in Snow Leopard

Snow Leopard already comes with PHP 5.3.0 built-in with GD image library. All you have to do is show-hidden-files, open the /etc/apache2/httpd.conf file in Text Wrangler.app, and edit out one comment line to initiate PHP.

Here's info on how to initiate the built-in version of PHP 5.3.0 in Snow Leopard

First click the show-hidden-files.app to show hidden files on your Mac. With hidden files visible navigate to /etc/apache2/httpd.conf right-click and open with Text Wrangler.app

Find line 115 in the code that looks like this:

#LibraryModule php5_modulte libexec/apache2/libphp5.so

Remove the hash symbol (#) to uncomment the command so it looks like this:

LibraryModule php5_modulte libexec/apache2/libphp5.so

Close and save the file.

Snow Leopard has a php.ini.default file that you need to rename and edit to control your php settings. Sounds simple enough but it's a little tricky to get the required php.ini file because the file is in a directory where it can not be renamed.

Use the Show Hidden files to see the php.ini.default file then select it and press command-c to copy the file to the clipboard. Then go to the desktop and press command-v to paste the file to the desktop. Now open the php.ini.default file with Text Wrangler from the desktop. With php.ini.default open in Text Wrangler choose File/Save As... For file name enter php.ini and for location choose the desktop. Then take the php.ini file and place it in the /etc/apache2 directory.

It's a cumbersome process but it keeps you from using Terminal commands. You can trash the php.ini.default file that you pasted on the Desktop since you only needed it to open and save as php.ini


Once you have your php.ini file setup in the correct directory then you need to open it again and make some changes to the file. So open /etc/apache2/php.ini in Text Wrangler and find the three instances where it says

/var/tmp/mysql.sock on line 1060, 1213, and 1272 

and change it to

/tmp/mysql.sock

After that setup the datetimezone for the file on line 997 of php.ini

Change this:

;date.timezone = 

to this:

date.timezone = "America/Los_Angeles"

Change America/Los_Angeles to whatever local time zone is available for your region.


2. Initiate PHP in Snow Leopard

3. Configure virtual hosts

By default the root path to websites hosted locally in Snow Leopard is /Library/WebServer/Documents/ where entering http://localhost/ will take you to the index file located at /Library/WebServer/Documents/

Most people (like myself) like to work on my websites inside the /Sites folder. For instance the structure of my websites are setup as folders inside the /Sites folder with a folder that has /site1 another folder that has /site2 etc. for each individual site in the /Sites folder

In order to have apache and php access these sites you have to configure your virtual hosts. The goal is to be able to enter http://site1/ to go to the index file located at ~/Sites/site1/ and enter http://site2/ to go to the index file located at ~/Sites/site2/ and so on.

Show Hidden files then open etc/apache2/users/username.conf file and change etc/apache2/users/username.conf file so that it has virtual hosts directories setup.

In etc/apache2/users/username.conf change this:

<Directory "/Users/username/Sites/">
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

To this:

<Directory "/Users/username/Sites/*/">
     Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

NameVirtualHost *:80
 
<virtualhost *:80>
    DocumentRoot /Users/username/Sites/_db
    ServerName database
</virtualhost>

NameVirtualHost *:80

<virtualhost *:80>
    DocumentRoot /Users/username/Sites/site2
    ServerName site1
</virtualhost>

NameVirtualHost *:80

<virtualhost *:80>
    DocumentRoot /Users/username/Sites/site3
    ServerName site2
</virtualhost>

That points to three different websites in the User/username/Sites folder.

Then edit the etc/hosts file from this:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1	localhost
255.255.255.255	broadcasthost
::1             localhost 
fe80::1%lo0	localhost

To This:

127.0.0.1	localhost
255.255.255.255	broadcasthost
::1             localhost 
fe80::1%lo0	localhost

# Local aliases

127.0.0.1 database

127.0.0.1 site1

127.0.0.1 site2

That way when you enter http://database in the URL of your browser it will go to the root of Users/username/Sites/_db/ and when you enter http://site1 in the URL it will go to the root of Users/username/Sites/site1/ same for http://site2 and so on.


3. Configure virtual hosts

4. Install MySQL

Download and Install the MySQL x86_64 version for Snow Leopard. There are three packages to install:

First install the mysql-5.4.1-beta-osx10.5-x86_64.pkg then install the MySQLStartupItem.pkg then install the MySQL.prefPane

After MySQL x86_64 is installed go to System Preferences and from the MySQL preference pane click the button to start MySQL. You must enter your administrator password to start MySQL.

Then go to System Preferences and in Sharing preference click the Web Sharing checkbox to enable php locally.

You now have MySQL and php running locally and you can place a test info() php file in any of the virtual hosts directories to see php running on your local server.

You can install the MySQL GUI Tools to help you setup MySQL interface later if desired although it's not required. The GUI Tools says it's the 10.4 Universal Binary version but it works for Snow Leopard just the same.


4. Install MySQL

5. Install phpMyAdmin

Go to phpmyadmin.net/home_page/downloads.php and choose phpMyAdmin-3.2.1-english.zip

Download and unzip the file and rename to _db and place in your Sites folder

Create a writable folder named config in _db/config

Go to http://database/setup to setup phpMyAdmin and click the new server button.

In the setup set the checkboxes to connect without password in the Basic Settings and Server configuration Tabs of the Overview

Click save then click save again to write config.inc.php in config folder

Move config.inc.php from config folder to _db folder and trash the config folder

Enter http://database in your browser to visit the phpMyAdmin homepage. Login with a blank username password. Once you've logged in you can change your password. You can also open MySQL Administrator app from the MySQL GUI tools (if you installed it earlier) to setup additional users on phpMyAdmin to login with different usernames/passwords.

That's it - now you have PHP, Apache, MySQL, and phpMyAdmin running on Snow Leopard with virtual hosts setup, and no errors on datetimezone or problems connecting socks in MySQL. Everything is all setup now. Next step would be to install mcrypt library in Snow Leopard php which is a different tutorial.


5. Install phpMyAdmin


© 2009 DWFAQ.info