Search code examples
sshlaravel-artisanlaravel-6

Laravel 6: Cannot run any artisan command on the server


[UPDATE]

edited artisan file like this

ini_set('display_errors',1);
error_reporting(-1);

and I got this error

Parse error: syntax error, unexpected '?' in /home/u635130117/domains/example.com/public_html/laravel/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php on line 500

Here's the code

if (isset($arguments[1]) && is_string($arguments[1])) {
        return $factory->of($arguments[0], $arguments[1])->times($arguments[2] ?? null); //line 500
    } elseif (isset($arguments[1])) {
        return $factory->of($arguments[0])->times($arguments[1]);
    }

I have connected to the shared hosting using SSH but can't run any artisan command like clearing cache or listing artisan commands I get nothing at all no output. I tested creating a new command and it's not created too.

enter image description here


Solution

  • The parse error occurs if the php version is to low. So we discovered there are more than one versions of php installed on the server after the execution of php -v returned php version 5.6.40.

    Finally in the phpinfo were the path of the php 7 version which is also being used by the webserver. This was /opt/alt/php72/usr/bin/php.

    Commands can now executed by using /opt/alt/php72/usr/bin/php like /opt/alt/php72/usr/bin/php artisan key:generate.

    You can also create an alias like php7 or just php for this. It's described here.