Heberger son mail comme les pros .. ou presque ;)

Pré-requis : un serveur linux, mysql installé, un certificat ssl

Installation des logiciels

root@srv1:~# aptitude install postfix postfix-mysql courier-authdaemon courier-authlib-mysql courier-imap-ssl courier-pop-ssl
The following NEW packages will be installed:
  courier-authdaemon courier-authlib{a} courier-authlib-mysql courier-authlib-userdb{a} courier-base{a} courier-imap{a}
  courier-imap-ssl courier-pop{a} courier-pop-ssl courier-ssl{a} expect{a} libfam0{a} libltdl7{a} postfix postfix-mysql tcl8.5{a}
0 packages upgraded, 16 newly installed, 0 to remove and 0 not upgraded.
Need to get 4,825 kB of archives. After unpacking 12.7 MB will be used.
Do you want to continue? [Y/n/?] y
Get:1 http://debian.mirrors.ovh.net/debian/ squeeze/main libltdl7 amd64 2.2.6b-2 [296 kB]
Get:2 http://debian.mirrors.ovh.net/debian/ squeeze/main tcl8.5 amd64 8.5.8-2 [1,599 kB]
Get:3 http://debian.mirrors.ovh.net/debian/ squeeze/main expect amd64 5.44.1.15-4 [250 kB]
Get:4 http://debian.mirrors.ovh.net/debian/ squeeze/main courier-authlib amd64 0.63.0-3 [83.2 kB]
Get:5 http://debian.mirrors.ovh.net/debian/ squeeze/main courier-authdaemon amd64 0.63.0-3 [8,250 B]
Get:6 http://debian.mirrors.ovh.net/debian/ squeeze/main courier-authlib-mysql amd64 0.63.0-3 [21.5 kB]
Get:7 http://debian.mirrors.ovh.net/debian/ squeeze/main courier-authlib-userdb amd64 0.63.0-3 [36.7 kB]
Get:8 http://debian.mirrors.ovh.net/debian/ squeeze/main libfam0 amd64 2.7.0-17 [28.8 kB]
Get:9 http://debian.mirrors.ovh.net/debian/ squeeze/main courier-base amd64 0.65.0-3 [245 kB]
Get:10 http://debian.mirrors.ovh.net/debian/ squeeze/main postfix amd64 2.7.1-1+squeeze1 [1,402 kB]
Get:11 http://debian.mirrors.ovh.net/debian/ squeeze/main courier-pop amd64 0.65.0-3 [61.3 kB]
Get:12 http://debian.mirrors.ovh.net/debian/ squeeze/main courier-ssl amd64 0.65.0-3 [65.8 kB]
Get:13 http://debian.mirrors.ovh.net/debian/ squeeze/main courier-pop-ssl amd64 0.65.0-3 [30.4 kB]
Get:14 http://debian.mirrors.ovh.net/debian/ squeeze/main courier-imap amd64 4.8.0-3 [622 kB]
Get:15 http://debian.mirrors.ovh.net/debian/ squeeze/main courier-imap-ssl amd64 4.8.0-3 [30.4 kB]
Get:16 http://debian.mirrors.ovh.net/debian/ squeeze/main postfix-mysql amd64 2.7.1-1+squeeze1 [44.4 kB]
Fetched 4,825 kB in 0s (7,997 kB/s)
Preconfiguring packages ...
Selecting previously deselected package libltdl7.
(Reading database ... 24727 files and directories currently installed.)
Unpacking libltdl7 (from .../libltdl7_2.2.6b-2_amd64.deb) ...
Selecting previously deselected package tcl8.5.
Unpacking tcl8.5 (from .../tcl8.5_8.5.8-2_amd64.deb) ...
Selecting previously deselected package expect.
Unpacking expect (from .../expect_5.44.1.15-4_amd64.deb) ...
Selecting previously deselected package courier-authlib.
Unpacking courier-authlib (from .../courier-authlib_0.63.0-3_amd64.deb) ...
Selecting previously deselected package courier-authdaemon.
Unpacking courier-authdaemon (from .../courier-authdaemon_0.63.0-3_amd64.deb) ...
Selecting previously deselected package courier-authlib-mysql.
Unpacking courier-authlib-mysql (from .../courier-authlib-mysql_0.63.0-3_amd64.deb) ...
Selecting previously deselected package courier-authlib-userdb.
Unpacking courier-authlib-userdb (from .../courier-authlib-userdb_0.63.0-3_amd64.deb) ...
Selecting previously deselected package libfam0.
Unpacking libfam0 (from .../libfam0_2.7.0-17_amd64.deb) ...
Selecting previously deselected package courier-base.
Unpacking courier-base (from .../courier-base_0.65.0-3_amd64.deb) ...
Selecting previously deselected package postfix.
Unpacking postfix (from .../postfix_2.7.1-1+squeeze1_amd64.deb) ...
Selecting previously deselected package courier-pop.
Unpacking courier-pop (from .../courier-pop_0.65.0-3_amd64.deb) ...
Selecting previously deselected package courier-ssl.
Unpacking courier-ssl (from .../courier-ssl_0.65.0-3_amd64.deb) ...
Selecting previously deselected package courier-pop-ssl.
Unpacking courier-pop-ssl (from .../courier-pop-ssl_0.65.0-3_amd64.deb) ...
Selecting previously deselected package courier-imap.
Unpacking courier-imap (from .../courier-imap_4.8.0-3_amd64.deb) ...
Selecting previously deselected package courier-imap-ssl.
Unpacking courier-imap-ssl (from .../courier-imap-ssl_4.8.0-3_amd64.deb) ...
Selecting previously deselected package postfix-mysql.
Unpacking postfix-mysql (from .../postfix-mysql_2.7.1-1+squeeze1_amd64.deb) ...
Processing triggers for man-db ...
Setting up libltdl7 (2.2.6b-2) ...
Setting up tcl8.5 (8.5.8-2) ...
update-alternatives: using /usr/bin/tclsh8.5 to provide /usr/bin/tclsh (tclsh) in auto mode.
Setting up expect (5.44.1.15-4) ...
Setting up courier-authlib (0.63.0-3) ...
Setting up courier-authdaemon (0.63.0-3) ...
Starting Courier authentication services: authdaemond.
Setting up courier-authlib-mysql (0.63.0-3) ...
Setting up courier-authlib-userdb (0.63.0-3) ...
Setting up libfam0 (2.7.0-17) ...
Setting up courier-base (0.65.0-3) ...
update-alternatives: using /usr/bin/deliverquota.courier to provide /usr/bin/deliverquota (deliverquota) in auto mode.
update-alternatives: using /usr/share/man/man5/maildir.courier.5.gz to provide /usr/share/man/man5/maildir.5.gz (maildir.5.gz) in auto mode.
update-alternatives: using /usr/bin/maildirmake.courier to provide /usr/bin/maildirmake (maildirmake) in auto mode.
update-alternatives: using /usr/share/man/man7/maildirquota.courier.7.gz to provide /usr/share/man/man7/maildirquota.7.gz (maildirquota.7.gz) in auto mode.
update-alternatives: using /usr/bin/makedat.courier to provide /usr/bin/makedat (makedat) in auto mode.
Setting up postfix (2.7.1-1+squeeze1) ...
Adding group `postfix' (GID 110) ...
Done.
Adding system user `postfix' (UID 106) ...
Adding new user `postfix' (UID 106) with group `postfix' ...
Not creating home directory `/var/spool/postfix'.
Creating /etc/postfix/dynamicmaps.cf
Adding tcp map entry to /etc/postfix/dynamicmaps.cf
Adding group `postdrop' (GID 111) ...
Done.
setting myhostname: srv1.faistonweb.com
setting alias maps
setting alias database
changing /etc/mailname to srv1.faistonweb.com
setting myorigin
setting destinations: srv1.faistonweb.com, localhost.faistonweb.com, , localhost
setting relayhost:
setting mynetworks: 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
setting mailbox_size_limit: 0
setting recipient_delimiter: +
setting inet_interfaces: all
WARNING: /etc/aliases exists, but does not have a root alias.
Postfix is now set up with a default configuration.  If you need to make
changes, edit
/etc/postfix/main.cf (and others) as needed.  To view Postfix configuration
values, see postconf(1).
After modifying main.cf, be sure to run '/etc/init.d/postfix reload'.
Running newaliases
Stopping Postfix Mail Transport Agent: postfix.
Starting Postfix Mail Transport Agent: postfix.
Setting up courier-pop (0.65.0-3) ...
Starting Courier POP3 server: pop3d.
Setting up courier-ssl (0.65.0-3) ...
Setting up courier-pop-ssl (0.65.0-3) ...
cp: not writing through dangling symlink `/usr/lib/courier/pop3d.pem'
chmod: cannot operate on dangling symlink `/usr/lib/courier/pop3d.pem'
chown: cannot dereference `/usr/lib/courier/pop3d.pem': No such file or directory
Generating a 1024 bit RSA private key
.............++++++
......++++++
writing new private key to '/usr/lib/courier/pop3d.pem'
-----
1024 semi-random bytes loaded
Generating DH parameters, 512 bit long safe prime, generator 2
This is going to take a long time
....................................................+.............+..................................+.............................+.........
...............................................+......................+..+............++*++*++*++*++*++*
subject= /C=US/ST=NY/L=New York/O=Courier Mail Server/OU=Automatically-generated POP3 SSL key/CN=localhost/emailAddress=postmaster@example.com
notBefore=Nov 19 17:33:34 2012 GMT
notAfter=Nov 19 17:33:34 2013 GMT
SHA1 Fingerprint=20:7F:4D:76:12:CA:43:47:AB:FB:CD:EA:64:B9:0D:1A:F0:FB:4D:EB
Starting Courier POP3-SSL server: pop3d-ssl.
Setting up courier-imap (4.8.0-3) ...
Starting Courier IMAP server: imapd.
Setting up courier-imap-ssl (4.8.0-3) ...
cp: not writing through dangling symlink `/usr/lib/courier/imapd.pem'
chmod: cannot operate on dangling symlink `/usr/lib/courier/imapd.pem'
chown: cannot dereference `/usr/lib/courier/imapd.pem': No such file or directory
Generating a 1024 bit RSA private key
.........................++++++
.............................................++++++
writing new private key to '/usr/lib/courier/imapd.pem'
-----
1024 semi-random bytes loaded
Generating DH parameters, 512 bit long safe prime, generator 2
This is going to take a long time
.......................++*++*++*++*++*++*
subject= /C=US/ST=NY/L=New York/O=Courier Mail Server/OU=Automatically-generated IMAP SSL key/CN=localhost/emailAddress=postmaster@example.com
notBefore=Nov 19 17:33:36 2012 GMT
notAfter=Nov 19 17:33:36 2013 GMT
SHA1 Fingerprint=65:4C:B9:C6:96:35:26:2E:D4:12:D0:8A:F4:BA:8C:0C:19:60:59:BB
Starting Courier IMAP-SSL server: imapd-ssl.
Setting up postfix-mysql (2.7.1-1+squeeze1) ...
Adding mysql map entry to /etc/postfix/dynamicmaps.cf
root@srv1:~#

