In this FuelPHP Configuration chapter, we will understand how to configure a FuelPHP application. By default, configuration files are stored inside the fuel/app/config folder. The application’s main configuration is fuel/app/config/config.php. The configuration is specified using PHP’s associated array.
Overview
By default, all default configuration files are defined in fuel/core/config folder. To override a default configuration, add the corresponding key in the /fuel/app/config/config.php file and modify the value. We can use βdot-notationβ to simplify multi-dimensional array. For example, the following configurations serve the same purpose (load specified packages).
array("always_load" => array("packages" => array( ... ) ) ); always_load.packages = array( ... );
Configuration can be grouped by purpose and specified using different files such as db.php for database configuration, package.php for package management, etc.
Type of Configuration Format
FuelPHP is quite flexible and provides different format to specify the configuration. The default configuration format is PHP using php array. The other options are β
INI β Simple text-based configuration supported by many softwares including PHP language itself.
[group] key = value
YAML β Easy to understand, indentation based, and human readable configuration management.
group: key: value
JSON β Easy to understand and most used file format by the developers.
{ "group" : { "key": "value" } }
Memcached β Stores the configuration in a memcached server. The memcached server details can be specified in the main configuration file, fuel/app/config/config.php using config.memcached entry.
DB β Stores the configuration in RDBMS System. The table structure of the configuration table is as follows.
CREATE TABLE IF NOT EXISTS `config` ( `identifier` char(100) NOT NULL, `config` longtext NOT NULL, `hash` char(13) NOT NULL, PRIMARY KEY (`identifier`) )
The database and table details can be specified in the configuration file using config.database and config.table_name entries.
Environment
Environment enables FuelPHP to work in different modes by loading different configuration. FuelPHP supports the following environment.
- Development β \Fuel::DEVELOPMENT sets the development mode
- Production β \Fuel::PRODUCTION sets the production mode
- Test β \Fuel::TEST sets the testing mode
- Staging β \Fuel::STAGING sets the staging mode
FuelPHP also supports the creation of a new environment. This will enable every developer to have his/her own configuration setting and they can enable it while coding and testing the application. The configuration of a specific environment can be added by simply creating a folder with the environment name (example: test) and placing the configuration file inside the newly created folder, shown as follows.
. βββ config.php βββ db.php βββ development β βββ db.php βββ production β βββ db.php βββ routes.php βββ staging β βββ db.php βββ test βββ db.php 4 directories, 7 files
Set Your Environment
There are three ways to set up your environment.
Option 1 β Set environment with web server’s environment variables. Add the following code in the virtual host section in httpd.conf file of Apache web server. It can be added in .htaccess file as well.
SetEnv FUEL_ENV production
Option 2 β Set environment with FuelPHP bootstrap file, /fuel/app/bootstrap.php
Fuel::$env = (isset($_SERVER['FUEL_ENV']
Option 3 β Set Environment using Oil
$ env FUEL_ENV = production php oil -v
It produces the following result.
Fuel: 1.8 running in "production" mode
Next Topic : Click Here