Lab 11: Deployment and Revision Control

20 points

In this lab you will deploy your lab website on dreamhost. If the domain name for your lab website is, I've set up a subdomain that points to a dreamhost server. You'll deploy a copy of your lab website on the dreamhost server.

You will also experiment with the popular git source control system.

(I'll also set up hosted dreamhost subdomains as deploy.[yourproject] and link them on the projects page. You should deploy your term project websites to those accounts separately, not as a part of this lab.)

Deploying your website

Deploying a Drupal website on a hosting service generally includes three steps:

For this lab you'll deploy your lab website on the subdomain. I've also created a database for you on dreamhost with the login and password given to you. The database server is and the database name is yourID, that is, your login, e.g. zzz99. Let's start by creating a new drupal site to be uploaded to dreamhost.

  1. Create a new drupal site directory /var/www/html/sites/ by copying your default site.
  2. cd into the new site directory you just created and edit the settings.php file to connect to your database on the dreamhost database server, (Note that localhost won't work as the host--you'll have to change it to Also change the database name, user, and password to those given to you.
  3. The web server on isn't configured to default to index.php files, so let's copy the index.php file to index.html in your webserver home directory with the command
    cp /var/www/html/index.php /var/www/html/index.html
  4. A single zipfile uploads much faster than thousands of separate files. Create a zip archive of all the files:
    cd /var/www/html
    zip -r /tmp/ .htaccess *
    This creates the file "" in /tmp with all the contents of your /var/www/html directory. (The hidden .htaccess file has to be named separately because * doesn't include it.)
  5. Upload it to your dreamhost server with the command
    scp /tmp/
    While you are waiting for the upload, you can continue with the rest of the lab.
  6. Log in to the server with ssh, cd into the website directory (, and unzip your files with the unzip command in the current directory. (You should end up with several files in including authorize.php, index.php, includes, sites, etc.)
  7. Copying your database

  8. Use mysqldump to create an SQL dump of your database. As a reminder, you can find instructions on the Resources page (mysqldump command). Copy copy the file to william-blount with the scp command, log into william-blount, and type the command
    mysql -u drupal7user8 -p -h [database name] < [mysqlDumpFile.sql]
  9. Set a cron job for Drupal as in lab 6.
  10. Your website should be deployed and running. Give it a try!
  11. Revision Control

    We're simply going to use git locally, on your VM. You can also use git to synchronize your directory of files with other repositories or a server. If you eventually work at a company that uses source control, they will already have a server set up. If you want to share your code with others or collaborate on a project and don't have access to a server, you can set up an account at -- for free, if the project is open source.

    Note that there are git GUIs which may be easier for some purposes. A google search should locate several. However, it's a good idea to start out with the command-line interface in order to better learn how it works.

  12. Type git help to see a list of common commands.
  13. Introduce yourself to git. Type the following at a command prompt:
    git config --global "Your name here"
    git config --global
  14. Your /var/www/html directory should already be under source control with git. Change into /var/www/html and type 'git status'. It should show you any modified and untracked files that are not current in your last git commit. If for some reason you don't have the directory under source control you can set it up now: type git init. Git should reply Initialized empty Git repository in .git/. Now add the current directory to the repository with the command git add . (the dot is part of the command). The snapshot is now stored in a temporary staging area which git calls the "index".
  15. To upload the contents of your www directory to the git server type git commit -m "Lab 11 commit". The -m option gives the commit message explaining the changes you are committing. Congratulations! You've backed up your code and made it available to everyone else in your group (if there were anyone else in your group).
  16. Edit the file robots.txt in the webserver root directory (/var/www/html). Robots (Google's Web crawler, for example) read this file to learn what they may crawl and what they may not. Since this is a development site, we don't want search engines to index it. So, after the User-agent: line add a line that says
    Disallow: /
    This will prevent (obedient) robots from crawling the site.
  17. Type git commit -a. (The -a option means you don't have to manually add the changed file with a git add command.) Add a suitable commit message, such as "Prevent robots from indexing the site".
  18. Type git log to see recently changed files. Now try git log -p to see all the actual changes.
  19. Let's create a new branch of the repository. Type git branch experimental. If you now type git branch you'll get a list of existing branches. The master branch is still active.
  20. Let's switch to the experimental branch. Type git checkout experimental. Now edit the robots.txt file and add a comment at the top that says
    # this is the experimental branch
    Commit the change.
  21. Switch back and forth between the master and experimental branch and watch the contents of that file change.
  22. Now switch back to the master branch with git checkout master. Edit the robots.txt file and check that the change you made is no longer visible since it was on a different branch. Now edit the robots.txt file and make a different change -- add the comment
    # this is the master branch
    Commit your change.
  23. At this point you have two different branches. Let's merge them back into one. Type the command
    git merge experimental
    You'll get a message about a merge conflict -- there are two different versions of the robots.txt file.
    git diff will show you the differences. Edit robots.txt to remove the stuff that was added, including the comments, and type git commit -a to commit the result of the merge.
  24. Edit your robots.txt file and make sure the Disallow: / line is deleted. Commit your changes.
  25. This lab was intended to introduce some revision control concepts. It was based in part on the git tutorial at There is more to learn about git if you intend to use it. You can optionally continue with that tutorial or another to learn more. If you wish to upload your website to dreamhost using git, see their git wiki page.
  26. Turn In

    I will check your git repository and the deployment of your live site on