You are right, but there are better ways to do that.
One way is using dotenv. Trending way for managing configurations.
from dotenv project:
Storing configuration in the environment is one of the tenets of a
twelve-factor app. Anything that is likely to change between
deployment environments – such as database credentials or credentials
for 3rd party services – should be extracted from the code into
So what you are doing is right, the way you are doing may not be best.
Since you are doing require_once(), you may want to check if file exists else it would be fatal error.
The problems I see with keeping that path in Apache:
- You may need to modify apache config and restart / reload Apache for your new configurations
- Not all developers in your team may have access to Apache config. If the config is in code itself, like .env, it would be easy for developers.
- Debugging would be easy with .env
- If you plan to unit test, mocking would be easy.