The best way to run a Drupal 7 cron via drush

Edit 2015/4/8: You also want to read this article from Mattias on preventing cronjobs to overlap.

Edit 2015/3/18: Check this article on how to install drush via composer, which is currently the preferred way to install.

This is the best way to run your Drupal 7 drush cron command from crontab:

# Run cron every 15 minutes, quiet
*/15 * * * * drush --quiet --root=$HOME/htdocs --uri= cron

# --quiet  means there is no output, so no mail every time cron runs
# --root   is a nicer way than first do a "cd $dir; drush cron"
# --uri    is needed so certain modules (like xmlsitemap and media)
#          don't generate urls like http://default/ but use the full
#          site url

A more extensive cron with a custom SHELL, PATH and MAILTO would be:

# If there is output, mail it to this address

# Add more paths

# Make sure we are using bash as shell (or any other shell)

# Run cron every 15 minutes, quiet
*/15 * * * * drush --quiet --root=$HOME/htdocs --uri= cron

# Run an import every night, output goes to MAILTO
0 2 * * * drush --root=$HOME/htdocs --uri= run-import

That’s all.

Mounting a remote filesystem using sshfs

It seems few people know that you can easily mount a remote filesystem over an ssh connection, using the pretty obviously named tool “sshfs”. It’s pretty buggy on Windows, but it works like a charm on OSX and Linux. You do need a stable network connection to keep the connection working fast though.


# Homebrew
brew install sshfs

# Ubuntu
sudo apt-get install sshfs

# CentOS
sudo yum install ssfs

Aliases in .bash_profile

I use aliases for most of my ssh connections and sshfs mounts. Combined with using my ssh key (with extra password) this gives me an almost instant login to servers by typing a simple alias for it.

# ~/.bash_profile
# Options for ssh and sshfs aliases
# These have been proven to be the best ones for Mac OSX so far
SSHOPTS='-v -4'

# ssh connection aliases
alias server01="ssh $SSHOPTS"

# sshfs mounts
alias fsserver01="sshfs $SSHFSOPTS -ovolname=server01 \
  karel@server01.local:/var/www/vhosts/ \

Using an sshfs mount to work

With these aliases in place I would start working like this:

# 1. Mount the remote file system

# 2. Open $HOME/Projects/ in my local editor

# 3. Login to the server to run my git commands etc:


A side note after using these kind of setups for almost 3 years: you need a very fast and reliable internet connection to make this work.

Also funky editors like PHPStorm and Eclipse cannot handle working on a mount like this (they perform a lot of directory and file scanning to discover things), but it works perfectly with Sublime Text 3.

A safer nginx virtual host config for Symfony2 sites

As Symonfy redirects all PHP requests to app.php, it’s a safe solution to only use app.php as your nginx fastcgi_pass script. This way it’s simply impossible to run PHP code from other files (e.g. malware that tries to inject code into your site).

Your webroot would still point to Symonfy’s web directory.


server {
  listen 80;
  root /var/www/vhosts/;
  index index.php index.html;
  location / {
    try_files $uri @app;
  location @app {

    fastcgi_pass unix:/var/run/php5-fpm.sock;

    include fastcgi_params;

    fastcgi_param SCRIPT_FILENAME /var/www/vhosts/;
    fastcgi_param SCRIPT_NAME /var/www/vhosts/;



Unlike a common PHP setup for nginx, there is no location match for *.php files now.

This setup can also be applied to Drupal’s setup, as Drupal does the same thing with the index.php file in the document root.

This information was taken from Gerry Vandermaesen’s The Unofficial ‘Best’ Practises on Symfony development.