Reputation: 9221
On my local machine I'm using docker to serve my php, I included the .env file using the following lines in my docker-compose.yml file, which is working fine, I can see the variables using getenv()
, the issue is I can't get them to work on my online server.
app:
env_file:
- .env
I use deployer to deploy my website to my host (which is running nginx and php-fpm), using the following deployer script
host('staging')
->hostname('app.host.be')
->port(22)
->stage('staging')
->set('deploy_path', '/var/www/')
->set('branch', 'master')
->identityFile('~/.ssh/id_rsa')
->user('admin')
->set('env', [
'MY_ENV' => 'test'
]);
I also tried setting the env as outside of the host definition
set('env', [
'MY_ENV' => 'test'
]);
host('staging')
->hostname('app.host.be');
But running getenv()
is only returning the following results on my live server
array(2) { ["USER"]=> string(8) "www-data" ["HOME"]=> string(8) "/var/www" }
Upvotes: 1
Views: 1453
Reputation: 78
I would leave a comment, but I don't have enough reputation, yet.
Please take a look at this issue https://github.com/deployphp/deployer/issues/1504
Environment variables in PHP are a bit different, they are not really system level variables, the way docker sets it for example.
So the variables you set with deployer are available to PHP for the duration of that run.
Depending on your hosting, you might have enough permissions to modify environment variables on the VM, so you should research a way to modify those. Preferably through a continuous deployment pipeline.
EDIT: please also look into Dotenv in PHP and check out a recommended flow based on that.
Upvotes: 2