Quick links: Content - sections - sub sections
EN FR
Jelix 1.8.1

Section: Configuration files

^ Configuration Modules directories »
Switch to language: FR

A Jelix application have several configuration files:

  • A project.xml file, describing general information about the application
  • A module.xml file in each module, describing general information about the module
  • A mainconfig.ini.php file for the global configuration
  • A localconfig.ini.php for configuration specific to environment where your application is installed
  • A config.ini.php file for each entry points
  • A liveconfig.ini.php file to store parameters that are changed during the live of the application
  • A profiles.ini.php for connections profiles (database configuration for example).
  • A urls.xml file that defines the mapping between URLS and controllers.
  • A framework.ini.php listing all available entry points.

All are automatically generated when you create an application or a module (except localconfig.ini.php). However, you have to modify them to bring additionnal information or to change parameters.

Except project.xml and module.xml files, configuration files are in app/system/ for default parameters (mainconfig.ini.php, config.ini.php, urls.xml...), or var/config/ for parameters specific to the server environment (localconfig.ini.php, profiles.ini.php...).

Note: before Jelix 1.7, all files were into var/config/).

This chapter presents these files. See the chapter on configuration details to know more.

The project.xml file

The file project.xml contains some informations about the application. Here is an example:


<?xml version="1.0" encoding="iso-8859-1"?>
<project xmlns="http://jelix.org/ns/project/1.0">
    <info id="testapp@jelix.org" name="testapp" createdate="2017-01-01">
        <version>1.0</version>
        <label lang="en-EN">Testapp</label>
        <description lang="en-EN">Application to test Jelix</description>
        <licence URL="http://www.gnu.org/licenses/gpl.html">GPL</licence>
        <copyright>2005-2017 Laurent Jouanneau and other contributors</copyright>
        <creator name="Laurent Jouanneau" email="laurent@jelix.org"/>
        <homepageURL>http://jelix.org</homepageURL>
    </info>
</project>

The module.xml file

A module.xml file must be present in each directory of modules. It describes some general information, and dependencies with other modules.


<module xmlns="http://jelix.org/ns/module/1.0">
    <info id="jelix_tests@testapp.jelix.org" name="jelix_tests">
        <version>1.0</version>
        <label>Jelix tests</label>
        <description>unit tests for jelix</description>
    </info>
    <dependencies>
        <jelix minversion="1.6.0" maxversion="1.7.*" />
        <module name="testurls" minversion="1.0.2" maxversion="1.1b1" />
        <module name="jauthdb" />
        <module name="jacl2db" />
        <module name="jacldb" />
    </dependencies>
</module>

The file app/system/urls.xml

It defines the mapping between URLS and controllers.

You don't have to define all urls, since default urls are index.php/<module>/<controller>/<method>.

See the dedicated chapter.

Note: before Jelix 1.7, this files was optional, because different URLs engine were available. Since Jelix 1.7, it is mandatory, and should contain at least the mapping for the url /.

app/system/framework.ini.php file

This file contains the list of entry points. It is mainly used by the installer.

Configuration ini files

Jelix framework configuration is stored in an ini-like file. It is a file structured by sections ([section name]). Each section is a collection of parameter-name=value pairs. There is a generic section, un-named, usually at the start of such file.

The main configuration file is app/system/mainconfig.ini.php. However you could have different parameters for each entry point, and for each environment. This is why there are additionnal ini files, which are merged with the main configuration file at runtime.

app/system/mainconfig.ini.php

As said before, each entry point may have its specific config file. Although in practice, many parameters can be shared between them. To prevent wasteful repeats defines a common config file : mainconfig.ini.php.

A glimpse at mainconfig.ini.php (abstract):


locale = "en_US"
charset = "UTF-8"
timeZone = "Europe/Paris"
theme = default

[modules]
mymodule.enabled = on
jauth.enabled = on

[coordplugins]
;...

[responses]
;...

<entrypoint>/config.ini.php

Then, should lay in an entry point related config file, only specific parameters or overloaded parameters already defined in mainconfig.ini.php.

You can have a file into app/system/ but also into var/config if you have parameters for the environment.

Example: a classic request with index.php as entry point should define app/system/index/config.ini.php file. Storing under an index sub-directory serves only a better organization (As each entry point may have its config file, app/system would quickly become a mess).

A specific config should only define or redefine a small amount of properties:


