Sunday, February 08, 2009

Installing MAMP

Installing MAMP (not MAMP Pro) on a Leopard machine and creating virtual Hosts.

for Beginners

(REAL beginners)

Installing MAMP (not MAMP Pro) on a Leopard machine and creating virtual Hosts.

Feb 8, 2009

One year ago I put the following webpage to help others install MAMP on their Mac. Since then, I have had many people visit the site for help. I have decided to move the page to my blog to save bandwidth on my personal server. So here that page is. I have been using MAMP for a year and have found it to be a great help. And I hope it helps you too.

I have not reinstalled the program since, so I do not know if my instructions still hold true. If you have problems, please post a comment and I will try and fix the problems.

In fact, I am thinking of setting up a Wiki to post the instructions so others can add to it. Even if I do, I will keep this post active just in case the Wiki is hit by scum-bags.

Happy programming

Scott

--------------------------------------------

Jan 23,2008

Dear New Dynamic Website Programmers

I spent several days trying to figure out how to set up virtual hosts on my two Mac computers and ran into hours of frustration. First of all, I am a real beginner! I have worked with Macs since 1983 (owned a Lisa) so I have a broad experience base with the platform. But with php/mySQL etc, I have NO experience. Finally, I have obtained success! I have set up three virtual hosts on both computers. The following is to the best of my memory how I did it. And I hope it helps someone else out there who finds themself in a similar situation.

I have been developing websites now for several years, but never dynamic ones. Out of curiosity and looking for a challenge, I decided to try one out. I have a couple of hosting accounts with GoDaddy.com one of which is for a friend that I am building a site.

Was it hard? Well, Yes and No. I find this an interesting philosophical question. Once you know how to do something, it isn't hard; is it? What seems to be hard is explaining it to someone else. This is what I found. The people out there that try to explain are usually people who know the stuff cold. What I find is that many of these good people make assumptions that leave out critical information for real beginners. You know, those of us that have not taken classes in C++ or JAVA or PEARL etc. I took calculus in college and had a very difficult time at it. Thirty years later I wrote three books on the subject (long story). I know what the process of not-knowing to knowing is about. When I wrote the books I had just learned the subject (again) so when I went to writing about it, I came from the perspective of the person who would normally have trouble with calculus. Like I said on the back of the book; calculus is not hard, it is just different.

Well, enough jabber. Here is what you do to set up your Mac to run virtual hosts using MAMP. I did the following:

First of all, I use Dreamweaver to develop sites with a little help from two lesser known programs WebDesign andStyleMaster.

1) Bought books...several of them and none were up-to-date enough to help with the installation of php on new machines.

2) Went on line and searched for help....This is where I found MAMP

3) I Downloaded MAMP

MAMP is a nifty program that sets up your computer to run php on an apache server. You install it and it creates an environment where you can test php scripts and MySQL databases on your own computer. You do not have to be connected to a remote server (like GoDaddy, or Host Monster ). Apple has had apache and php on their machines for some time now, but you will quickly find out that the versions of both open source programs is behind the times or not totally complete. MAMP installs over the Apple version in its own directory in your Applications folder. You place your website pages into a folder called htdocs inside of the MAMP folder. Once you get MAMP configured, you are set to go. You run a php page (like index.php) and MAMP acts like your remote server and runs the script.

4) Pulled my hair out

Since I have an older G-5 duel PPC I needed to download MAMP version 1.7 which I did. I also own a new MacBook (latest and greatest). Both machines are running Leopard 1.5.1 MAMP comes in a "Pro" version that will set up virtual hosts automatically. I have not bought the program yet, so I can not speak to its pluses over the regular MAMP.

I started out going to a posting on stringfoo.com. This was some help with the initial setup of MAMP, but confused me when he started to explain virtual hosts. Then I found the following forum post at MAMP. This was the most help as it showed how to set up the two files that make virtual hosting possible. Which, by the way, was different from the stringfoo instructions. What I will try and do is to put it all together for you without mixing in any other stuff like stringfoo did by talking to both new installs and transfering old ones.

Instructions:

