+ 2

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) Or is there another way in using environment variable :|

8th Mar 2021, 12:44 PM
Leon lit
Leon lit - avatar
3 odpowiedzi
+ 13
If business logic of your program relies on some dev dependencies, the program will crash in production, because dev dependencies are installed only in the dev environment. So, the answer is yes, the production server will fail in your case. The phpdotenv installation guide implies that you shouldn't install it as a dev dependency: https://github.com/vlucas/phpdotenv#installation Services like Heroku are usually used to emulate the production environment. I would recommend to keep it that way, so that any successful deployment on Heroku would mean the real production deployment will be successful as well.
10th Mar 2021, 6:05 AM
Igor Makarsky
Igor Makarsky - avatar
+ 1
Oh I see, alright thanks a lot. I'll research more on how to emulate production environment in my local.
10th Mar 2021, 10:13 AM
Leon lit
Leon lit - avatar
0
akrm
6th May 2021, 7:58 PM
اكرم الشاعري
اكرم الشاعري - avatar