View Full Version : command line php

07-10-2009, 12:22 AM
Is there a way to get php5-cli installed on a server here with westhost? I have been developing in Drupal for a while now and just recently ran across Drush. It would allow me to administer my so SO much easier, but it is php run from the command line.

I have drush installed but when I call the drush executable I get the following:
-sh: ./drush: /usr/bin/env: bad interpreter: No such file or directory

I ran into something similar on my ubuntu local dev machine, but apt-get install php5-cli took care of it.

Since we can't use rpm or other package managers from what I can tell, is there a way for me to get the php command line goodness that I need?

I appreciate any help.

07-10-2009, 11:18 PM
Forget about the original question. What I really wanted was to run drush and was barking up the wrong tree when it didn't work right away. Lemme 'splain..

After some digging around I was able to run drush as I wanted without doing anything crazy.

BTW, drush is a Drupal command line scripting tool that is pretty awesome.

It turns out that php5 already has the ability to run php scripts from the command line. So a regular install of php5 done from the Site Manager will work fine.

So, if you use drupal on westhost and want to play with drush, this is what I did.

Get drush and extract it to wherever you want, I put it in /home/username/drush

I made a backup of the drush executable so I could reference it as I am not much of a shell scripter.
With the new copy, I changed the first line from

#!/usr/bin/env bash


Doing this allows it to be interpreted by the sh shell that is the default for westhost.

Then I had to change line 42 from:

41 # Alternatively we run with straight php, which works on most other systems.
42 /usr/bin/env php $SCRIPT_PATH "$@"

41 # Alternatively we run with straight php, which works on most other systems.
42 /usr/bin/php $SCRIPT_PATH "$@"

This is where the php executable is located. Earlier in the code it checks for php-cli, which I couldn't find anywhere. But the default php works fine.

The last thing I did was alias the drush command. Drush does different things based on where you execute it, so it's very handy to have it aliased so you can run it under different areas of drupal or in separate installations.

Find your .bashrc profile in the root of your vps. I figured it would be in my home directory, but that is not the case. Edit the .bashrc file and add this to the alias section of the file:
alias drush='/path/to/my/drush'
replacing the /path/to/my with your path and finishing with the actual command being aliased.

Hopefully this will come in handy for someone else.

Cheers! :)