Env variables php

1. The problem I’m having:

I’m testing if caddy can replace our apache server with caddy and my only problem now is to get variables injected into the caddy server as envrionment variables that I can use in php files.
Currently I managed to create a test var

php_fastcgi unix//run/php/php7.4-fpm.sock {

	env testvariable 'hello'
}

When I check the php info I can see the variable but it appears under VARIABLES and not under ENVIRONMENT. How can I inject variables that appears under ENVIRONMENT in php info?

This is not the place where I expected and “env” var to appear. Maybe I’m missing out on something. Thanks

$_SERVER[‘testvariable’]

2. Error messages and/or full log output:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

3. Caddy version:

4. How I installed and ran Caddy:

a. System environment:

b. Command:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

c. Service/unit/compose file:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

d. My complete Caddy config:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

5. Links to relevant resources:

You’re using php-fpm, so you need to configure php-fpm with the env vars. Or use a PHP library like GitHub - vlucas/phpdotenv: Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically. to load them from a .env file.

The env in php_fastcgi is for FastCGI environment variables, which as you found, are passed to $_SERVER. It’s a different thing.

Ok, I see! Thanks alot for the help!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.