Lab 11: Deployment and Revision Control
In this lab you will deploy your lab website on dreamhost. If the domain name for your lab website is abc123.calvincs.com, I've set up a subdomain deploy.abc123.calvincs.com 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].calvincs.com 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:
- Create a new directory deploy.abc123.calvincs.com in /var/www/html/sites and edit the new settings.php file with username, password, and server name appropriate for logging into the host's database server
- Copy your /var/www/html files into the host's server web directory (deploy.abc123.calvincs.com)
- Copy your database onto the host's database server
For this lab you'll deploy your lab website on the deploy.abc123.calvincs.com subdomain. I've also created a database for you on dreamhost with the login and password given to you. The database server is mysql.calvincs.com 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.
- Create a new drupal site directory /var/www/html/sites/deploy.abc123.calvincs.com by copying your default site.
- 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, mysql.calvincs.com (Note that localhost won't work as the host--you'll have to change it to mysql.calvincs.com.) Also change the database name, user, and password to those given to you.
- The web server on dreamhost.com 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
- A single zipfile uploads much faster than thousands of separate files.
Create a zip archive of all the files:
zip -r /tmp/site.zip .htaccess *
This creates the file "site.zip" 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.)
- Upload it to your dreamhost server with the command
scp /tmp/site.zip firstname.lastname@example.org:
While you are waiting for the upload, you can continue with the rest of the lab.
- Log in to the william-blount.dreamhost.com server with ssh, cd into the website directory (deploy.abc123.calvincs.com), and unzip your files with the unzip command in the current directory. (You should end up with several files in deploy.abc123.calvincs.com including authorize.php, index.php, includes, sites, etc.)
- 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 mysql.calvincs.com [database name] < [mysqlDumpFile.sql]
- Set a cron job for Drupal as in lab 6.
- Your website should be deployed and running. Give it a try!
- Type git help to see a list of common commands.
- Introduce yourself to git. Type the following at a command prompt:
git config --global user.name "Your name here"
git config --global user.email yourID@students.calvin.edu
- 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".
- 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).
- 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
This will prevent (obedient) robots from crawling the site.
- 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".
- Type git log to see recently changed files. Now try git log -p to see all the actual changes.
- 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.
- 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.
- Switch back and forth between the master and experimental branch and watch the contents of that file change.
- 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.
- At this point you have two different branches. Let's merge them back into one. Type the
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.
- Edit your robots.txt file and make sure the Disallow: / line is deleted. Commit your changes.
- This lab was intended to introduce some revision control concepts. It was based in part on the git tutorial at kernel.org. 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.
Copying your database
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 github.com -- 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.
I will check your git repository and the deployment of your live site on yoursite.calvincs.com