db-backend.txt 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. I'm afraid I have no information on
  18. other systems at the present time.
  19. Configuring addressbooks in database
  20. ------------------------------------
  21. First you need to create a database and a table to store the data in.
  22. Create a database user with access to read and write in that table.
  23. For MySQL you would normally do something like:
  24. (from the command line)
  25. # mysqladmin create squirrelmail
  26. (from the mysql client)
  27. mysql> GRANT select,insert,update,delete ON squirrelmail.*
  28. TO squirreluser@localhost IDENTIFIED BY 'sqpassword';
  29. The table structure should be similar to this (for MySQL):
  30. CREATE TABLE address (
  31. owner varchar(128) DEFAULT '' NOT NULL,
  32. nickname varchar(16) DEFAULT '' NOT NULL,
  33. firstname varchar(128) DEFAULT '' NOT NULL,
  34. lastname varchar(128) DEFAULT '' NOT NULL,
  35. email varchar(128) DEFAULT '' NOT NULL,
  36. label varchar(255),
  37. PRIMARY KEY (owner,nickname),
  38. KEY firstname (firstname,lastname)
  39. );
  40. and similar to this for PostgreSQL:
  41. CREATE TABLE "address" (
  42. "owner" varchar(128) NOT NULL,
  43. "nickname" varchar(16) NOT NULL,
  44. "firstname" varchar(128) NOT NULL,
  45. "lastname" varchar(128) NOT NULL,
  46. "email" varchar(128) NOT NULL,
  47. "label" varchar(255) NOT NULL,
  48. CONSTRAINT "address_pkey" PRIMARY KEY ("nickname", "owner")
  49. );
  50. CREATE UNIQUE INDEX "address_firstname_key" ON "address"
  51. ("firstname", "lastname");
  52. Next, edit your configuration so that the address book DSN (Data Source
  53. Name) is specified, this can be done using either conf.pl or via the
  54. administration plugin. The DSN should look something like:
  55. mysql://squirreluser:sqpassword@localhost/squirrelmail or
  56. pgsql://squirreluser:sqpassword@localhost/squirrelmail
  57. From now on all users' personal addressbooks will be stored in a
  58. database.
  59. Configuring preferences in database
  60. -----------------------------------
  61. This is done in much the same way as it is for storing your address
  62. books in a database.
  63. The table structure should be similar to this (for MySQL):
  64. CREATE TABLE userprefs (
  65. user varchar(128) DEFAULT '' NOT NULL,
  66. prefkey varchar(64) DEFAULT '' NOT NULL,
  67. prefval BLOB DEFAULT '' NOT NULL,
  68. PRIMARY KEY (user,prefkey)
  69. );
  70. and for PostgreSQL:
  71. CREATE TABLE "userprefs" (
  72. "username" varchar(128) NOT NULL,
  73. "prefkey" varchar(64) NOT NULL,
  74. "prefval" text,
  75. CONSTRAINT "userprefs_pkey" PRIMARY KEY ("prefkey", "username")
  76. );
  77. Next, edit your configuration so that the preferences DSN (Data Source
  78. Name) is specified, this can be done using either conf.pl or via the
  79. administration plugin. The DSN should look something like:
  80. mysql://squirreluser:sqpassword@localhost/squirrelmail or
  81. pgsql://squirreluser:sqpassword@localhost/squirrelmail
  82. From now on all users' personal preferences will be stored in a
  83. database.
  84. Default preferences can be set by altering the $default array in
  85. db_prefs.php.