/
configuration-files.gtw
320 lines (231 loc) · 10.5 KB
/
configuration-files.gtw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
~~LANG:FR@frman:configuration/fichiers-configuration~~
A Jelix application have several configuration files:
* A @@F@project.xml@@ file, describing general information about the application
* A @@F@module.xml@@ file in each module, describing general information about the module
* A @@F@mainconfig.ini.php@@ file for the global configuration
* A @@F@localconfig.ini.php@@ for configuration specific to environment where your
application is installed
* A @@F@config.ini.php@@ file for each entry points
* A @@F@liveconfig.ini.php@@ file to store parameters that are changed during
the live of the application
* A @@F@profiles.ini.php@@ for connections profiles (database configuration for example).
* A @@F@urls.xml@@ file that defines the mapping between URLS and controllers.
* A @@F@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 @@F@project.xml@@ and @@F@module.xml@@ files, configuration files are in @@F@app/system/@@
for default parameters (@@F@mainconfig.ini.php@@, @@F@config.ini.php@@, @@F@urls.xml@@...),
or @@F@var/config/@@ for parameters specific to the server environment (@@F@localconfig.ini.php@@,
@@F@profiles.ini.php@@...).
Note: before Jelix 1.7, all files were into @@F@var/config/@@).
This chapter presents these files. See [[configuration-details|the chapter on configuration details]] to know more.
===== The project.xml file =====
The file @@F@project.xml@@ contains some informations about the application. Here is an
example:
<code xml>
<?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>
</code>
===== The module.xml file =====
A @@F@module.xml@@ file must be present in each directory of modules. It
describes some general information, and dependencies with other modules.
<code xml>
<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>
</code>
===== 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 [[/components/urls|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 @@F@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 : @@F@mainconfig.ini.php@@.
A glimpse at @@F@mainconfig.ini.php@@ (abstract):
<code ini>
locale = "en_US"
charset = "UTF-8"
timeZone = "Europe/Paris"
theme = default
[modules]
mymodule.enabled = on
jauth.enabled = on
[coordplugins]
;...
[responses]
;...
</code>
==== @@<entrypoint>/config.ini.php@@ ====
Then, should lay in an entry point related config file, only specific parameters
or overloaded parameters already defined in @@F@mainconfig.ini.php@@.
You can have a file into @@F@app/system/@@ but also into @@F@var/config@@
if you have parameters for the environment.
Example: a classic request with index.php as entry point should define
@@F@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, @@F@app/system@@ would quickly become a mess).
A specific config should only define or redefine a small amount of properties:
<code ini>
[coordplugins]
autolocale = index/autolocale.ini.php
[responses]
html=myHtmlResponse
</code>
==== @@var/config/localconfig.ini.php@@ ====
A file @@F@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 @@F@mainconfig.ini.php@@ to set some parameters specific to the installation, put them in
@@F@localconfig.ini.php@@. Parameters in this file override those set in @@F@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 @@F@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 @@F@defaultconfig.ini.php@@ exists into the
@@F@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:
- @@F@lib/jelix/core/defaultconfig.ini.php@@,
- @@F@app/system/mainconfig.ini.php@@
- @@F@app/system/<entrypoint>/config.ini.php@@
- @@F@var/config/localconfig.ini.php@@
- @@F@var/config/<entrypoint>/config.ini.php@@
- @@F@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.
- You can indicate PHP constants:
<code php>
# somewhere in a file included by your index.php
define("SOMETHING", "hello world");
</code>
In one of your ini file:
<code ini>
foo = SOMETHING
</code>
Then foo will have the value @@"hello world"@@.
- You can indicate environment variables:
<code bash>
# variables set in the environment of PHP-FPM, PHP-CLI, or Apache (with the PHP module)
MYAPP_MYSQL_LOGIN=admin
MYAPP_MYSQL_PASSWORD=Sup3Rp4ssw0rd!
</code>
Example, in your profiles.ini.php (see below), you have to use this syntax:
<code ini>
[jdb:default]
driver=mysqli
login= ${MYAPP_MYSQL_LOGIN}
password= ${MYAPP_MYSQL_PASSWORD}
</code>
===== 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):
<code ini>
[jdb:default]
driver=mysqli
host=localhost
login= mylogin
password=mypassword
</code>
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:
<code ini>
[jdb]
jacl2_profile = default
[jdb:default]
driver=mysqli
host=localhost
login= mylogin
password=mypassword
</code>
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:
<code ini>
[jdb:__common__]
host=my.server.example.com
persistant=on
</code>
You can of course redefine these parameters in profiles.
===== Virtual profile =====
You can use a profile which is not declared in @@F@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
@@M@createVirtualProfile@@ method of the object @@C@jProfiles@@ and pass it, the
type name of connection, a name and an array of parameters.
Example
<code php>
$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
</code>
Of course, all parameters defined in a @@__common__@@ profile apply on virtual profiles.