Création de la structure de données
Créé une base de donnée, par exemple, postfix, noté le login/pass, ils seront utilisées plus tard. Créé la structure de données dans mysql qui va bien ( ne pas oublier “Use postfix;” au depart pour selectionner la base ).


DROP TABLE IF EXISTS `admin`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `admin` (
  `username` varchar(255) NOT NULL DEFAULT '',
  `password` varchar(255) NOT NULL DEFAULT '',
  `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `active` tinyint(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`username`),
  KEY `username` (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Postfix Admin - Virtual Admins';
/*!40101 SET character_set_client = @saved_cs_client */;

DROP TABLE IF EXISTS `alias`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `alias` (
  `address` varchar(255) NOT NULL DEFAULT '',
  `goto` text NOT NULL,
  `domain` varchar(255) NOT NULL DEFAULT '',
  `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `active` tinyint(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`address`),
  KEY `address` (`address`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Postfix Admin - Virtual Aliases';
/*!40101 SET character_set_client = @saved_cs_client */;

 DROP TABLE IF EXISTS `alias_domain`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `alias_domain` (
  `alias_domain` varchar(255) NOT NULL DEFAULT '',
  `target_domain` varchar(255) NOT NULL DEFAULT '',
  `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `active` tinyint(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`alias_domain`),
  KEY `active` (`active`),
  KEY `target_domain` (`target_domain`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Domain Aliases';
/*!40101 SET character_set_client = @saved_cs_client */;

DROP TABLE IF EXISTS `domain`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `domain` (
  `domain` varchar(255) NOT NULL DEFAULT '',
  `description` varchar(255) NOT NULL DEFAULT '',
  `aliases` int(10) NOT NULL DEFAULT '0',
  `mailboxes` int(10) NOT NULL DEFAULT '0',
  `maxquota` int(10) NOT NULL DEFAULT '0',
  `transport` varchar(255) DEFAULT NULL,
  `backupmx` tinyint(1) NOT NULL DEFAULT '0',
  `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `active` tinyint(1) NOT NULL DEFAULT '1',
  `quota` int(10) DEFAULT '0',
  PRIMARY KEY (`domain`),
  KEY `domain` (`domain`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Postfix Admin - Virtual Domains';
/*!40101 SET character_set_client = @saved_cs_client */;

DROP TABLE IF EXISTS `domain_admins`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `domain_admins` (
  `username` varchar(255) NOT NULL DEFAULT '',
  `domain` varchar(255) NOT NULL DEFAULT '',
  `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `active` tinyint(1) NOT NULL DEFAULT '1',
  KEY `username` (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Postfix Admin - Domain Admins';
/*!40101 SET character_set_client = @saved_cs_client */;

DROP TABLE IF EXISTS `imp_sentmail`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `imp_sentmail` (
  `sentmail_id` bigint(20) NOT NULL,
  `sentmail_who` varchar(255) NOT NULL,
  `sentmail_ts` bigint(20) NOT NULL,
  `sentmail_messageid` varchar(255) NOT NULL,
  `sentmail_action` varchar(32) NOT NULL,
  `sentmail_recipient` varchar(255) NOT NULL,
  `sentmail_success` int(11) NOT NULL,
  PRIMARY KEY (`sentmail_id`),
  KEY `sentmail_ts_idx` (`sentmail_ts`),
  KEY `sentmail_who_idx` (`sentmail_who`),
  KEY `sentmail_success_idx` (`sentmail_success`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

DROP TABLE IF EXISTS `mailbox`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `mailbox` (
  `username` varchar(255) NOT NULL DEFAULT '',
  `password` varchar(255) NOT NULL DEFAULT '',
  `name` varchar(255) NOT NULL DEFAULT '',
  `maildir` varchar(255) NOT NULL DEFAULT '',
  `quota` int(10) NOT NULL DEFAULT '0',
  `domain` varchar(255) NOT NULL DEFAULT '',
  `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `active` tinyint(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`username`),
  KEY `username` (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Postfix Admin - Virtual Mailboxes';
/*!40101 SET character_set_client = @saved_cs_client */;

DROP TABLE IF EXISTS `vacation`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `vacation` (
  `email` varchar(255) NOT NULL DEFAULT '',
  `subject` varchar(255) NOT NULL DEFAULT '',
  `body` text NOT NULL,
  `cache` text NOT NULL,
  `domain` varchar(255) NOT NULL DEFAULT '',
  `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `active` tinyint(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`email`),
  KEY `email` (`email`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Postfix Admin - Virtual Vacation';
/*!40101 SET character_set_client = @saved_cs_client */;


insert into admin VALUES ( "admin@domain.com", PASSWORD( "MOT_DE_PASSE"), NOW(), NOW(), 1);

Création des fichiers de mapping sql
Créé les fichiers permettant à postfix d'aller chercher dans mysql les mailbox/domains/alias que le serveur doit géré. Remplacer les valeurs pour user, password, dbname par celles qui vont bien :
/etc/postfix/mysql_relay_domains_maps.cf


user = postfix
password = PASSWORD
hosts = localhost
dbname = postfix
query = SELECT domain FROM domain WHERE domain='%s' and backupmx = '1'

/etc/postfix/mysql_sasl_maps.cf


user = postfix
password = PASSWORD
hosts = localhost
dbname = postfix
query = SELECT name FROM mailbox WHERE username='%s' AND password='%s'

/etc/postfix/mysql_virtual_alias_maps.cf


user = postfix
password = PASSWORD
hosts = localhost
dbname = postfix
query = SELECT goto FROM alias WHERE address='%s' AND active = '1'

/etc/postfix/mysql_virtual_domains_maps.cf


user = postfix
password = PASSWORD
hosts = localhost
dbname = postfix
query = SELECT domain FROM domain WHERE domain='%s' and backupmx = '0' and active = '1'

/etc/postfix/mysql_virtual_mailbox_limit_maps.cf


user = postfix
password = PASSWORD
hosts = localhost
dbname = postfix
query = SELECT quota FROM mailbox WHERE username='%s'

/etc/postfix/mysql_virtual_mailbox_maps.cf


user = postfix
password = PASSWORD
hosts = localhost
dbname = postfix
query = SELECT maildir FROM mailbox WHERE username='%s'

Configuration de postfix
On peut maintenant passer à la configuration de postfix à proprement parler. Dans le fichier suivant, re-utiliser le certificat pour smtpd_tls_cert_file et smtpd_tls_key_file, définir votre nom de machine complet pour myhostname.
/etc/posfix/main.cf


smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no
# appending .domain is the MUA's job.
append_dot_mydomain = no
readme_directory = no
# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certificates/domaine.pem
smtpd_tls_key_file=/etc/ssl/private/domaine.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
myhostname = MACHINE_HOSTNAME
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
message_size_limit = 131457280
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
default_destination_concurrency_limit=10
# smtps
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_auth_enable          = yes
smtpd_sasl_security_options     = noanonymous
broken_sasl_auth_clients        = yes
smtpd_sasl_path                 = smtpd
smtpd_sasl_authenticated_header = yes
smtp_sasl_password_maps = proxy:mysql:/etc/postfix/mysql_sasl_maps.cf
smtpd_sender_restrictions       = permit_sasl_authenticated, permit_mynetworks
smtpd_recipient_restrictions    = permit_mynetworks,permit_sasl_authenticated,reject_non_fqdn_sender,reject_non_fqdn_recipient,reject_unauth_destination,reject_unauth_pipelining,reject_invalid_hostname
# MySQL Configuration
virtual_alias_maps = proxy:mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_gid_maps = static:111
virtual_mailbox_base = /var/mail
virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_minimum_uid = 5001
virtual_transport = maildrop
virtual_uid_maps = static:5001
create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_mailbox_limit_maps = proxy:mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps
  $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains
  $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps
  $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks
  $virtual_mailbox_limit_maps
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = Sorry, this user has overdrawn their diskspace quota. Please try again later.
virtual_overquota_bounce = yes
virtual_create_maildirsize     = yes
virtual_mailbox_extended       = yes
virtual_mailbox_limit_override = yes
maildrop_destination_recipient_limit = 1

Vous avez maintenant un MTA fonctionnel. Reste à faire sorte de pouvoir reccupéré le courrier depuis un client.

Configuration de courrier-imap
Dans /etc/courrier/authdaemonrc, il vous faut :


authmodulelist="authmysql"
authmodulelistorig="authmysql"

Ensuite editer /etc/courier/authmysqlrc pour définir les champs MYSQL_SERVER, MYSQL_USERNAME, MYSQL_PASSWORD

Pour la gestion des domaines, comptes et alias, 2 solutions : faire les inserts directement en base ou bien installer postfixadmin.

Exemples de créations manuelles

Un exemple rapide de création de domaine directement en base de donnée :


use postfix;
insert into domain VALUES( "mondomaine.com", "Mon super domaine a moi", 0, 0, 0, "maildrop", 0, NOW(), NOW(), 1, NULL);

Création d'une boite mail :


use postfix;
insert into mailbox VALUES( "compte@mondomaine.com", PASSWORD( "MON_PASS_SECRET"), "Mon utilisateur", "mondomaine.com/compte@mondomaine.com", 0, "mondomaine.com", NOW(), NOW(), 1);

Creation d'un alias :


use postfix;
insert into alias VALUES( "monalias@mondomaine.com", "compte@mondomaine.com", "mondomaine.com", NOW(), NOW(), 1);

Hebergement Joomla basique sur serveur dédié

Pré-requis :
- un serveur de type lamp
- une base de donnée mysql

Téléchargement de joomla

root@serveur:/# cd /var/www/serveur.domaine.com/
root@serveur:/var/www/serveur.domaine.com# ls
root@serveur:/var/www/serveur.domaine.com# wget http://joomlacode.org/gf/download/frsrelease/17715/77262/Joomla_2.5.8-Stable-Full_Package.zip
--2012-11-15 19:56:41--  http://joomlacode.org/gf/download/frsrelease/17715/77262/Joomla_2.5.8-Stable-Full_Package.zip
Resolving joomlacode.org... 206.123.111.164
Connecting to joomlacode.org|206.123.111.164|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://downloads.joomlacode.org/frsrelease/7/7/2/77262/Joomla_2.5.8-Stable-Full_Package.zip [following]
--2012-11-15 19:56:42--  http://downloads.joomlacode.org/frsrelease/7/7/2/77262/Joomla_2.5.8-Stable-Full_Package.zip
Resolving downloads.joomlacode.org... 206.123.111.167
Connecting to downloads.joomlacode.org|206.123.111.167|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7921714 (7.6M) [application/zip]
Saving to: `Joomla_2.5.8-Stable-Full_Package.zip'
100%[==============================================================================================>] 7,921,714   3.10M/s   in 2.4s
2012-11-15 19:56:45 (3.10 MB/s) - `Joomla_2.5.8-Stable-Full_Package.zip' saved [7921714/7921714]

Extraction

root@serveur:/var/www/serveur.domaine.com# unzip Joomla_2.5.8-Stable-Full_Package.zip
...
root@serveur:/var/www/serveur.domaine.com#

Ré-attribution du propriétaire correct :

 chown -fR www-data *
root@serveur:/var/www/serveur.domaine.com#

Il ne vous reste plus qu’à ouvrir votre navigateur favori, vous connecter sur http://serveur.domaine.com et vous laisser guider pour finaliser l’installation.

Création d’une base mysql en ligne de commande

Pour créé une base Mysql et pouvoir l’utiliser, c’est relativement simple, on va utiliser l’outil mysql de base pour : créé une base et donner les droits d’utilisation à un utilisateur.

root@serveur:~# mysql -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 41
Server version: 5.1.63-0+squeeze1 (Debian)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database testjoomla; Query OK, 1 row affected (0.00 sec)
mysql> grant all on testjoomla.* to 'testjoomla'@'localhost' identified by 'password'; Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)

Mise en place d’un lamp ( Linux / Apache / Mysql / Php )

Pré-requis : un serveur linux ( on utilisera ici une Debian 6.0 ) sans rien d’installer dessus.

Pour la suite de l’article, on dira que le serveur a une entrée dns correctement configurée ( ainsi que le reverse ) pour serveur.domaine.com

Installation des logiciels

Ca, on utilise simplement apt et c’est reglé ;)

root@serveur:/home# apt-get install apache2 libapache2-mod-php5 php5 php5-gd php5-mysql mysql-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  apache2-mpm-prefork apache2-utils apache2.2-bin apache2.2-common fontconfig-config heirloom-mailx libapr1 libaprutil1
  libaprutil1-dbd-sqlite3 libaprutil1-ldap libdbd-mysql-perl libdbi-perl libfontconfig1 libgd2-xpm libhtml-template-perl libjpeg62
  libmysqlclient16 libnet-daemon-perl libonig2 libplrpc-perl libpng12-0 libqdbm14 libt1-5 libx11-6 libx11-data libxpm4
  mysql-client-5.1 mysql-common mysql-server-5.1 mysql-server-core-5.1 php5-cli php5-common php5-suhosin ssl-cert ttf-dejavu-core
Suggested packages:
  apache2-doc apache2-suexec apache2-suexec-custom exim4 mail-transport-agent php-pear libgd-tools libipc-sharedcache-perl
  libterm-readkey-perl tinyca openssl-blacklist
Recommended packages:
  mailx
The following NEW packages will be installed:
  apache2 apache2-mpm-prefork apache2-utils apache2.2-bin apache2.2-common fontconfig-config heirloom-mailx libapache2-mod-php5
  libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libdbd-mysql-perl libdbi-perl libfontconfig1 libgd2-xpm
  libhtml-template-perl libjpeg62 libmysqlclient16 libnet-daemon-perl libonig2 libplrpc-perl libpng12-0 libqdbm14 libt1-5 libx11-6
  libx11-data libxpm4 mysql-client-5.1 mysql-common mysql-server mysql-server-5.1 mysql-server-core-5.1 php5 php5-cli php5-common
  php5-gd php5-mysql php5-suhosin ssl-cert ttf-dejavu-core
0 upgraded, 41 newly installed, 0 to remove and 0 not upgraded.
Need to get 37.3 MB of archives.
After this operation, 96.8 MB of additional disk space will be used.
Do you want to continue [Y/n]? Y
....

On verifie que les services tournent bien :

root@serveur:/home# netstat -an | grep LISTEN | egrep "(80|3306)"
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN
tcp6       0      0 :::80                   :::*                    LISTEN

Il semblerait qu’on ait bien quelque chose qui ecoute sur le port 3306 et uniquement sur localhost, le serveur mysql à bien l’air installé.

De même pour le port 80, on doit donc donc avoir apache de lancé. Il suffit de vérifier à l’aide d’un navigateur/telnet que monserveur.mondomaine.com réponds bien et affiche bien “It Works”

Les choses sérieuses, création d’un premier site de test ..

Mise en place de l’arborescence des répertoires

root@serveur:/# mkdir /var/www/www.domaine.com
root@serveur:/# mv /var/www/index.html /var/www/www.domaine.com

On met les droits qui vont bien

root@serveur:/# chown -fR www-data:www-data /var/www/*
root@serveur:/# chmod -fR g+rwxs /var/www/*
root@serveur:/# chmod -fR o-rwx /var/www/*

Prendre votre éditeur de texte préféré pour éditer le fichier /etc/apache2/sites-available afin d’obtenir :

<VirtualHost *:80>
        ServerAdmin webmaster@domaine.com
        ServerName serveur.domaine.com
        DocumentRoot /var/www/serveur.domaine.com
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/serveur.domaine.com/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>
        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/serveur.domaine.com-error.log
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/serveur.domaine.com-access.log combined
</VirtualHost>

On demande à apache de verifier la configuration :

root@srv1:~# apachectl configtest
Syntax OK

Ne reste plus, qu’a lui faire prendre en compte

root@serveur:/# /etc/init.d/apache2 reload
Reloading web server config: apache2.