Using Drush on OIT Web Hosting

Drupal Version

If you are hosting a Drupal website on OIT Web Hosting, you can SSH into your host, but you cannot run the command-line tool Drush from your SSH session because OIT doesn't allow PHP to be run directly from the SSH command line of Web Hosting accounts.  However, this doesn't mean that you cannot use Drush at all with OIT Web Hosting – you just have to work around this limitation.

Disclaimer

THESE INSTRUCTIONS ARE COMPLETELY, 100%, NO, EVEN 1000%, NOT SUPPORTED IN ANY OFFICIAL WAY BY OIT WEB HOSTING.  No warranty expressed or implied.  Always back up your site and database(s) before trying these instructions.  These instructions, though tested on several sites, may break your site, cause data loss, or even make your dog not like you any more.  Be careful!

Process

Essentially, you will run Drush locally on your computer, but have it operate on an OIT Web Hosting site.  To do this, you will need to:

  1. Establish an SSH tunnel for the database connection, and
  2. Mount your site's files over ssh via SSHFS.

Note: The instructions presented below are for using Drush on a Mac. If you want to try this from a Windows computer, both SSH (<) and SSHFS (WebDrive) clients are available for Windows.

Prerequisites

  • Drush, installed locally – Installation instructions are available at the Drush Docs site.  If you have the Acquia Dev Deskstop installed, you already have Drush.  You can also install it via homebrew.

  • An SSH client – Suggested products are:

    • On a macOS / Mac OS X system: Terminal or iTerm
    • On a Windows system: SecureCRT
  • An SSHFS client to let you mount a remote filesystem over SSH – Suggested products are:

  • Access to your site via SSH – You must know the password for your site's (unfortunately named) FTP Login account, which you can set/reset via your web hosting administration panel in the Web Hosting Settings screen.  (Note as of the 2015/16 Plesk upgrades, you can now set up and use an SSH key instead of needing the SSH/FTP password.)

  • Be on campus or have access to the campus VPN Service, as OIT Web Hosting does not allow SSH directly from off-campus.

Steps to Drush Bliss

In the instructions below, foo.gatech.edu is a placeholder for your site's actual hostname, and foo is a placeholder for your site's SSH/FTP account. Replace these with your site's hostname and SSH/FTP account where appropriate.  Also, these instructions assume you are using Transmit as your SSHFS client.  Configuration screens for WebDrive will be similar.

  1. Install Drupal, if you haven't already... via source, Installatron, etc.
  2. Edit your httpdocs/sites/default/settings.php file, changing the databases array's host and port entries to read:
     'host' => php_sapi_name() == 'cli' ? '127.0.0.1' : 'mysql.localhost',
     'port' => php_sapi_name() == 'cli' ? '3307' : '3306',
  3. Create a file named dbip.php in your sites httpdocs directory: 
    <?php 
    if (array_key_exists('REMOTE_ADDR', $_SERVER) 
       && ((substr($_SERVER['REMOTE_ADDR'], 0,7) == '128.61.') 
       || (substr($_SERVER['REMOTE_ADDR'], 0,8) == '130.207.') 
       || (substr($_SERVER['REMOTE_ADDR'], 0,8) == '143.215.') 
       || (substr($_SERVER['REMOTE_ADDR'], 0,9) == '192.93.8'))) 
       { 
        echo gethostbyname('mysql.localhost'); 
       } 
    ?>
    
  4. On your local machine, in a terminal window, open up an SSH tunnel through your Web Hosting server to your Web Hosting account's database host:
    ssh -N foo@foo.gatech.edu -L 3307/`curl -s http://foo.gatech.edu/dbip.php`/3306
  5. Use an SSHFS client to mount your site's httpdocs directory. For Transmit, use the SFTP connection and choose Mount as Disk:


     
  6. In a terminal, navigate to the mount point ( /Volumes/foo.gatech.edu/ ) and run drush status to test your configuration. You should see the message "Database : Connected and Drupal bootstrap: Successful."
  7. When you are finished using Drush on your site, remember to close (control-C) the SSH command doing the tunneling and unmount your site's filesystem (drag it to the Trash).