Deployment tip: unexpected ‘class’ error in public/index.php

I’ve unexpectedly encountered a situation which might be useful to someone deploying projects. When it’s time to move projects from local environment to production (or staging) server, a lot of weird things might happen there. One of them is a parse error in public/index.php file.

Basically, when trying to load your Laravel 5.1 project in the browser, you might see this:


And if we look at the line 50 of public/index.php, it’s this:

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

Looks like a normal PHP syntax, right? What could be wrong here?
The thing is that syntax of ::class appeared only in version 5.5: see documentation.

So if you see this error on your (or your client’s server), it means that there’s an older PHP version there. In my case, it was 5.4.40.

With that, it’s useful to remember the requirements for specifically Laravel 5.1 version:
– PHP >= 5.5.9
– OpenSSL PHP Extension
– PDO PHP Extension
– Mbstring PHP Extension
– Tokenizer PHP Extension

For Laravel 5.0 it was all the same except PHP version:
– PHP >= 5.4

Hope that small but real-life story helps someone. Happy deployment!

Like our articles?
Check out our Laravel online courses!



Please enter your comment!
Please enter your name here