[coordplugins]
autolocale = index/autolocale.ini.php

[responses]
html=myHtmlResponse

var/config/localconfig.ini.php

A file localconfig.ini.php may exist. It can be different in different environment (development, integration, production...). This file should be specific to the server where the application is installed. Instead of modifying the mainconfig.ini.php to set some parameters specific to the installation, put them in localconfig.ini.php. Parameters in this file override those set in mainconfig.ini.php.

Of course, this file should not be stored into your code repository.

liveconfig.ini.php

Since Jelix 1.6.18, a new configuration file liveconfig.ini.php allows to store parameters that are modified during the live of the application. It should not be stored into you source code repository.

How configuration file are readed

You have to know that an other configuration file defaultconfig.ini.php exists into the lib/jelix/core/ directory. It contains all possible parameters and some comments explaining their purpose.

So, to known the full configuration, Jelix reads these files in this order and merge them:

  1. lib/jelix/core/defaultconfig.ini.php,
  2. app/system/mainconfig.ini.php
  3. app/system/<entrypoint>/config.ini.php
  4. var/config/localconfig.ini.php
  5. var/config/<entrypoint>/config.ini.php
  6. var/config/liveconfig.ini.php

Values of a configuration file override values of the previous configuration file.

The resulting content is stored in a cache for each entry point.

Using environment variables

Ini files are readed by the parse_ini_file function, and so specific syntaxes are available to indicate values coming from outside the ini file.

  1. You can indicate PHP constants:

# somewhere in a file included by your index.php
define("SOMETHING", "hello world");

In one of your ini file:


foo = SOMETHING

Then foo will have the value "hello world".

  1. You can indicate environment variables:

# variables set in the environment of PHP-FPM, PHP-CLI, or Apache (with the PHP module)
MYAPP_MYSQL_LOGIN=admin
MYAPP_MYSQL_PASSWORD=Sup3Rp4ssw0rd!

Example, in your profiles.ini.php (see below), you have to use this syntax:


[jdb:default]
driver=mysqli
login= ${MYAPP_MYSQL_LOGIN}
password= ${MYAPP_MYSQL_PASSWORD}

The var/config/profiles.ini.php file

This file contains all connections parameters of some Jelix Components: SQL and NoSQL databases, SOAP web services, cache etc.

This is an ini file. Each section correspond to a profile. A profile is a set of parameters of a single connection. Sections names are composed of two names, separated by a ":":

  • first name is the name of the connection type, (often corresponding to the composant name)
  • second name is a name of your choice. However two names have a special meaning: "default" indicates the default profile to use if the profile name is not given to the component. And "common", described below.

The content of the section content connection parameters.

Here is an example for a jDb connection (jDb allow to access to a SQL database):


[jdb:default]
driver=mysqli
host=localhost
login= mylogin
password=mypassword

Remember that you can indicate environment variables. See above.

Profile Alias

You can define some profile alias, ie more than one name to a profile. This is useful for example when a module uses a specific profile name, but it correspond to an existing profile in your configuration.

Aliases are defined in a section whose name contains only the name of the connection type. An example with jDb, defining the alias "jacl2_profile' for the default profile:


[jdb]
jacl2_profile = default

[jdb:default]
driver=mysqli
host=localhost
login= mylogin
password=mypassword

An alias should not linked to an other alias.

Common parameters

It is possible to define parameters that are common to all profiles of the same type. This avoids repeating them in each profile. To do this, you must declare them in a special profile, __common__.

For example, if all connections to SQL databases (jDB) must be persistent and are all on the same server:


[jdb:__common__]
host=my.server.example.com
persistant=on

You can of course redefine these parameters in profiles.

Virtual profile

You can use a profile which is not declared in profiles.ini.php file. Then you can use a connection whose informations is known only during the execution.

A virtual profile must be created before using your component. Use createVirtualProfile method of the object jProfiles and pass it, the type name of connection, a name and an array of parameters.

Example


   $params = array(
       'driver'=>'mysqli',
       'host'=>'localhost',
       'database'=>'jelix',
       'user'=>'toto',
       'password'=>'blabla',
       'persistent'=>false,
       'force_encoding'=>true
   );
   jProfiles::createVirtualProfile('jdb', 'my_profil', $params);

   $cnx = jDb::getConnection('my_profil');
   // and play with your database

Of course, all parameters defined in a __common__ profile apply on virtual profiles.