PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, January 12, 2022

[FIXED] Where do I put my website configuration values in a LAMP server setup?

 January 12, 2022     apache, configuration, lamp, php, webserver     No comments   

Issue

I have usually put database and website-specific configuration values into global variables within a .php file. This gets included into any page that needs to access the database.

Is there anywhere more sensible that these things should go? Can I add arbitrary values to php.ini, and if so how? Or how about http.conf in apache? Can I configure my website that way?

Ideally, I'd like a solution that means the config isn't being read on every single request.


Solution

I found out a better way through fiddling around. You can add arbitrary config options to php.ini, e.g.

[MyGreatWebsite]
dbname=db_awesome

And you can retrieve them with the get_cfg_var function, e.g.

get_cfg_var('dbname')

It's not exposing things through phpinfo (As an env variable would) and it's only reading the config once (Verifiable because changing the values requires a server restart)



Answered By - izb
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing