CLI

Checking Ubuntu Version Number via the Command Line

When creating dev and staging environments based on an existing production environment (I know, right) it is useful to get the version of Linux you are running. In Ububntu, just fire up your terminal and type:

lsb_release -a

This will output something similar to:

Distributor ID: Ubuntu
Description:    Ubuntu 9.10
Release:        9.10
Codename:       karmic

Woot.

Install Drush on a Server You Don't Have Admin Rights To

I've been working with quite a few Drupal sites in the past couple years and recently one of my favorite tools to use has become drush. For those of you who aren't aware of it, drush is a command line utility (drush = DRUpal SHell) that makes management of a Drupal site much more bearable. Drush is a great tool to use and is quite simple to install on your system when you have admin rights to the box but what about those of us on shared hosting systems? For us, we have no admin rights but if you've picked a good hosting company, you'll have command line access and a .bashrc file (or similar e.g. bash_profile depending on your server distro).

Once you have command line access, create a directory on the server where you'll keep any programs you choose to install. I created a "bin" directory in my user's home.

mkdir bin

Once you've created that directory, use wget and the link to the latest drush version to download the tarball.

wget http://ftp.drupal.org/files/projects/drush-All-versions-3.0-beta1.tar.gz

Once it downloads, extract it.

tar xzvf drush-All-versions-3.0-beta1.tar.gz

cd into the newly created directory and make sure the drush* file is executable. If not,

chmod u+x drush

Now you have drush on your system but it would be quite cumbersome to have to type the full path to the executable as well as as the drush options. In order to alleviate this we have two choices: we can either export our PATH or setup an alias in our .bashrc file. I choose the latter, but I'll show you both options. First, however, you'll need to know the full path to the drush executable. Inside your ~/bin/drush directory, execute the following:

pwd

So your full path will be something like: /home/mysite/bin/drush/drush
Onto setting up the shortcuts to only have to type 'drush'

PATH option:

export PATH=$PATH:/home/mysite/bin/drush/drush

.bashrc option:

vi .bashrc

Inside the file, you'll add an alias (press 'i' to enter insert mode)

alias drush='/home/mysite/bin/drush/drush'

then save the file (type :wq)

The downside to using the .bashrc option, however, is that you'll have to start a new terminal session to begin using the alias (or type the same alias in the command line so you can use it this session then any other session you start it reads from the .bashrc). So exit then fire up your terminal again.

From here you can execute the entire suite of drush commands simply by using the word 'drush' followed by any drush options just like you would in a normal drush install.

To recap, simply:

  • open a terminal on your server
  • create a bin directory
  • download and extract drush into the bin directory
  • ensure drush is executable
  • get the full path to the executable then either
  • 1) add the full drush path to your PATH variable
  • or

  • 2) alias drush to the full drush path and restart you terminal session

*note: instead of executing a pwd to get the path to your drush install, you could use ~/bin/drush/drush if indeed your bin is in your home directory but I think it's best practice to use full, human readable paths to alleviate any ambiguity.

Latest Video


only search Coder's Wasteland
Powered by Drupal, an open source content management system

Digg this