software engineer, Drupal follower, Docker ninja, JS explorer, PHP believer, Exotic Hardware beta tester, Amiga enthusiast, truth seeker, parent & husband... at least for now...

You are a Drupal developer and you prefer to do all the installations and updates of your web sites using Drush, but your newest customer has a managed server at Hetzner? I am sure you already know that drush isn’t already installed and it is a little bit difficult to persuade the system administrator to add it. The following guide will help you to install it and use it in a few minutes.

First of all you have to have ssh access to the server, even if the user you use is not the root. To do that you have to login to your server panel from https://konsoleh.your-server.de/. Click on the server you have your domain installed and from the menu at the left column select “Account management > SSH access“. From the select field choose the domain, click next and then click “Activate”. After that a new message will appear saying that the ssh access is activated. Have in mind that you have to use the same credentials like FTP but the port of ssh is the 222, instead of the usual 22.

Open your terminal and connect to the server using ssh. And now it’s time to install Drush. Below are the steps you have to follow to complete the installation.

# create a new folder under user’s folder
mkdir drush
cd drush

# download the latest stable version of drush, which is compatible with Drupal 6, 7 and 8
wget http://files.drush.org/drush.phar

# test your installation and see the version of drush, along with the path where it is in the disk
php drush.phar core-status

# make it executable
chmod +x drush.phar

# rename it
mv drush.phar drush.php

# and initialize it
./drush.php init

When you run the last command you will be asked to append a few lines in the file .bashrc, which you better answer yes, although we will edit this file later. When I did the above I got the following info.

Copied example Drush configuration file to /usr/home/[username]/.drush/drushrc.php [ok]
Copied example Drush bash configuration file to /usr/home/[username]/.drush/drush.bashrc [ok]
Copied Drush completion file to /usr/home/[username]/.drush/drush.complete.sh [ok]
Copied example Drush prompt file to /usr/home/[username]/.drush/drush.prompt.sh [ok]

# Include Drush bash customizations.
if [ -f “/usr/home/[username]/.drush/drush.bashrc” ] ; then
    source /usr/home/[username]/.drush/drush.bashrc

# Include Drush completion.
if [ -f “/usr/home/[username]/.drush/drush.complete.sh” ] ; then
    source /usr/home/[username]/.drush/drush.complete.sh

# Include Drush prompt customizations.
if [ -f “/usr/home/[username]/.drush/drush.prompt.sh” ] ; then
    source /usr/home/[username]/.drush/drush.prompt.sh

# Path to Drush, added by ‘drush init’.
export $PATH=“$PATH:phar:///usr/home/[username]/drush/drush.php”

Append the above code to /usr/home/[username]/.bashrc?

As soon as the initialization finish, edit the .bashrc file and comment out the lines that refer to drush. Then append at the end of the file the following lines:

export COLUMNS
alias php=’/usr/bin/php’
alias drush=’/usr/bin/php ~/drush/drush.php –php=/usr/bin/php’

Save .bashrc and close the ssh connection. This is necessary because .bashrc commands are executed when you connect to the server, so try now to connect again. If you don’t see any errors then everything work as they should. Now we must test if drush is installed right.

# check drush version
drush version

You must get something like Drush Version : 8.0.3. If yes, then everything work like a charm. Drush is ready for you to use it as you always did. Get into the public-html folder where your Drupal installation must be and run drush to make updates and anything else you need.

#drupal #webserver #installation #guide #drush #hetzner #managed
- 3 min read