2

I have SSH access on shared hosting and I followed this guide to install the composer: https://getcomposer.org/download/

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

I got the composer.phar installed/downloaded into custom dir /composer/composer.phar

And it works if you run it php composer.phar.

Then I ran php composer.phar require drush/drush:7.x to install drush. And it installed in the /composer/vendor/bin.

Now, if I run php composer.phar drush I get error:

[Symfony\Component\Console\Exception\CommandNotFoundException]
  Command "drush" is not defined.

I set paths PATH=$PATH:~/composer/vendor/bin and PATH=$PATH:~/composer/

If I run just composer or drush I get The program 'composer' is currently not installed. To run 'composer' please ask your administrator to install the package 'composer'.

2

Rename composer.phar to composer and move it to $HOME/bin then make sure $PATH contains $HOME/bin. You can do that by putting the line export PATH=$PATH:$HOME/bin/vendor/bin in your .bashrc and then doing a source .bashrc

Once you can run echo $PATH and see a string containing your home directory followed by /bin/vendor/bin and if you have moved composer.phar there under the name composer you know that the computer will look there when you run a command (composer for example).

The following command is what worked for me to install Drush with composer:

composer global require drush/drush:dev-master

| improve this answer | |
  • It's shared hosting, I have no /bin/. Root dir contains dirs like /htdocs/, /lib/, /conf/ – user3108268 May 16 '17 at 9:19
  • $HOME/bin means bin in your home directory. – Kartagis May 16 '17 at 9:27
  • source .bashrc returns -bash: .bashrc: No such file or directory – user3108268 May 16 '17 at 9:40
  • Okay, I had to copy .bashrc from /etc/skel/.bashrc to $home dir in order to run source .bashrc and now composer runs globally but composer drush reports same error. – user3108268 May 16 '17 at 9:52
  • 1
    composer global require drush/drush:dev-master More info: whaaat.com/installing-drush-9-using-composer Be a little inventive, can't expect us to give the literal answer to every question :) – Ruben Beekman May 16 '17 at 11:32
4

you can also install manually as long as you have ssh access

# get drush latest 8 version
# drush 8 works with D8, D7 and D6
# https://github.com/drush-ops/drush/releases
wget https://github.com/drush-ops/drush/releases/download/8.3.2/drush.phar

# make it executable
chmod +x drush.phar;

# move it to home directory or any other directory
mv drush.phar ~/drush;

# go to that directory
cd ~

# find out the path to the directory
pwd
# the output would look similar to this
# /home/your_user

# edit the following file 
nano .bashrc
# or 
# nano .bash_profile

# add this the end of the file
alias drush='/home/your_user/drush';

# use the alias you just setup
source ~/.bashrc;
| improve this answer | |
  • Thanks! That worked for me, I only had to change the alias to alias drush='php /home/your_user/drush/drush.phar --php=/usr/bin/php' – tmsss Sep 18 '19 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.