1) Turn off Web Sharing under Preferences -> Sharing. This turns off Apple's server. Leaving it on may work since it uses different ports, but I did not want to take a chance.

2) Install MAMP. It will create a folder in your Application folder called MAMP. Inside it will have several folders one of which is called htdocs. Remember this folder as it is where one of your sites will reside.


Disregard the htdocs2 and htdocs3 folders because they are not there when you first intall MAMP. You add these to hold your extra virtual hosts (other web sites you are developing). Neither is the index.php there.

3) Configure MAMP: Here is where stringfoo may help some. Go there for additional help.

Double click the MAMP..app icon to open the program. You should see the following window:


Click on Start Servers to start. The Status buttons should turn Green. Now Click on Open start page. You will see the MAMP start page. If this doesn't open or if one or both of the status buttons does not turn green, you do not have MAMP installed properly. One of the good things about MAMP is that if you mess-up, you can just trash the MAMP folder in your Apps folder and start over. Just reinstall.


Once the Start Page is open, you can click on phpinfo to see if php is operating; see below. Clicking on phpMyAdmin will open the second screen below. The last screenshot shows the SQLLiteManager screen.


To configure MAMP go back to the Start page and click on Preferences. These are pretty self evident except for Ports and Apache. For the Ports preference, I just used the two ports that MAMP defaults to (8888 for Apache and 8889 for MySQL):


These are different than the Apple defined ports. Other ports will allow you to have others see the site from places off your network. Other ports are used for various reasons. You can find an explanation of these differences at the MAMP website. For now just use the default.

