Debian Codegraph @

doc/sources/admin/sqlsessionbackend.rst

raw
1 SQL session backend
2 ===================
3
4 SQL session backend can be used with many SQL databases such as:
5
6 - `MariaDB / MySQL <https://metacpan.org/pod/Apache::Session::MySQL>`__
7 - `PostgreSQL <https://metacpan.org/pod/Apache::Session::Postgres>`__
8 - `Oracle <https://metacpan.org/pod/Apache::Session::Oracle>`__
9 - `Informix <https://metacpan.org/pod/Apache::Session::Informix>`__
10 - `Sybase <https://metacpan.org/pod/Apache::Session::Sybase>`__
11 - ...
12
13 Setup
14 -----
15
16 .. _sqlsessionbackend-prepare-the-database:
17
18 Prepare the database
19 ~~~~~~~~~~~~~~~~~~~~
20
21 Your database must have a specific table to host sessions. Here are some
22 examples for main databases servers.
23
24
25 .. attention::
26
27 If your database doesn't accept UTF-8 characters in
28 'text' field, use 'blob' instead of 'text'.
29
30 MySQL
31 ^^^^^
32
33 Create a database if necessary:
34
35 ::
36
37 mysqladmin create lemonldap-ng
38
39 Create sessions table:
40
41 .. code-block:: sql
42
43 CREATE TABLE sessions (
44 id char(32) not null primary key,
45 a_session text
46 );
47
48
49 .. attention::
50
51 Change ``char(32)`` by ``varchar(64)`` if you use the
52 now recommended SHA256 hash algorithm. See
53 :doc:`Sessions<sessions>` for more details
54
55
56 .. tip::
57
58 You can change table name ``sessions`` to whatever you want,
59 just adapt the parameter ``TableName`` in module options.
60
61
62 .. attention::
63
64 For a better UTF-8 support, use
65 `DBD::MariaDB <https://metacpan.org/pod/DBD::MariaDB>`__ with
66 Apache::Session*::MySQL instead of DBD::mysql
67
68 PostgreSQL
69 ^^^^^^^^^^
70
71 Create user and role:
72
73 ::
74
75 su - postgres
76 createuser lemonldap-ng -P
77
78 ::
79
80 Entrez le mot de passe pour le nouveau rôle : <PASSWORD>
81 Entrez-le de nouveau : <PASSWORD>
82 Le nouveau rôle est-il un super-utilisateur ? (o/n) n
83 Le nouveau rôle doit-il être autorisé à créer des bases de données ? (o/n) n
84 Le nouveau rôle doit-il être autorisé à créer de nouveaux rôles ? (o/n) n
85
86 Create database:
87
88 ::
89
90 createdb -O lemonldap-ng lemonldap-ng
91
92 Create table:
93
94 ::
95
96 psql -h 127.0.0.1 -U lemonldap-ng -W lemonldap-ng
97
98 ::
99
100 Mot de passe pour l'utilisateur lemonldap-ng :
101 [...]
102 lemonldap-ng=> create unlogged table sessions ( id char(32) not null primary key, a_session text );
103 lemonldap-ng=> q
104
105
106 .. attention::
107
108 Change ``char(32)`` by ``varchar(64)`` if you use the
109 now recommended SHA256 hash algorithm. See
110 :doc:`Sessions<sessions>` for more details
111
112 Manager
113 ~~~~~~~
114
115 Go in the Manager and set the session module (for example
116 `Apache::Session::Postgres <https://metacpan.org/pod/Apache::Session::Postgres>`__
117 for PostgreSQL) in ``General parameters`` » ``Sessions`` »
118 ``Session storage`` » ``Apache::Session module`` and add the following
119 parameters (case sensitive):
120
121 =================== ================================================= ====================================
122 Required parameters
123 ----------------------------------------------------------------------------------------------------------
124 Name Comment Example
125 =================== ================================================= ====================================
126 **DataSource** The `DBI <https://metacpan.org/pod/DBI>`__ string dbi:Pg:dbname=sessions;host=10.2.3.1
127 **UserName** The database username lemonldap-ng
128 **Password** The database password mysuperpassword
129 **Commit** Required for PostgreSQL 1
130 **TableName** *(Optional)* Name of the table sessions
131 =================== ================================================= ====================================
132
133 You must read the man page corresponding to your database
134 (`Apache::Session::MySQL <https://metacpan.org/pod/Apache::Session::MySQL>`__,
135 ...) to learn more about parameters. You must also install the database
136 connector (https://metacpan.org/pod/DBD::Oracle,
137 `DBD::Pg <https://metacpan.org/pod/DBD::Pg>`__,...)
138
139
140 .. attention::
141
142 For MySQL, you need to set additional parameters:
143
144 - LockDataSource
145 - LockUserName
146 - LockPassword
147
148
149
150
151 .. tip::
152
153 For better performances, you can use specific
154 :doc:`browseable session backend<browseablesessionbackend>`.
155
156 Learn more at
157 :ref:`how to increase Data Base performances<performances-apachesession-performances>`.
158
159
160 UTF8 support
161 ^^^^^^^^^^^^
162
163 If you may store some non-ASCII characters, you must add the parameter
164 corresponding to your database.
165
166 ========== ================= =====
167 Database Parameter name Value
168 ========== ================= =====
169 MySQL mysql_enable_utf8 1
170 PostgreSQL pg_enable_utf8 1
171 SQLite sqlite_unicode 1
172 ========== ================= =====
173
174 Security
175 --------
176
177 Restrict network access to the database.
178
179 You can also use different user/password for your servers by overriding
180 parameters ``globalStorage`` and ``globalStorageOptions`` in
181 lemonldap-ng.ini file.