Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4598324
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:22:59+00:00 2026-05-21T23:22:59+00:00

Ways to store configuration for a Web App written in PHP? I’ve seen people

  • 0

Ways to store configuration for a Web App written in PHP?
I’ve seen people use .ini, basic .php, etc.
Also, define() or simple global variables?
Most information as you can find.
Also, are databases good methods of storing configuration?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T23:22:59+00:00Added an answer on May 21, 2026 at 11:22 pm

    There is no “Best Way ™” to store your application configurations. It really all depends on your application, the kind of configurations, how often they can/need to change, and how easy you want to make it to change them.

    Some people use a full singleton (or static) Config class for their application. Which looks something like this (with varying levels of complexity):

    <?php
    
    class Config
    {
    
        protected static $config = array();
    
        private function __construct() {} // make this private so we can't instanciate
    
        public static function set($key, $val)
        {
            self::$config[$key] = $val;
        }
    
        public static function get($key)
        {
            return self::$config[$key];
        }
    
    }
    

    This is handy because you can call it wherever you want in your application with Config::set() or Config::get(). You then have a central place that your entire application is configured, and you can make it as complex or as simple as you like. You can back things up to the database, memcached, etc, whatever.

    Which brings me to the next thing. Using the database is fine for things that need to be able to be changed on the fly and don’t necessarily have to have an “initial setting”. An example would be site application customization features (eg. currency, background color, header image, etc). The problem here is, you have to load that every time a page is loaded in your application. So to solve that, you can use a middle layer caching technology (like memcached if you like). That would be fast, way faster than the database, but still adds overhead because you have to load it on every page load.

    The fastest way, and consequently the “hardest” to change, is to use a config.php file or the like. This file would have $_GLOBALS array key definitions, or define()‘s for values that you need access to throughout your application. This is fast because it’s included in the request and hard coded in PHP, so all PHP has to do is interpret the file – no network IO or any added overhead other than the minimal overhead of including a file into your script. The things you’d store in these PHP files are things like your MySQL connection credentials, web service connection credentials, etc.

    For an application which has a lot of users and a lot of customizations, you’ll probably need to deploy a ‘hybrid’ of the methods, or come up with your own. For something that is just a standard application deployment, you might be able to get away with a very simple config.php type approach.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing on a LAMP(erl) stack and know of several ways to store
What are the ways to retrieve data submitted to the web server from a
Are there any ways to secure stored procedure consistency at the software level, so
Some ways to iterate through the characters of a string in Java are: Using
What ways are there to protect licensing enforcement mechanisms in C/C++? I know of:
There are a few ways to get class-like behavior in javascript, the most common
There are several ways to iterate over a result set. What are the tradeoff
What are the different ways (programmatically and otherwise) to determine what versions of .NET
Below are two ways of reading in the commandline parameters. The first is the
I see 2 main ways to set events in JavaScript: Add an event directly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.