Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

zaster's avatar

Different PHP versions in single digital ocean droplet(LEMP)

I have hosted several laravel websites in a single digial ocean droplet with different php versions.

Now i realise that when i run something like

php artisan

I get different erros, such as From Site1

Opis\Closure\SerializableClosure implements the Serializable interface, which is deprecated. Implement __seriali ze() and __unserialize() instead (or in addition, if support for old PHP versions is necessary)

From Site2

PHP Fatal error: During inheritance of ArrayAccess: Uncaught ErrorException: Return type of Illuminate\Support\Collection::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/site2/vendor/laravel/framework/src/Illuminate/Support/Collection.php:1693

When i do a

php --version

It shows

PHP 8.2.2 (cli) ....

However, in different nginx server blocks the php versions are mentioned as

fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;

etc...

I think the errors are related to composer.json

0 likes
4 replies
LaryAI's avatar
Level 58

It seems like you have multiple Laravel projects running on the same server with different PHP versions. To fix the errors you're seeing, you need to make sure that each project is using the correct PHP version.

Here's what you can do:

  1. Update the PHP version for each project in its respective Nginx server block. For example, if you have a Laravel project running on PHP 7.2, you should have the following line in its server block:
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
  1. Make sure that each project is using the correct version of PHP by running the following command in each project's root directory:
php --version

This should output the correct version of PHP that the project is using.

  1. If you're still seeing errors, make sure that each project's dependencies are compatible with the PHP version it's using. You can do this by running the following command in each project's root directory:
composer update

This will update the project's dependencies to the latest compatible versions.

  1. Finally, make sure that each project's composer.json file specifies the correct PHP version. You can do this by adding the following line to the config section of the file:
"platform": {
    "php": "7.2"
}

Replace 7.2 with the correct PHP version for each project.

By following these steps, you should be able to run multiple Laravel projects on the same server with different PHP versions without any issues.

CamKem's avatar

You can't have multiple version of php running on the same server, you will either need to upgrade Laravel for each project (with something like Laravel Shift) or create a seperate server for each Laravel app.

zaster's avatar

@camkem Sorry. I corrected the question now. It should be single digital ocean droplet and multiple server blocks

CamKem's avatar

@zaster Thanks, I understand better now. Rather than me typing it all out, Here is link for a in-depth step by step guide on how to setup & configure it. Plus the guide has links to other guides that contain related tutorials for some of the steps.

If you get stuck along the way create a new thread with more specific details around which part you are stuck with. Good luck with it!

Please or to participate in this conversation.