Laravel 5.6: Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE)

Published 5 months ago by patriknemecek

Hello, when I was solve problem with TrustedProxies, I got another error 500 with error message:

local.ERROR: Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) {"exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) at vendor/symfony/routing/Route.php:53).

Before upgrade all works fine.

Best Answer (As Selected By patriknemecek)
Snapey

create a simple test.php page in your public folder

put phpinfo() in it and then hit test.php in your browser

Sometimes the php version being used by the webserver can be a different version to the command line

Snapey
Snapey
5 months ago (960,065 XP)

did the 'upgrade' also significantly change the Laravel version?

patriknemecek

Output of "php artisan --version" is Laravel 5.6.4

Cronix
Cronix
5 months ago (651,390 XP)

Make sure your php version matches what the version of laravel you are using requires. Different laravel versions require a different minimum php version.

Edit: Laravel 5.6 requires PHP >= 7.1.3 https://laravel.com/docs/5.6#server-requirements

Snapey
Snapey
5 months ago (960,065 XP)

yes, 5.6 now, but what was it before? Your error is typical of an incompatible php version

patriknemecek

I use PHP 7.2.2, Laravel 5.6 requires PHP 7.1.3 or higher.

patriknemecek

Yes, it is probably problem with PHP, now I tried fresh Laravel install and same error.

Snapey
Snapey
5 months ago (960,065 XP)

create a simple test.php page in your public folder

put phpinfo() in it and then hit test.php in your browser

Sometimes the php version being used by the webserver can be a different version to the command line

patriknemecek

Yes you are absolutely right, I didn't thought my Apache2 use PHP 7.0

Sandburg2011

Can someone please explain how to update the Apache php version to 7.2?

HafizSaifullah

I solved the above problem by disabling 7.0 and enabling 7.2 just like in the below link

AhmedHelalAhmed

Thank you I faced the same problem

danielme

Had the same issue, forgot to disable php 7.0 before enabling 7.2 module in apache (nothing changes in apache and no errors are given if you just enable 7.2 without disabling 7.0 first).

Apache: "sudo a2dismod php7.0" "sudo a2enmod php7.2" "sudo service apache2 restart"

Also handy if you are on Ubuntu/Debian: "update-alternatives --config php" lets you set the default php version for CLI, this way you can jump back and forth between php versions to use as default.

Here is a nice guide with a lot of info you need regarding php versions and apache: https://thishosting.rocks/install-php-on-ubuntu/

debbiev

If you have shell access, check out your $PATH. Mine was picking up an old version of php.

whereis php echo $PATH

I found the right version of php here: /opt/php71/bin

so I add this line to the end of my .bashrc

export PATH=/opt/php71/bin:$PATH

Now composer doesn't error. and php artisan runs great!

:-D

PS. The version of php that you're using in the shell may be different from the version used to serve your site. That can be fixed in cpanel's php selector.

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