Drupal Workflow with Drush, Git and git-ftp

As I prepare to upgrade some sites to Drupal 7, it seemed like a good time to document my workflow. I'd used Drush for local development on Drupal 6 sites and it eliminated the time spent manually downloading modules and updates. In Drupal 7, module updating isn't nearly as painful - in fact, it's built right into the admin pages (though you'll probably want to do this on a local or staging server first, just in case). A few sites I'm working on are hosted with a cPanel-based host that doesn't allow ssh access, so I can't just set up a git remote and push to the production server. Moving them to another host also isn't the best option right now. Git-ftp to the rescue.

tl:dr Set up your site and Drush locally, commit changes to git, test then use git-ftp to push them to the production server

Here's how I set up things up:
  • Set up your site locally. For OS X, I go with MAMP
  • Install Drush and git-ftp on your machine.
  • Initialize a git repo in your site directory. 
  • Set up your .gitignore file (one is included by default in D7). Here are some suggested entries. Make sure settings.php is listed (especially if your site is on Github!), and Drush depending where it's installed.
  • Run drush status to see the current Drush context. If you see a warning about a mysql sock connection, try sudo mkdir /var/mysql then sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock. (HT)
  • Run pm-update to update non-core modules. It will also check your Drupal core version and ask if you want to update that too. After the updates, the command will automatically update your local database. 
  • Make sure the site works on a local machine (or continue with the steps below with a staging server. Or just go for it if you're brave, it's a low traffic site or because nothing should go wrong if you do.)
  • Make any other changes you need to then git add as needed and git commit.
  • To be safe, put the production site into maintenance mode and make sure the database is backed up somewhere (most hosts do this automatically or with an add-on, unless you've rolled your own on AWS or similar).
  • cd into your local public_html folder and follow the instructions here for your first git ftp init.
  • Configure defaults so you can just use git ftp push from now on.
  • After pushing the changes, check the site status. You might need to run update.php. When everything looks ok, take the site out of maintenance mode.
  • Celebrate your freedom from tedium and consider starting new Drupal projects on a host that allows ssh access. Some cPanel-based commodity hosts, like HostGator and Dreamhost, do. Those remain most cost-effective for many commons purposes. For really high traffic or database intensive sites/apps, an integrated solution like Acquia or Pantheon might be worth considering.
Update: If your files are already in a remote location, try git-ftp catchup.

Popular posts from this blog

Thinking About BIPA and Machine Learning

Changing PDF Metadata with Python

A New Serverless Look