Install CiviCRM tool cv without sudo

cv

With the CiviCRM command line tool cv you can run cron jobs and perform other related tasks from the terminal.

To install cv without sudo access, for example on shared hosting, you can install cv. First, you need to find (in this case in Scotch Box / Vagrant) the available environment paths with:

$PATH

Result:

-bash: /home/vagrant/.rvm/gems/ruby-2.4.1/bin:/home/vagrant/.rvm/gems/ruby-2.4.1@global/bin:/home/vagrant/.rvm/rubies/ruby-2.4.1/bin:/home/vagrant/bin:/home/vagrant/.local/bin:/home/vagrant/.nvm/versions/node/v6.10.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/vagrant/.rvm/bin:/home/vagrant/.rvm/bin: No such file or directory

In this case, /home/vagrant/bin is a registered path, and available to the default user, since it is located in /home/vagrant/bin, which is the same as ~/bin.

Install cv with these commands, standing in your home directory:

mkdir ~/bin # remember to check if this folder already exists
curl -LsS https://download.civicrm.org/cv/cv.phar -o ~/bin/cv
chmod +x ~/bin/cv

Test by running the command from terminal

cv api job.execute --user=admin --cwd=/var/www/public/your_website

Open cron
crontab -e
Enter this to run cv once every hour, as well as Drupal cron with Drush:

PATH=/home/vagrant/.rvm/gems/ruby-2.4.1/bin:/home/vagrant/.rvm/gems/ruby-2.4.1@global/bin:/home/vagrant/.rvm/rubies/ruby-2.4.1/bin:/home/vagrant/bin:/home/vagrant/.local/bin:/home/vagrant/.nvm/versions/node/v6.10.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/vagrant/.rvm/bin:/home/vagrant/.rvm/bin
# run CiviCRM cron with cv 
5 * * * * cv api job.execute --user=admin --cwd=/var/www/public/your_website

# Drupal cron via drush once every hour, assuming drush is in ~/bin
10 * * * * drush core-cron --root=/var/www/public/your_website