0

I developed a website using php 7.1.4 and Laravel 5.6. It works well on localhost, but after I finished it I found that the server I have to upload it to, has php 7.0.3. It doesn't work at all, all it shows is 500 internal server error.

I tried to change the version of MAMP to 7.0, and it shows this error:

[03-Jul-2018 14:17:22 Europe/Bucharest] PHP Parse error: syntax error, unexpected '?' in /Applications/MAMP/htdocs/agroinfo/vendor/symfony/http-foundation/Response.php on line 491 [03-Jul-2018 14:17:22 Europe/Bucharest] PHP Fatal error: Exception thrown without a stack frame in Unknown on line 0

Is there any way to make the project work with the current version of PHP (PHP 7.0.3). The reason I can't change the version of PHP on the server is that there is already another project there.

  • 2
    If you're deploying to PHP 7.0, you'll need to downgrade to Laravel 5.5 – iainn Jul 03 '18 at 11:33
  • And this is why your development server must **always** resemble your production server. In php 7.1, you can i.e. add function arguments like this `function(?string $string)` which means that the string can be null. Either rebuild the entire project in php 7.0 or update the other. – Loek Jul 03 '18 at 11:34
  • I would instead propose to research about docker. This would decouple the project from various server machines and give complete control over dependencies and upgrades, at the same time simplifying subsequent deployments and upgrades. – Simas Joneliunas Jul 03 '18 at 11:38

1 Answers1

1

Likely you wrote your function definitions using function testReturn(): ?string logic. This is a php 7.1 feature and will not work in earlier versions.

If your project allows, consider upgrading the php version before downgrading the project.

Another, recommended, option is to use Docker to package your application with a php 7.1 container. It will give you complete control over the project dependencies and decouple your project from the server machine

Simas Joneliunas
  • 2,890
  • 20
  • 28
  • 35