background image

Content tagged with: upgrade

Eric's picture

Version control is an essential tool when it comes to maintaining your code and properly tracking filesystem changes. In this quick tutorial, I'll show you how to update a Drupal module in a subversion integrated environment using rsync. Since simply copying the contents of a new module update on top of your current directory structure is a bad idea (since it will NOT account for file deletions), rsync is a great solution for syncing module update changes. NOTE: it is a bad idea to update a module in a production environment without proper testing; this code assumes you are working in a development environment.

The first step is to download the latest (and in most cases, stable) package for the module you'd like to update to a directory outside your drupal path. For my Drupal installations, I browse to the Available updates page (admin/reports/updates) and copy the URL from this page. Next I go to my shell, use wget to fetch the package to my home directory, and unpack the file:

$ cd ~
$ mkdir Downloads
$ cd Downloads
$ wget http://ftp.drupal.org/files/projects/xmlsitemap-6.x-2.x-dev.tar.gz
$ tar -xzf xmlsitemap-6.x-2.x-dev.tar.gz

Now you can run the rsync command to apply the filesystem changes to your Drupal module directory. You'll have to update the paths listed below to match your filesystem and Drupal installation.

$ rsync -avCz --delete ~/Downloads/xmlsitemap/ /var/www/vhosts/tdb.erl.dev/httpdocs/sites/all/modules/xmlsitemap/

If executed properly, you can change directory to the module you are trying to update and run an "svn stat" command to see what has been updated. NOTE: the below output is simulated to show common svn status changes.

$ cd /var/www/vhosts/tdb.erl.dev/httpdocs/sites/all/modules/xmlsitemap
$ svn stat
?      xmlsitemap.newfile.php
!      xmlsitemap_taxonomy
M      xmlsitemap.module

At this point, you should see a list of all the files that have changed with this module update. You can now run the update.php script in your development environment and verify the changes are working properly. If everything is working properly, you can commit the module update changes...

# remove files that have been deleted
$ svn stat | grep ^! | awk {'print $2'} | xargs -i svn rm '{}'

# add files that have been added
$ svn stat | grep ^? | awk {'print $2'} | xargs -i svn add '{}'

# commit
$ svn commit -m "upgraded xmlsitemap module to version 6.x-2.x-dev"

Now, you can safely deploy the module changes to your production environment (svn update), run the update.php script, and ensure everything is working properly.

Eric's picture

This morning, I encountered a PHP fatal error on my development environment. Upon further inspection, one of my third party modules (XML Sitemap) required a later version of PHP. A fresh installation of Centos 5.3 comes with version 5.1.6 of PHP. Here is an easy way to upgrade PHP to a later version by using the Utter Ramblings Yum repository.

I created a new yum repo file:

$ sudo emacs /etc/yum.repos.d/utterramblings.repo

# FILE CONTENTS - START
[utterramblings]
name=Jason's Utter Ramblings Repo
baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
# FILE CONTENTS - END

Ran a yum update:

$ sudo yum update
# ...snip...
Updated: apr.i386 0:1.2.12-2.jason.1 apr-util.i386 0:1.2.12-5.jason.1 curl.i386 0:7.15.5-2.1.el5_3.5 httpd.i386 0:2.2.8-jason.3 ksh.i386 0:20080202-2.el5_3.1 mod_ssl.i386 1:2.2.8-jason.3 mysql.i386 0:5.0.58-jason.2 mysql-server.i386 0:5.0.58-jason.2 pcre.i386 0:7.6-jason.1 php.i386 0:5.2.6-jason.1 php-cli.i386 0:5.2.6-jason.1 php-common.i386 0:5.2.6-jason.1 php-gd.i386 0:5.2.6-jason.1 php-mbstring.i386 0:5.2.6-jason.1 php-mssql.i386 0:5.2.6-jason.1 php-mysql.i386 0:5.2.6-jason.1 php-odbc.i386 0:5.2.6-jason.1 php-pdo.i386 0:5.2.6-jason.1 php-pear.noarch 1:1.6.2-1.jason.1 php-xml.i386 0:5.2.6-jason.1 php-xmlrpc.i386 0:5.2.6-jason.1 subversion.i386 0:1.4.4-jason.1 tzdata.noarch 0:2009k-1.el5
Complete!

After updating all these packages, I checked out my new PHP version:

$ php -v | head -1
PHP 5.2.6 (cli) (built: May  5 2008 10:32:59)

Now, my PHP fatal error has been resolved.

NOTE: This blog entry is a re-post of a previous article.

Eric's picture

Back in December 2008 I posted a blog entry on how to upgrade a subversion integrated Drupal site. This procedure was based on the process of unpacking the new Drupal installation, copying the sites folder into the new Drupal installation, and checking everything back into subversion. Although this is the recommended and cleanest way to upgrade Drupal, it may be a hassle if you have a huge repository and lots of files. So why not just overwrite the old directory with the new Drupal files? Well first of all, it would be good to take into consideration file deletions; and second, I've always been the kind of person who believes in fresh installs. I'd rather reinstall my operation system versus upgrading it. If you insist on overwriting the files, here's how you can do it...

Go to /admin/reports/updates to checkout which version your currently running and which is recommended. Download the new version of Drupal, along with the current version of your Drupal installation. If you can't find the current version, look for the "View all releases" link here: http://drupal.org/project/drupal

$ wget http://ftp.drupal.org/files/projects/drupal-6.8.tar.gz
$ wget http://ftp.drupal.org/files/projects/drupal-6.9.tar.gz

Next, unpack both of the files:

$ tar -xzf drupal-6.8.tar.gz
$ tar -xzf drupal-6.9.tar.gz

Now, use the diff command to compare the directories:

$ diff -r -q drupal-6.8 drupal-6.9

You'll see a lines of output that resemble the following:

Files drupal-6.8/CHANGELOG.txt and drupal-6.9/CHANGELOG.txt differ

Files that differ are OK, we can easily copy them into our current installation and check them in as modifications. To ignore those lines, we can run the previous command and tack on a grep statement to ignore them:

$ diff -r -q drupal-6.8 drupal-6.9 | grep -iv differ$

Hopefully, the previous command will return no output. If the diff command returned any output, it's probably telling you a file exists in one version and not the other. You'll have to manually resolve these subversion changes.

If the previous diff command returned no output, the new Drupal installation can be simply be copied on top of your current installation. But first, let's keep track of how many changes there were. NOTE: the next command assumes your current Drupal environment is up to date (the HEAD revision) and every file has been checked into the repository prior to the upgrade.

# check how many file modifications there are:
$ diff -r -q drupal-6.8 drupal-6.9 | wc -l
83

# copy the files into your current Drupal installation:
$ cp -r drupal-6.9/* /path/to/your/drupal/installation/httpdocs/

# verfiy the same number of file modifications:
$ svn stat /path/to/your/drupal/installation/httpdocs/ | grep ^M | wc -l
83

If the numbers match, run the update.php script. And if all went well, commit the changes:

$ svn commit /path/to/your/drupal/installation/httpdocs/ -m "Upgraded Drupal from 6.8 to 6.9"

Eric's picture

Here's a quick procedure on how to upgrade a Drupal site that's integrated with subversion (a checked out local repository). NOTE: you'll have to update paths, users/group, etc. I wrote this from memory, hopefully there are no errors.

# backup db
cd /var/www/vhosts/SITEHOSTNAME
cd archive
mysqldump DATABASE | gzip > DATABASE.sql.gz
cd ..

# get new version of drupal, unpack, & rename
wget http://ftp.drupal.org/files/projects/drupal-6.7.tar.gz
tar -xzf drupal-6.7.tar.gz
mv drupal-6.7 httpdocs_new

# TODO: Place the site in "Off-line" mode

# copy sites directory
cp -pr httpdocs/sites/* httpdocs_new/sites

# remove old subversion files
cd httpdocs_new
find . -type d -name "\.svn" -exec rm -rf {} \;
cd ..

# set permissions (as necessary)
chown -R apache.GROUP httpdocs_new
chmod -R 2770 httpdocs_new

# swap directories
svn mv httpdocs httpdocs_bak
svn commit -m "renamed site per upgrade"
mv httpdocs_new httpdocs

# upgrade db
# login in as userID 1
# http://SITEHOSTNAME/update.php

# test site, revert as necessary

# TODO: Place the site in "Online" mode

# check in new files
svn add httpdocs
svn commit -m "upgraded drupal"

# remove backup folder
svn del httpdocs_bak
svn commit -m "removed old version of site"