0

I have hosted by project on shared hosting where my 'app' folder i outside public_html The php version is 7.3.5, the issue i am having is.. i am have created a cron job to automatically backup the project database but i keep getting this error on my logs;

[08-Jun-2019 21:04:01 UTC] PHP Parse error:  syntax error, unexpected '?', expecting variable (T_VARIABLE) in /home/username/app-folder/vendor/zendframework/zend-diactoros/src/functions/marshal_uri_from_sapi.php on line 83 

I am using spatie/laravel-backup.

My cron is set as

*   *   *   *   *   php /home/username/app-folder/artisan backup:run 
3
  • Sounds like CLI version is different. Whats the code, and what does the version come back as if you run php --version? Commented Jun 8, 2019 at 21:47
  • That was what I initially thought so i created a route; Route::get('phpinfo', function () { return phpinfo(); }); and am getting PHP Version 7.3.5 Commented Jun 8, 2019 at 21:50
  • When running in command line as well as web? CRON uses CLI so you must verify both versions are the same Commented Jun 8, 2019 at 21:53

2 Answers 2

5

Have you checked that file at line 83?

I did, on Github, I see the only question mark on that line is a ?int in the method signature.

I googled for 15seconds and found that it's a new feature of PHP 7.1 . So I checked composer.json of that package and see that it requires "php": "^7.1".

Are you sure you are running PHP 7.3.5 on that machine? Please put a phpinfo(); exit(); in your public/index.php and double check because that error is a symptom you are running a version of php lower than 7.1

Sign up to request clarification or add additional context in comments.

Comments

1

The error represents an issue with PHP scripts written for PHP 7.X and above that use an older version of PHP.

The feature which is used is called a Null Coalesce Operator.

You can read more about it from PHP's official documentation here - https://www.php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op

The cron which you're using is invoking the php binary directly, which is the default version set to be used by WHM/cPanel

If you know the direct path to your PHP binary you can directly call it when setting up your cron like:

*   *   *   *   *   php /home/username/app-folder/artisan backup:run 

For servers without CloudLinux:

*   *   *   *   *   /opt/cpanel/ea-php70/root/usr/bin/php /home/username/app-folder/artisan backup:run 

For servers with CloudLinux:

*   *   *   *   *   /opt/alt/php70/usr/local/bin/php /home/username/app-folder/artisan backup:run 

*Note: You can change hte php70 string in the two example paths above with any other PHP 7.X version installed, for PHP 7.1 - php71 etc..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.