Sunday, March 15, 2009

How to push a simple Drupal web site from test to production

I decided to give up on the twitter issue for now (I've been trying to get tweets onto my Drupal web site but couldn't make it work right). So I decided to go with what I have, which is my basic web pages + my Transcode blog showing up on the Drupal-created web site's main page.

My next task was to try to push the web site live, onto my hosted web server. I had to learn how to create a MySQL database on the hosting company, which was easy to do but took a couple of hours to show up. I also wanted ssh access to my site, which apparently caused my hosting company to move my hosted environment to a different server; that also took a few hours to get going, but was relatively painless. I tried to connect to it after a few hours, and couldn't; I found out that I needed to create a new password for the ssh service to work (makes sense, no problem).

Once I did all that, a few hours later I was able to get to the site. Here were the basic steps I took:

- I took my whole web site's "htdocs" directory tree and made a tarball of it:

tar cvf website.tar ./htdocs

This is where my images, PHP code for Drupal + modules, and all my other content sits, at least the content that doesn't get stored directly into the database. (e.g., PostScript documentation that I store on the site for public download)

- I FTPd the tarball over to my hosting provider, just put it somewhere for the time being.

- I took a snapshot of my Drupal database using "mysqldump":

mysqldump -u myusername -pmypassword mydatabasename > databasename.sql

(note: no space between the "-p" and the beginning of the password string. Not sure why that was the case, when there is a space between the "-u" and the beginning of the username string.)

- I FTPd the databasename.sql file to my hosting provider as well.

- I logged into my hosting provider's site, went into the administration interface for it, and asked it to create a new MySQL 5.0 database. I gave the database the same name as I gave when I set up Drupal on my local site. I picked a username and password, then it was ready to go. I noted the hostname where that DB sits, because I need to use that later.

- I used ssh to get into my site. Once there, I unpacked the htdocs tarball:

tar xvf htdocs.tar

- I moved the htdocs directory to be a peer of my existing html directory (the top of the html tree for my existing web site; I'm going to replace that html tree with my new Drupal-based html tree). Now, typing "ls" I see the following

htdocs html

- I went into htdocs/sites/default/files/ and edited the "settings.php" file to make sure the setting for connecting to the database is correct. I needed to update the username, password, and hostname to make sure they all correctly use the production site's values. The line looks something like this:

$db_url = 'mysqli://user:password@nameofdbhostname.com/nameofdb';

- I moved the original html directory out of the way

mv html html.orig

- I moved the Drupal-based htdocs document tree into place

mv htdocs html

- I was then ready to test by going here: http://www.transcode.com/

The Drupal-based content showed up like a charm. Voila!

My first live site push with Drupal worked, no problem.

Next, I'll need to learn how to do site updates: I intend to do more web site development via Drupal on my local machine, using my test/development environment (using VirtualBox to run OpenSolaris as a guest OS, so that my whole environment sits in a single .vdi file that I can put on a USB stick and take and use anywhere I want to go, or copy it onto a DVD or anywhere, really). Anyway, once I make more improvements to my web site, I'll want to push them live, too, so I need to learn how to update an existing live site. I'm hoping that will be pretty easy.

No comments: