Lab 2: Getting Started with TurboGears

Due:  Tuesday, September 18, office hours or by appointment (see turning in your work, below).

Goals:

Collaboration: You may work in teams of 2-3 for this lab. You may discuss the assignment with anyone you wish. You may obtain help from anyone you wish, but you should clearly document that help. You need turn in only one assignment per team.

Contents:

Preliminaries: SSH and MySQL

Before getting started with TurboGears on the MathLAN, you need to have ready access to the MySQL database server which runs on aiken.  In turn, to have ready access to the MySQL database server, you must set up ssh.

Although I encourage you to work in pairs, each student should complete this part of the lab individually so that everyone is set up to use TurboGears.

  1. Follow Mr. Stone's instructions for setting up and using OpenSSH on the MathLAN. You will choose a passphrase and create a keypair. 
  2. Practice using ssh to connect to aiken.cs.grinnell.edu, our departmental web and database server.
Now that you have a keypair for SSH, you can set up ssh-agent. ssh-agent is a program that caches your public ssh key, so that you can connect using SSH many times in a session without having to re-type your passphrase each time.
  1. On the desktop, go to the Gnome menu (it looks like a footprint) and choose Desktop > Preferences > Sessions.  You should now see a dialog box with three tabs. Select the Startup Programs tab and then click the Add button. Type "/usr/bin/ssh-add" (without the quotes) in the text box and click the OK button. Then click the Close button of the Sessions dialog box.
  2. Log out. Then log back in. When Gnome starts, you should see a dialog box that asks you to enter your passphrase. Do so.
  3. Test that ssh-agent is working properly: Open a terminal window and type "ssh aiken". If all has gone well, it will not ask you to enter your passphrase again.

Congratulations! You now have ssh-agent working. You can ssh from any MathLAN machine to any other without retyping your passphrase.

The next step is to set up SSH tunnelling for MySQL. This will allow programs you run on a MathLAN workstation to connect to the MySQL server on aiken.

  1. Open the ~/.bashrc file in your favorite text editor (e.g., vim, emacs, gedit).
  2. Add the following lines to the bottom:
    # Have 'tunnel-mysql' set up ssh port forwarding for mysql
    alias tunnel-mysql="/usr/bin/ssh -v -N -L 3306:127.0.0.1:3306 aiken"
    To explain: You are creating up a new command, tunnel-mysql. This command tells ssh to connect to aiken with verbose output (-v), to not execute any remote command (-N), and to set up port forwarding (-L port:host:hostport).  In this case, we forward the default mysql port (3306) on the local host to the the same port on aiken.
  3. Save and close ~/.bashrc, then type "source ~/.bashrc" to execute the commands it contains.
  4. Type "tunnel-mysql" to start the ssh tunnel.
  5. Open another terminal window (or a new tab) and type "mysql -h 127.0.0.1 -u <username> -p <database>", filling in the username and database name you were given by Mr. Stone. When you are prompted to do so, enter the MySQL password you were given by Mr. Stone.  You should see something like the following:
    [10:26am] davisjan@rolle (~): mysql -h 127.0.0.1 -u davisjan -p davisjan_sandbox
    Enter password:
    Welcome to the MySQL monitor. Commands end with ; or \g.
    Your MySQL connection id is 9608
    Server version: 4.0.24_Debian-10-log

    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

    mysql>
    Type exit to quit mysql.

Congratulations! You have successfully connected to the MySQL server.

In the future, you will need to run the "tunnel-mysql" command in a separate terminal window whenever you run TurboGears.


TurboGears: The 20-minute Wiki tutorial

Whew! Now you have your MySQL tunnel running and you can finally start using TurboGears.

Go to the 20-minute Wiki tutorial and follow the instructions through to the end (pages 1-6). You may work in teams of 2-3. 

Despite the name, this tutorial can take quite a bit longer than 20 minutes, especially if you explore the links. You'll finish the tutorial as homework due next Tuesday.

Some notes and advice on the tutorial...

Page 1:

Page 2:
Page 3:
Page 4:
Page 6:

When you are done, quit the TurboGears server and the MySQL tunnel.

If you haven't done so already, read about The Big Picture. Feel free to email me with any questions.

Turning in your work

Come show me what you did! Sign up for a 15-minute office hour slot on Tuesday, September 18. If you can't come to my office hours, make an appointment with me for some other time this week. If you worked in a team, plan to all meet with me together.

I'll ask you how it went, you'll give me a demo of your Wiki, and you'll have a chance to ask me any questions you have about TurboGears.


Janet Davis (davisjan@cs.grinnell.edu)

Created August 3, 2007
Last revised September 14, 2007