syntax error, unexpected T_CLASS, expecting T_STRING or T_VARIABLE or '$' in artisan

Published 6 months ago by abdoelsayed2016

iam using PHP 7.0.27 (cli) (built: Jan 23 2018 09:07:32) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies

when build cron job that error appear Parse error: syntax error, unexpected T_CLASS, expecting T_STRING or T_VARIABLE or '$' in /path_to_project/artisan on line 31 X-Powered-By: PHP/5.3.29 Content-type: text/html

tykus
tykus
6 months ago (623,140 XP)

X-Powered-By: PHP/5.3.29 means you are not using PHP 7

abdoelsayed2016

when using php --version

PHP 7.0.27 (cli) (built: Jan 23 2018 09:07:32) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies

Snapey
Snapey
6 months ago (960,075 XP)

Your cron is using an older version.

You must have more than one version available.

Snapey
Snapey
6 months ago (960,075 XP)

try which -a php

abdoelsayed2016

how can i used another version ?

abdoelsayed2016

/usr/local/bin/php

/usr/bin/php

/usr/local/bin/php

abdoelsayed2016
          • php /path_to_project/artisan schedule:run >> /path_to_project/log.txt
tykus
tykus
6 months ago (623,140 XP)

Check which of those binaries is PHP 7 and use that for your cron, e.g. if

/usr/local/bin/php --version
// PHP 7.0.27 (cli)

then

/usr/local/bin/php /path_to_project/artisan schedule:run >> /path_to_project/log.txt
abdoelsayed2016

/usr/local/bin/php --version

PHP 5.3.29 (cli) (built: Nov 13 2017 09:44:03)

Copyright (c) 1997-2014 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2014 Zend Technologies with the ionCube PHP Loader v4.7.5, Copyright (c) 2002-2014, by ionCube Ltd., and with Zend Guard Loader v3.3, Copyright (c) 1998-2010, by Zend Technologies
abdoelsayed2016

/usr/local/bin/php

/usr/bin/php

/usr/local/bin/php

all of them is php 5.3

abdoelsayed2016

any solutions plz ???

tykus
tykus
6 months ago (623,140 XP)

You clearly do not have the same PATH variable whenever cron runs that you in your session at the command line.

Do you have php70-cli as a command? Can you get the full path to this command, and use that in the cron job:

/path/to/php70-cli /path_to_project/artisan schedule:run >> /path_to_project/log.txt

Please sign in or create an account to participate in this conversation.