A config.ini file is a simple configuration file where you store settings outside of your code so they’re easy to manage and change without editing the source.
Structure:
- It’s text-based and usually divided into sections with
[brackets]. - Each section contains key = value pairs.
Here’s an example of an config.ini file:
[database]
host = localhost
user = myuser
password = secret
dbname = mydb
[app]
debug = trueWhat you define in them:
- Database credentials
- API keys
- File paths
- App settings (debug mode, language, etc.)
Laravel
Now in Laravel it works a bit differently, instead of config (configuration) files it uses .env (environment) files.
They are built rather similar they also use “key = value” pairs.
Here’s how an example of a .env file:
APP_NAME="MyApp"
APP_ENV=local
APP_DEBUG=true
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=mydb
DB_USERNAME=myuser
DB_PASSWORD=secret
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=nullThe main difference is that you write the keys in uppercase with “_”. Same as a config file you also define the following:
- Database credentials
- API keys
- File paths
- App settings (debug mode, language, etc.)
Here’s how we would do it at hosttech:
Wonderland
In Wonderland we use something called “object-style access” to get data from the config files. The Zend framework provides a way to easily read the information out of config files. You load the file into a object then you can access as mentioned before with the “object-style access”. Now while this is quite handy it also means that if you can’t call the framework or if there’s a problem your code also can’t access the config file usually meaning that the whole page will be down or at least part of it. Now while it can work without the autoloader it’s a lot more code you need otherwise since then you would need to call “require_once ‘Zend/Config/Ini.php’;” before each time you want to access something from the config file. With the autoloader you can just set it up once which is quite handy.
Here’s how the config file “can” look like:

Now to access something you save the data in a variable “$config” like so:
// set up the autoloader
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
$config = WonderlandRegistry::getConfig();
// getConfig() function
public static function getConfig()
{
return self::get('config');
}Now after you saved the data in the variable you can access it’s values like so:
// in the config file dns.url = ...
.$config->dns->url.
// or an example with the image above
.$config->maintanance->status.myhosttech
Now since the myhosttech part uses Laravel it uses .env files instead of config files.
Here’s how it “can” look like:

Now in myhosttech it works a bit different on how you access those values. You access the data saved in the .env file through config files, meaning that you for example have a config file called “services.php” in which you save something under the key-name “token” and then set the value of said token to what stand in the .env file. So in the code you call the path to the token stored in the config file, not directly the .env file.
Here’s how that looks like:
// call to the config file to the specified key
config('services.cloudtalk.myhosttech.api.token') // services file->cloudtalk->myhosttech->api->token
// said key in the services.php file
'token' => env('CLOUDTALK_MYHOSTTECH_API_TOKEN')
// value stored in the .env file (empty on purpose but would have a value normally)
CLOUDTALK_MYHOSTTECH_API_TOKEN= ...You could also directly access it from the .env file like so:
env('CLOUDTALK_MYHOSTTECH_API_TOKEN')There are a few reasons on why you go through config files instead of directly accessing the .env file, some are that it’s easier to understand when you look at the code and another is that then it’s easier to look something up or change something since it’s grouped in the config files. Meaning that you don’t have to look through all the .env files which can get rather long.
There’s also a security aspect to this, it makes it so that only specifically chosen variables become part of the apps usable config. This also means that if someone manages to temper with the .env file that it would only affect on the values of the config files not the real .env file.
