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

jordan.dobrev.88@gmail.com's avatar

Environmental variables mixture

Hi,

I have the following systems on the same machine:

  1. Laravel API REST server
  2. Laravel client system that uses the API to extract information

Turned out that when the client makes an API call somehow the environments are mixed, so I get the database env settings from system2(Client) in system1(Server). I know I can resolve the issue when I separate them using vagrant or sth like that so they behave like different systems, but how do I make it work if they have to be on the same machine.

0 likes
4 replies
jordan.dobrev.88@gmail.com's avatar

No. System 1 and System 2 are totally separate systems. They both run on the same machine.

When you execute a script on server 2 that makes an API call to system 1, the env() function in the configuration file for system 1 loads the information in the .env file for system 2. Simply said System 1 .evn variables are modified with the .env variables in system 2.

chaospower's avatar
Level 1

it's a bit confusing.

So system2 should have loaded api calls with system 1 env. But system 1 is loading system 2 instead of using it's own env? Are you using Laravel 5 or 4.2?

If you followed configuration correctly it's probably a bug somewhere.

http://laravel.com/docs/4.2/configuration http://laravel.com/docs/5.0/configuration

PHP should have loaded system 1's environment instead of system 2. Because system 2 is just request and receive. The env of system 1 should be the one to load.

What is your Webserver and PHP 5 setup (nginx + php5-fpm / apache php5-fpm) ?

My wild guess is probably due to global override. Since both are using 1 php, conflicting variables will be overwritten by the last assignment.

http://php.net/manual/en/reserved.variables.environment.php

If you can change the index to a different one, I think it will not conflict.

You should probably just run 2 virtual machines and share the same folder.

2 likes
mike_hasarms's avatar

I'm having this issue with Laravel 5.3 now. I have one Laravel install that sends a cURL request to the other install. When both Laravel instances are used in the combined HTTP request the second app inherits the wrong DB_DATABASE value from the first project.

Please or to participate in this conversation.