Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

milewski's avatar

Laravel Artisan Commands Through Cron Tab?

I am having problems executing cron jobs in my project.. i have a queue, if i simples go to the terminal and execute queue:work it will process, however if i try using the console command through cron job like this:

//App/Console/Kernel.php
$schedule->command('queue:work database --queue=default --tries=3')->everyMinute();
        $schedule->command('queue:work database --queue=emails --tries=3')->everyMinute();

i get the following error outputted to my log file

local.ERROR: exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory' in /Users/me/laravel_project/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:50

and the crontab is set correctly as if i append a custom command just to log::info("hi"); it works

0 likes
2 replies
jimmck's avatar

This what I do to make it work. This is from an email I sent, it references Laravel 4, but all applies.

Hi,

I had to put the path in my cron file.  Once done done, all works fine.  MAC OSX, Laravel 4, PHP 5.6.3

Here is my file:

SHELL=/bin/bash
PATH=/Applications/:/Applications/XAMPP/xamppfiles/bin/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
* * * * * php /Users/jimm/WebProjects/laravel42/artisan scheduled:run 1>> /dev/null 2>&1


This for a MAC running XAMP.

milewski's avatar
milewski
OP
Best Answer
Level 1

Oh Thanks man @jimmck after seeing your answerer i figure out what was wrong.. it`s indeed the path... you just need to specify the path where your php lies, i guess by using just the PHP it will point to the old version which ships on the OS..

then i just had to change from:

* * * * * php /Users/jimm/WebProjects/laravel42/artisan scheduled:run 1>> /dev/null 2>&1

to:

* * * * * /Applications/MAMP/bin/php/php5.6.2/bin/php /Users/jimm/WebProjects/laravel42/artisan scheduled:run 1>> /dev/null 2>&1

and everything works fine now :)

3 likes

Please or to participate in this conversation.