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
2
Answers
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 yourpublic/index.php
and double check because that error is a symptom you are running a version of php lower than 7.1The 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:
For servers without CloudLinux:
For servers with CloudLinux:
*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..