db-backend.txt 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. $Id$
  2. Storing private addressbooks and preferences in a database
  3. ==========================================================
  4. On sites with many users you might want to store your user data in a
  5. database instead of in files. This document describes how to configure
  6. SquirrelMail to do this.
  7. Methods for storing both personal addressbooks and user preferences in
  8. a database is included as a part of the distribution.
  9. Configuring PEAR DB
  10. -------------------
  11. For this to work you must have the PEAR classes installed, these are
  12. part of PHP. Once these are installed you must have sure the directory
  13. containg them is a part of your PHP include path. See the PHP
  14. documentation for information on how to do that.
  15. Under Mandrake Linux the PEAR classes are installed as part of the
  16. php-devel package and under FreeBSD they are installed as part of
  17. the mod_php4 or php4 port/package. In Debian, you can install the
  18. php4-pear package. I'm afraid I have no information on
  19. other systems at the present time.
  20. Configuring addressbooks in database
  21. ------------------------------------
  22. First you need to create a database and a table to store the data in.
  23. Create a database user with access to read and write in that table.
  24. For MySQL you would normally do something like:
  25. (from the command line)
  26. # mysqladmin create squirrelmail
  27. (from the mysql client)
  28. mysql> GRANT select,insert,update,delete ON squirrelmail.*
  29. TO squirreluser@localhost IDENTIFIED BY 'sqpassword';
  30. The table structure should be similar to this (for MySQL):
  31. CREATE TABLE address (
  32. owner varchar(128) DEFAULT '' NOT NULL,
  33. nickname varchar(16) DEFAULT '' NOT NULL,
  34. firstname varchar(128) DEFAULT '' NOT NULL,
  35. lastname varchar(128) DEFAULT '' NOT NULL,
  36. email varchar(128) DEFAULT '' NOT NULL,
  37. label varchar(255),
  38. PRIMARY KEY (owner,nickname),
  39. KEY firstname (firstname,lastname)
  40. );
  41. and similar to this for PostgreSQL:
  42. CREATE TABLE "address" (
  43. "owner" varchar(128) NOT NULL,
  44. "nickname" varchar(16) NOT NULL,
  45. "firstname" varchar(128) NOT NULL,
  46. "lastname" varchar(128) NOT NULL,
  47. "email" varchar(128) NOT NULL,
  48. "label" varchar(255) NOT NULL,
  49. CONSTRAINT "address_pkey" PRIMARY KEY ("nickname", "owner")
  50. );
  51. CREATE UNIQUE INDEX "address_firstname_key" ON "address"
  52. ("firstname", "lastname");
  53. Next, edit your configuration so that the address book DSN (Data Source
  54. Name) is specified, this can be done using either conf.pl or via the
  55. administration plugin. The DSN should look something like:
  56. mysql://squirreluser:sqpassword@localhost/squirrelmail or
  57. pgsql://squirreluser:sqpassword@localhost/squirrelmail
  58. From now on all users' personal addressbooks will be stored in a
  59. database.
  60. Global address book uses same table format as the one used for personal
  61. address book. You can even use same table, if you don't have user named
  62. 'global'.
  63. Configuring preferences in database
  64. -----------------------------------
  65. This is done in much the same way as it is for storing your address
  66. books in a database.
  67. The table structure should be similar to this (for MySQL):
  68. CREATE TABLE userprefs (
  69. user varchar(128) DEFAULT '' NOT NULL,
  70. prefkey varchar(64) DEFAULT '' NOT NULL,
  71. prefval BLOB DEFAULT '' NOT NULL,
  72. PRIMARY KEY (user,prefkey)
  73. );
  74. and for PostgreSQL:
  75. CREATE TABLE "userprefs" (
  76. "username" varchar(128) NOT NULL,
  77. "prefkey" varchar(64) NOT NULL,
  78. "prefval" text,
  79. CONSTRAINT "userprefs_pkey" PRIMARY KEY ("prefkey", "username")
  80. );
  81. Next, edit your configuration so that the preferences DSN (Data Source
  82. Name) is specified, this can be done using either conf.pl or via the
  83. administration plugin. The DSN should look something like:
  84. mysql://squirreluser:sqpassword@localhost/squirrelmail or
  85. pgsql://squirreluser:sqpassword@localhost/squirrelmail
  86. Note that when using the above PostgreSQL schema, you also need to change
  87. the prefs_user_field variable in config.php from the default 'user' to
  88. 'username'.
  89. From now on all users' personal preferences will be stored in a
  90. database.
  91. Default preferences can be set by altering the $default array in
  92. db_prefs.php.
  93. Troubleshooting
  94. ---------------
  95. 1. Oversized field values. Preferences are not/can't be saved
  96. Database fields have size limits. Preference table example sets 128
  97. character limit to owner field, 64 character limit to preference key
  98. field and 64KB (database BLOB field size) limit to value field.
  99. If interface tries to insert data without checking field limits, it
  100. can cause data loss or database errors. Table information functions
  101. provided by Pear DB libraries are not accurate and some database
  102. backends don't support them. Since 1.5.1 SquirrelMail provides
  103. configuration options that set allowed field sizes.
  104. If you see oversized field errors in your error logs - check your
  105. database structure. Issue can be solved by increasing database field
  106. sizes.
  107. If you want to get more debugging information - check setKey() function
  108. in dbPrefs class. Class is stored in functions/db_prefs.php