The Apache tab asks for the root folder. This is where you will place your web pages. Here again, let the default htdocs be home for the time being. You can change these later to other locations such as your Site folder by changing the path to something like /User/Sites/site1 (where User is your computer's name and site1 is a folder inside of the folder called Sites).


Now you are ready to use the htdocs folder for your server. Try it. I created a web page (using Dreamweaver)with the phpinfo call in it. Just save it to the htdocs folder. Make sure you call the page index.php.


In case you cannot read the screenshot, the code is below:


Notice how I named (titled) the page "Site 1 Test Page". This will be the the name on the top ribbon of the screen (see the screenshot below). I did this so that when I created and tested other virtual sites I called the pages "Site 2 Test Page" and "Site 3 Test Page" respectively. This lets you know that you are testing the index.php that you intended. If this is confusing, don't worry, it will make sense later when you set up the virtual hosts.


You should see the php info page you saw in MAMP start page. You do this by opening your browser and inputing the following into the address bar and hitting theReturn key: http://localhost:8888/index.php


If is all well to this point, you have a working test site. You put your webpages inside htdocs and call your start page whether it is index.html or others by doing the same thing you did above to call the phpinfo page. Input into your browser:

http://localhost:8888/"your start page"

The only problem is that, if you want to test more than one web site at the same time, you are out of luck. For instance, in Dreamweaver, if you try and point more than one site to the htdocs folder expecting to be able to test more than one site (let's say, by adding sub-folders), it will not allow it.

Now I will show you how I set up two special files to allow you to test more than one site using MAMP.

The first is the hosts file found in the /private/etc directory. Where is that, you say. Well, it is hidden. To see it all you do is use the Go to Folder in the Go menu when you are in the finder. Type in " /private/etc " (no quotes). and hit return. You will see the hosts folder in the list. This is where it is, but you will NOT edit it with a text editor, you will use the Terminal.

Open the Terminal application. You can find this app in your Utilities folder in Applications.

When you open the app you will be presented with the Terminal screen. My computer name below is BlackMac and my user name is scott. Your screen will look the same with your computers name and your user name in place of BlackMac and scott. Type in this string: ( sudo pico /etc/hosts ). Hit your Return key.


Type in your admin password (this is the password you set up when you first installed your Leopard system and is the password for your main admin account). Don't worry when you do not see anything, the cursor will not move and you will not see the password on your screen. It is there however. You will be presented with the following screen after a Return:


Arrow down (use your keyboard arrow keys) to the 127.0.0.1 line. Arrow over to just past localhost. Type two more local hosts with different numbers added. My page looks like below as I used 2 and 3 as my second and third hosts:


You save this file by holding down the Control Key and pressing O (control-o ; not zero) on your keyboard to save the file then hit the Return key. Now press (control-x) to exit Terminal.

For those of you that know Terminal better than I, you can also use " sudo nano " to edit the hosts file (see the stringfoo site). I had trouble getting the file to save in the right place, so I used the " sudo pico " method which worked for me.

Now make two new folders inside the MAMP folder called htdocs2 and htdocs3. These will house your second and third web sites (now you know what I was talking about above):


Now you need to edit the MAMP httpd.conf file. It is located here: MAMP -> config -> apache -> httpd.conf :


Open this file in your text editor (I use Dreamweaver or WebDesign, shown below). Once opened, scroll down to the bottom (about line 1133) and you will see the following line:

# NameVirtualHost *

This is where you will define your virtual hosts for MAMP. The pound sign ( # ) in front of NameVirtualHost * makes it a comment. You must remove this so the line will look like:

NameVirtualHost *

Now your are going to type the following lines right under this line. Do not worry about returns if you type, it just makes it more readable and will not mess things up:


These are your three hosting sites. Notice the first one defines the default site, like it is renaming the site. This is very important to have included as the first of the virtual sites. You must have the DocumentRoot correct in this site. You can check its root path on line 368 (or nearabouts). You can also find the serverRoot on line 50 which shows you where MAMP does its work. Below are screenshots of both. Also, remember the adding of the localhost's in the Terminal program. Here is where you use these three servers you defined. Make sure you type them correctly.

When I say type them, that is what I mean. Sometimes carrage-returns are different between programs and this has screwed up some from what I have read in the foums. You can try and copy/paste them from this web page, but if you have problems, try and type them in.


Save this file (httpd.conf).

Turn off the MAMP servers and then turn them on again. This will restart the programs with the new virtual sites available.

To access the three sites you merely use the following browser addresses:

Server 1: http://localhost:8888/
Server 2: http://localhost2:8888/
Server 3: http://localhost3:8888/

To see if they work, copy the php file you made above renaming them for their respective locations and put them in the htdoc2 and htdoc3 folders (you do already have one in the htdoc folder, don't you?). Now you input the three addresses into your browser to check and see if the three work.

Server 1: http://localhost:8888/index.php
Server 2: http://localhost2:8888/index.php
Server 3: http://localhost3:8888/index.php

Below is a screenshot of my third site. I put http://localhost3:8888/ into the address box of the browser and got the following page:


Notice how I did not put the "index.php" in the address, I just have "http://localhost3:8888/". Back in the httpd.conf file if you go to line 455 you will find the following line:

DirectoryIndex index.html index.php

This makes MAMP look for these common start pages. Remember to put your index.php files in to each htdoc folder. This worked great on my G5 PPC machine, but did not work on my MacBook (intel) machine. I had to type in index.php even though the httpd.conf file showed index.php as one of the index files.


For those who use Dreamweaver (CS3), below is a screenshot of how you should set up the testing server page in the program:


Testing Server folder: G5:Applications/MAMP/htdocs

URL Prefix: http://localhost:8888/

This shot is of my first site called site1. For site 2 you would merely change the name of the server to:

http://localhost2:8888

For server 3:

http://localhost3:8888/

There you have it, I hope this helps those beginners out there who have had the same trouble I had.

I put this up to help people and I hope it does. I do not want to become your tech support though. I will eventually put it up on a blog rather than on my server so people can respond and add to the discussion. I will not, however, respond personally to anyone. I will, at the time I have it up on a blog, respond by correcting the page if someone finds a problem or if I find a better way of saying things. I just do not have the time, sorry : )

Your friend in programming need:

Scott


Thursday, January 08, 2009

WIKI

How about a WIKI? I have seen several educational wiki's and think that, of all courses, calculus would be a good candidate for one. Calculus is full of new concepts students have difficulty with. Different approaches to these concepts is sometimes all that is required to get the lightbulb to turn on.

Perhaps edits by both teachers and students would be useful. Students with posts on what did turn on the light.

Dangerous, of course, to let students post as they have a tendency of clowning. Perhaps the calculus student is a more mature young person though.