Using Laravel on php 7.0

lucasvm1980 picture lucasvm1980 · Aug 10, 2018 · Viewed 10.9k times · Source

I have installed Laravel 5.5 and I'm getting the same error, documentation says this:

  • PHP >= 7.0.0
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension

I ran: $ php artisan --version` $ Laravel Framework 5.5.42

and I'm getting this error:

Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_PARSE) Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE)

Is the documentation wrong? I'm using: https://laravel.com/docs/5.5/installation#installing-laravel My server can only use PHP 7.0. Not 7.1. Is there no way to run Laravel on 7 anymore?

I'm installing via composer.

Is there a way to download a compatible version with 7.0?

Answer

Ignacio Alles picture Ignacio Alles · Aug 10, 2018

If you have PHP 5.5 (actually 5.5.9 or greater) you should use Laravel 5.2.

If you have PHP 7.0 you can use Laravel 5.5.

The error you mentioned is because you are using PHP 5.5 which does not support PHP 7 Null coalescing operator (??) and it is being used somewhere in Laravel code.

As you said your server supports PHP 7.0, you might have more than one PHP versions installed on your system. Check PHP version running php --version.