How to set environment variables for my wordpress

Expected behavior

Actual behavior

Additional Information

Steps to reproduce the behavior

good night, I’m hosting a wordpress site using ECS FARGATE and I need to define database variables (rds) within my WP-CONFIG.PHP file, I’m a beginner and I’m having a lot of difficulty

What have you tried? What exactly have you set up? What is working, and did you use it without Docker? Many more details will increase your chances for help.

hello dear, good afternoon. so far I created the dockerfile (see the attachment) configuring the variables of my RDS database. I also have my wordpress files that are inside an AWS EFS file system. What I would like to do is make my wordpress php use these variables

php

I think Arjan asked the right question which you did not answer

but your code shows that you did not try it without Docker because it would not work that way either. Take a look at the PHP documentation

https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.single

Note : Unlike the double-quoted and heredoc syntaxes, variables and escape sequences for special characters will not be expanded when they occur in single quoted strings.

If you want to use environment variables in PHP then you need to search for “PHP environment variables” to find an other part of the PHP documentation:

https://www.php.net/manual/en/reserved.variables.environment.php

And see the recommended See also section to find getenv().

So you either use

define('DB_NAME', getenv('DB_NAME'));

or

define('DB_NAME', $_ENV['DB_NAME']);

If you want to use PHP-FPM later, you will also want to read the documentation of the PHP configuration:

https://www.php.net/manual/en/install.fpm.configuration.php

clear_env bool
Clear environment in FPM workers. Prevents arbitrary environment variables from reaching FPM worker processes by clearing the environment in workers before env vars specified in this pool configuration are added. Default value: Yes.

1 Like