Development code during deployment

Good day to you all, I have a question regarding the development code during the deployment of a PHP project app.

In using APIs for a project which we often need an API key along with it for it to be functional. We can store the key/s inside the .env file to hide those data by not hard coding them into the source code. In PHP people uses libraries like phpdotenv to read those data and use it for the application.

Now my question is when we use libraries such as phpdotenv (specified in the “require-dev” section in the composer.json), wouldn’t deploying the app with those code cause the app to crash in the production server? as the library is only downloaded in our development server. (assume I’m using Heroku for my hosting)

Hello,

First, IDK much specifically about PHP development, but I do know full stack development in other languages (currently focusing on full-stack TypeScript)

So I assume when you deploy your PHP app to Heroku, following a guide similar to this one, Heroku will setup the environment with the same packages you need/have locally by installing them automatically. This way you can still use external libraries, like phpdotenv.

The only thing about the phpdotenv is that technically you could also set environment variables to the instance itself in heroku, rather than push a .env file with your source. This way if you need to make changes you can just change the value(s) in heroku’s admin panel, and it will automatically restart the instance to get the new environment
variables. This will also allow you to specify different production environment variables than you have locally.

You can still have the package installed and used, it just wont really add/find anything in production/heroku.

1 Like

I see, thanks for the answer, I’ll research more on how to setup the environment variable in Heroku.

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