Drupal, drush and putty, fast and secure.

Popular open source CMS
KBleivik
Site Admin
Posts: 178
Joined: Tue Sep 29, 2009 6:25 pm
Location: Moss Norway
Contact:

Drupal, drush and putty, fast and secure.

Postby KBleivik » Thu Feb 28, 2013 1:27 pm

Drush http://drush.ws/ is a command line shell and scripting interface for Drupal that can make upgrading and updating your drupal site faster and more secure using your server's command line. Drush allows you to search the drupal.org site, install Drupal, install modules, enable modules and much more.

How do you get to your server's command line? The first thing to know is that sometimes you can't. Some Web hosting companies refuse to give you access. Use a company like A2Hosting that I use. Then you can use a program like PuTTY to give you shell (SSH) access. What is SSH? Technically, SSH allows you to control another computer (ie, your web server) over the Internet through a command line interface (CLI). PuTTY is a SSH shell that will allow you to access your web server directly from your computer. If you know how to use the DOS command line shell or Windows PowerShell, you should have no problem getting used to PuTTY and drush. From Drupal: A beginner's guide to Drush we quote:

Typical Drupal sites use dozens of modules. Each one is a separate project, with its own programmers working at their own pace. Hardly a month will go by without updates to some of the modules on your site.

Updating modules isn't hard, but it takes time. Worse, it's easy to make mistakes.

Sometimes you need to update Drupal core. Updating core is a bit stressful. You can do major damage to your site if you're not careful.

Drush can help. Drush is software that makes updating Drupal sites easier. When you tell Drush to update a module, it takes care of downloading the right version of the module, copying the files to the right place, and making database changes.

Even better, Drush can update core with a single command. W00f!


If you get errors connecting to your web site using PuTTY, the reason may be:

  1. That your hoster refuses to give you access.
  2. Don't write your site name correctly. Note that it shall have the format: example.com.
  3. You may use a wrong port.
  4. Other issues.

Note, if you are on a shared server, the command:

Code: Select all

cd ~


will not function since you do not have server-level root permissions. The command

Code: Select all

pwd


will tell you where you are in the directory hierarchy. Let us assume that your domain is addondomain.com then you may reach that directory by issuing the command:

Code: Select all

cd /home/username/public_html/addondomain.com


that functions for me on A2Hosting. Alternatively

Code: Select all

cd /public_html/addondomain.com


may function for you. If you get the following message

No such file or directory


or are unable to use PuTTY, you shall contact your hoster. When everything is Ok, you can install drupal drush.

For additional informatio see: Drupal: A beginner's guide to Drush. That article, tells you to install drush outside your home directory. If you are on a shared server, most probably you will get an error like this:

Code: Select all

-bash-3.2$ mkdir drush

mkdir: cannot create directory `drush':[b] Permission denied[/b]


One option is to put a .htaccess file in the drush sub directory of your home directory where you only allow your own ip access to the drush directory. Put the following .htaccess file in the drush sub folder of your web server:

.htaccess

Code: Select all

#Restric access to your own ip.
order deny,allow
deny from all
allow from your own Ip


Then, having restricted access to the drush directory, I change the permission of the drush file (no extension!!) as explained in the article, I made the following file and put it in the home folder on my web server:

.bashrc

Code: Select all

#Set the drush alias
alias drush='/home/username/public_html/drush/drush'


Then I run the file

Code: Select all

source .bashrc


and if everything is correct, you can now run drush by startiing the command with the drush key word. Example:

Code: Select all

drush help


Now it is time to test drush. As explained in the article, I will update my drupal site (if there is an update) issuing the following command:

Code: Select all

 drush pm-update wysiwyg


and get the following message:

No code updates available.


One more example. I got an email with the following message:

There are updates available for one or more of your modules or themes. To
ensure the proper functioning of your site, you should update as soon as
possible.


When I go to the reports page in the administration panel of my site and click on on the updates link I find that

Twitter 7.x-5.4 Update available
Recommended version: 7.x-5.5 (2013-Feb-25)


Then I have to use the name as it is in the URL: drupal.org/project/twitter so it is twitter and not Twitter. The following command:

Code: Select all

-bash-3.2$ drush pm-update twitter


gives the following information:

Checking available update data ... [ok]
Update information last refreshed: Sat, 03/02/2013 - 17:09

Update status information on all installed and enabled Drupal projects:
Name Installed version Proposed version Status
Drupal 7.20 7.20 Up to date
Chaos tools (ctools) 7.x-1.2 7.x-1.2 Up to date
CKEditor (ckeditor) 7.x-1.12 7.x-1.12 Up to date
Devel (devel) 7.x-1.3 7.x-1.3 Up to date
oauth 7.x-3.1 7.x-3.1 Up to date
Twitter (twitter) 7.x-5.4 7.x-5.5 Update available
Views (views) 7.x-3.5 7.x-3.5 Up to date

Code updates will be made to the following projects: Twitter [twitter-7.x-5.5]

Note: A backup of your project will be stored to backups directory if it is not managed by a supported version control system.
Note: If you have made any modifications to any file that belongs to one of these projects, you will have to migrate those modifications after updating.
Do you really want to continue with the update process? (y/n):


Hitting y gives the following output:

Project twitter was updated successfully. Installed version is now 7.x-5.5.

................................................................................................

No database updates required [success]
Finished performing updates. [ok]
-bash-3.2$


Now there are no available update in the Reports page on my drupal site, so drush functions as it shall. You find a list of drush commands on the drush site http://www.drush.org/

Additional information to the above article:

Note that there is a Drush Windows Installer

If you read the installation guide you find this information:

cwRsync Optional Components
This feature installs cwRsync in folder %ProgramFiles%\Propeople\Drush\cwRsync. It adds support for rsync command that is used for remote command invocation when Windows calls Linux/Unix server.


For more information on cwRsync see:

Litterature: http://www.packtpub.com/drush-drupal-co ... guide/book

Return to “Drupal”

Who is online

Users browsing this forum: No registered users and 1 guest