Hi everyone! I’m Darshan Hiranandani, working on deploying a PHP application to App Platform and need some help with configuring environment variables. Can anyone share their experience or best practices for setting up environment variables in this environment? I’m looking for tips on how to manage and secure these variables effectively.
Regards Darshan Hiranandani
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Heya @darshanhiranandani,
I’ll recommend you to check the following docs :
https://docs.digitalocean.com/products/app-platform/how-to/use-environment-variables/
It’s exactly what you are looking for
Hi Darshan,
Deploying a PHP application on DigitalOcean’s App Platform and configuring environment variables is straightforward!
Define Variables in App Platform:
Use Environment Variables in PHP:
getenv()
or $_ENV
.$dbHost = getenv('DB_HOST');
$dbUser = getenv('DB_USER');
$dbPass = getenv('DB_PASS');
Feel free to share more information about your PHP app setup and I can give you more details on this!
Some things that you should always consider are:
Sensitive Data Handling:
Use a .env
File Locally:
.env
file to store environment variables.vlucas/phpdotenv
to load variables from the .env
file into your PHP environment.require 'vendor/autoload.php';
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
Version Control Exclusions:
.env
file is included in your .gitignore
file to prevent it from being committed to version control.# .gitignore
.env
For more detailed instructions, you can refer to the official DigitalOcean documentation.
Hope this helps, and happy deploying!
- Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.