lemonldap-ng/doc/pages/documentation/current/sqlsessionbackend.html
Xavier Guimard ce59789747 Update doc
2019-06-28 16:53:45 +02:00

256 lines
12 KiB
HTML

<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8" />
<title>documentation:2.0:sqlsessionbackend</title>
<meta name="generator" content="DokuWiki"/>
<meta name="robots" content="noindex,nofollow"/>
<meta name="keywords" content="documentation,2.0,sqlsessionbackend"/>
<link rel="search" type="application/opensearchdescription+xml" href="lib/exe/opensearch.html" title="LemonLDAP::NG"/>
<link rel="start" href="sqlsessionbackend.html"/>
<link rel="contents" href="sqlsessionbackend.html" title="Sitemap"/>
<link rel="stylesheet" type="text/css" href="lib/exe/css.php.t.bootstrap3.css"/>
<!-- //if:usedebianlibs
<link rel="stylesheet" type="text/css" href="/javascript/bootstrap/css/bootstrap.min.css" />
//elsif:useexternallibs
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"></script>
//elsif:cssminified
<link rel="stylesheet" type="text/css" href="/static/bwr/bootstrap/dist/css/bootstrap.min.css" />
//else -->
<link rel="stylesheet" type="text/css" href="/static/bwr/bootstrap/dist/css/bootstrap.css" />
<!-- //endif -->
<script type="text/javascript">/*<![CDATA[*/var NS='documentation:2.0';var JSINFO = {"id":"documentation:2.0:sqlsessionbackend","namespace":"documentation:2.0"};
/*!]]>*/</script>
<script type="text/javascript" charset="utf-8" src="lib/exe/js.php.t.bootstrap3.js"></script>
<!-- //if:usedebianlibs
<script type="text/javascript" src="/javascript/jquery/jquery.min.js"></script>
//elsif:useexternallibs
<script type="text/javascript" src="http://code.jquery.com/jquery-2.2.0.min.js"></script>
//elsif:jsminified
<script type="text/javascript" src="/static/bwr/jquery/dist/jquery.min.js"></script>
//else -->
<script type="text/javascript" src="/static/bwr/jquery/dist/jquery.js"></script>
<!-- //endif -->
<!-- //if:usedebianlibs
<script type="text/javascript" src="/javascript/jquery-ui/jquery-ui.min.js"></script>
//elsif:useexternallibs
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.4/jquery-ui.min.js"></script>
//elsif:jsminified
<script type="text/javascript" src="/static/bwr/jquery-ui/jquery-ui.min.js"></script>
//else -->
<script type="text/javascript" src="/static/bwr/jquery-ui/jquery-ui.js"></script>
<!-- //endif -->
</head>
<body>
<div class="dokuwiki export container">
<!-- TOC START -->
<div id="dw__toc">
<h3 class="toggle">Table of Contents</h3>
<div>
<ul class="toc">
<li class="level1"><div class="li"><a href="#setup">Setup</a></div>
<ul class="toc">
<li class="level2"><div class="li"><a href="#prepare_the_database">Prepare the database</a></div>
<ul class="toc">
<li class="level3"><div class="li"><a href="#mysql">MySQL</a></div></li>
<li class="level3"><div class="li"><a href="#postgresql">PostgreSQL</a></div></li>
</ul>
</li>
<li class="level2"><div class="li"><a href="#manager">Manager</a></div>
<ul class="toc">
<li class="level3"><div class="li"><a href="#utf8_support">UTF8 support</a></div></li>
</ul>
</li>
</ul>
</li>
<li class="level1"><div class="li"><a href="#security">Security</a></div></li>
</ul>
</div>
</div>
<!-- TOC END -->
<h1 class="sectionedit1" id="sql_session_backend">SQL session backend</h1>
<div class="level1">
<p>
SQL session backend can be used with many SQL databases such as:
</p>
<ul>
<li class="level1"><div class="li"> <a href="https://metacpan.org/pod/Apache::Session::MySQL" class="urlextern" title="https://metacpan.org/pod/Apache::Session::MySQL" rel="nofollow">MariaDB / MySQL</a></div>
</li>
<li class="level1"><div class="li"> <a href="https://metacpan.org/pod/Apache::Session::Postgres" class="urlextern" title="https://metacpan.org/pod/Apache::Session::Postgres" rel="nofollow">PostgreSQL</a></div>
</li>
<li class="level1"><div class="li"> <a href="https://metacpan.org/pod/Apache::Session::Oracle" class="urlextern" title="https://metacpan.org/pod/Apache::Session::Oracle" rel="nofollow">Oracle</a></div>
</li>
<li class="level1"><div class="li"> <a href="https://metacpan.org/pod/Apache::Session::Informix" class="urlextern" title="https://metacpan.org/pod/Apache::Session::Informix" rel="nofollow">Informix</a></div>
</li>
<li class="level1"><div class="li"> <a href="https://metacpan.org/pod/Apache::Session::Sybase" class="urlextern" title="https://metacpan.org/pod/Apache::Session::Sybase" rel="nofollow">Sybase</a></div>
</li>
<li class="level1"><div class="li"> ....</div>
</li>
</ul>
</div>
<!-- EDIT1 SECTION "SQL session backend" [1-448] -->
<h2 class="sectionedit2" id="setup">Setup</h2>
<div class="level2">
</div>
<!-- EDIT2 SECTION "Setup" [449-467] -->
<h3 class="sectionedit3" id="prepare_the_database">Prepare the database</h3>
<div class="level3">
<p>
Your database must have a specific table to host sessions. Here are some examples for main databases servers.
</p>
<div class="noteimportant">If your database doesn&#039;t accept UTF-8 characters in &#039;text&#039; field, use &#039;blob&#039; instead of &#039;text&#039;.
</div>
</div>
<h4 id="mysql">MySQL</h4>
<div class="level4">
<p>
Create a database if necessary:
</p>
<pre class="code">mysqladmin create lemonldap-ng</pre>
<p>
Create sessions table:
</p>
<pre class="code file sql"><span class="kw1">CREATE</span> <span class="kw1">TABLE</span> sessions <span class="br0">&#40;</span>
id <span class="kw1">CHAR</span><span class="br0">&#40;</span><span class="nu0">32</span><span class="br0">&#41;</span> <span class="kw1">NOT</span> <span class="kw1">NULL</span> <span class="kw1">PRIMARY</span> <span class="kw1">KEY</span><span class="sy0">,</span>
a_session text
<span class="br0">&#41;</span>;</pre>
<div class="noteimportant">Change <code>char(32)</code> by <code>varchar(64)</code> if you use the now recommended SHA256 hash algorithm. See <a href="documentation/latest/sessions.html" class="wikilink1" title="documentation:latest:sessions">Sessions</a> for more details
</div><div class="notetip">You can change table name <code>sessions</code> to whatever you want, just adapt the parameter <code>TableName</code> in module options.
</div><div class="noteimportant">For a better UTF-8 support, use <a href="https://metacpan.org/pod/DBD::MariaDB" class="urlextern" title="https://metacpan.org/pod/DBD::MariaDB" rel="nofollow">DBD::MariaDB</a> with Apache::Session*::MySQL instead of DBD::mysql
</div>
</div>
<h4 id="postgresql">PostgreSQL</h4>
<div class="level4">
<p>
Create user and role:
</p>
<pre class="code">su - postgres
createuser lemonldap-ng -P</pre>
<pre class="code">Entrez le mot de passe pour le nouveau rôle : &lt;PASSWORD&gt;
Entrez-le de nouveau : &lt;PASSWORD&gt;
Le nouveau rôle est-il un super-utilisateur ? (o/n) n
Le nouveau rôle doit-il être autorisé à créer des bases de données ? (o/n) n
Le nouveau rôle doit-il être autorisé à créer de nouveaux rôles ? (o/n) n</pre>
<p>
Create database:
</p>
<pre class="code">createdb -O lemonldap-ng lemonldap-ng</pre>
<p>
Create table:
</p>
<pre class="code">psql -h 127.0.0.1 -U lemonldap-ng -W lemonldap-ng</pre>
<pre class="code">Mot de passe pour l&#039;utilisateur lemonldap-ng :
[...]
lemonldap-ng=&gt; create unlogged table sessions ( id char(32) not null primary key, a_session text );
lemonldap-ng=&gt; q</pre>
<div class="noteimportant">Change <code>char(32)</code> by <code>varchar(64)</code> if you use the now recommended SHA256 hash algorithm. See <a href="documentation/latest/sessions.html" class="wikilink1" title="documentation:latest:sessions">Sessions</a> for more details
</div>
</div>
<!-- EDIT3 SECTION "Prepare the database" [468-2380] -->
<h3 class="sectionedit4" id="manager">Manager</h3>
<div class="level3">
<p>
Go in the Manager and set the session module (for example <a href="https://metacpan.org/pod/Apache::Session::Postgres" class="urlextern" title="https://metacpan.org/pod/Apache::Session::Postgres" rel="nofollow">Apache::Session::Postgres</a> for PostgreSQL) in <code>General parameters</code> » <code>Sessions</code> » <code>Session storage</code> » <code>Apache::Session module</code> and add the following parameters (case sensitive):
</p>
<div class="table sectionedit5"><table class="inline table table-bordered table-striped">
<thead>
<tr class="row0 roweven">
<th class="col0 centeralign" colspan="3"> Required parameters </th>
</tr>
<tr class="row1 rowodd">
<th class="col0 centeralign"> Name </th><th class="col1 centeralign"> Comment </th><th class="col2 centeralign"> Example </th>
</tr>
</thead>
<tr class="row2 roweven">
<td class="col0 centeralign"> <strong>DataSource</strong> </td><td class="col1"> The <a href="https://metacpan.org/pod/DBI" class="urlextern" title="https://metacpan.org/pod/DBI" rel="nofollow">DBI</a> string </td><td class="col2"> dbi:Pg:dbname=sessions;host=10.2.3.1 </td>
</tr>
<tr class="row3 rowodd">
<td class="col0 centeralign"> <strong>UserName</strong> </td><td class="col1"> The database username </td><td class="col2"> lemonldap-ng </td>
</tr>
<tr class="row4 roweven">
<td class="col0 centeralign"> <strong>Password</strong> </td><td class="col1"> The database password </td><td class="col2"> mysuperpassword </td>
</tr>
<tr class="row5 rowodd">
<td class="col0 centeralign"> <strong>Commit</strong> </td><td class="col1"> Required for PostgreSQL </td><td class="col2"> 1 </td>
</tr>
<tr class="row6 roweven">
<td class="col0 centeralign"> <strong>TableName</strong> </td><td class="col1"> <em>(Optional)</em> Name of the table </td><td class="col2"> sessions </td>
</tr>
</table></div>
<!-- EDIT5 TABLE [2703-3107] -->
<p>
You must read the man page corresponding to your database (<a href="https://metacpan.org/pod/Apache::Session::MySQL" class="urlextern" title="https://metacpan.org/pod/Apache::Session::MySQL" rel="nofollow">Apache::Session::MySQL</a>, ...) to learn more about parameters. You must also install the database connector (<a href="https://metacpan.org/pod/DBD::Oracle" class="urlextern" title="https://metacpan.org/pod/DBD::Oracle" rel="nofollow">https://metacpan.org/pod/DBD::Oracle</a>, <a href="https://metacpan.org/pod/DBD::Pg" class="urlextern" title="https://metacpan.org/pod/DBD::Pg" rel="nofollow">DBD::Pg</a>,...)
</p>
<div class="noteimportant">For MySQL, you need to set additional parameters:<ul>
<li class="level1"><div class="li"> LockDataSource</div>
</li>
<li class="level1"><div class="li"> LockUserName</div>
</li>
<li class="level1"><div class="li"> LockPassword</div>
</li>
</ul>
</div><div class="notetip">For better performances, you can use specific <a href="browseablesessionbackend.html" class="wikilink1" title="documentation:2.0:browseablesessionbackend">browseable session backend</a>.
<p>
Learn more at <a href="performances.html#apachesession_performances" class="wikilink1" title="documentation:2.0:performances">how to increase Data Base performances</a>.
</p>
</div>
</div>
<h4 id="utf8_support">UTF8 support</h4>
<div class="level4">
<p>
If you may store some non-<abbr title="American Standard Code for Information Interchange">ASCII</abbr> characters, you must add the parameter corresponding to your database.
</p>
<div class="table sectionedit6"><table class="inline table table-bordered table-striped">
<thead>
<tr class="row0 roweven">
<th class="col0 centeralign"> Database </th><th class="col1 centeralign"> Parameter name </th><th class="col2 centeralign"> Value </th>
</tr>
</thead>
<tr class="row1 rowodd">
<td class="col0 centeralign"> MySQL </td><td class="col1 centeralign"> mysql_enable_utf8 </td><td class="col2 centeralign"> 1 </td>
</tr>
<tr class="row2 roweven">
<td class="col0 centeralign"> PostgreSQL </td><td class="col1 centeralign"> pg_enable_utf8 </td><td class="col2 centeralign"> 1 </td>
</tr>
<tr class="row3 rowodd">
<td class="col0 centeralign"> SQLite </td><td class="col1 centeralign"> sqlite_unicode </td><td class="col2 centeralign"> 1 </td>
</tr>
</table></div>
<!-- EDIT6 TABLE [3897-4060] -->
</div>
<!-- EDIT4 SECTION "Manager" [2381-4061] -->
<h2 class="sectionedit7" id="security">Security</h2>
<div class="level2">
<p>
Restrict network access to the database.
</p>
<p>
You can also use different user/password for your servers by overriding parameters <code>globalStorage</code> and <code>globalStorageOptions</code> in lemonldap-ng.ini file.
</p>
</div>
<!-- EDIT7 SECTION "Security" [4062-] --></div>
</body>
</html>