Chapter: Configuration files
« Core workflow | ^ Fundamental | Developing a module » |
− Table of content
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).
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.
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 on the application. Some
of these are important because they are used by the installer. 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>
<dependencies>
<jelix minversion="1.6.0" maxversion="1.6.*" />
</dependencies>
<directories>
<config>var/config</config>
<log>var/log</log>
<var>var</var>
<www>www</www>
<temp>../temp/testapp</temp>
</directories>
<entrypoints>
<entry file="index.php" config="index/config.ini.php" />
<entry file="soap.php" config="soap/config.ini.php" type="soap"/>
</entrypoints>
</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.6.*" />
<module name="testurls" minversion="1.0.2" maxversion="1.1b1" />
<module name="jauthdb" />
<module name="jacl2db" />
<module name="jacldb" />
</dependencies>
</module>
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.
Configuration files are stored in var/config
.
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
(called defaultconfig.ini.php
as of Jelix 1.5). Jelix automatically read its entries in addition to each config file
related to an entry point. No need to tell jelix about it in an entry point.
localconfig.ini.php ¶
Since Jelix 1.6, an additionnal 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.
<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
.
A glimpse at mainconfig.ini.php
(abstract):
locale = "fr_FR"
charset = "ISO-8859-1"
timeZone = "Europe/Paris"
theme = default
pluginsPath = lib:jelix-plugins/,app:plugins/
modulesPath = lib:jelix-modules/,app:modules/
[modules]
mymodule=2
jauth=2
[coordplugins]
;nom = nom_fichier_ini
[responses]
...
Example: a classic request with index.php as entry point should define
var/config/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, var/config
would quickly become a mess).
A specific config should only define or redefine a small amount of properties:
startModule = "testapp"
startAction = "main:index"
[coordplugins]
autolocale = index/autolocale.ini.php
[responses]
html=myHtmlResponse
take xmlrpc.php entry point, its config file could be :
startModule = "testapp"
startAction = "xmlrpc:index"
And so on for others entry points.
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 it is 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.
So, to known the full configuration, Jelix reads these files in this order and merge them:
lib/jelix/core/defaultconfig.ini.php
,mainconfig.ini.php
localconfig.ini.php
F<entrypoint>/config.ini.php
liveconfig.ini.php
Values of a configuration file override values of the previous configuration file.
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.
- 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"
.
- 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 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.