Sebastien PALMA - Mot-clé - PHP2024-03-21T20:02:58+01:00Sebastien PALMAurn:md5:9026dd85049a667a0ecd0b71e57f2c5bDotclearInstaller le module SPPLUS sur un serveur Debian Lennyurn:md5:13d95b2194713dcfd13ba2757d2adacb2010-06-01T11:14:00+02:002010-06-01T14:01:10+02:00zokarSysadminDebianPHPSpplus<p>Dans ce billet, je vous explique comment installer le module PHP Spplus, module de paiement en ligne sécurisé de la Caisse d'Epargne</p> <p>Premièrement, s'assurer que nous avons les paquets php5-dev installés :</p>
<pre>
root@~> aptitude install php5-dev
</pre>
<p>Ensuite, téléchargez le module Spplus (a l'heure actuelle, c'est la version 1.2 disponible <a href="http://kits.spplus.net/integration/spplus/kits/spplus-1.2.tar.gz" hreflang="fr">sur ce lien</a>.</p>
<p>Une fois fait, on passe à la partie installation :</p>
<pre>
root@~> tar -zxvf spplus-1.2.tar.gz
root@~> mv spplus-1.2 /tmp
root@~> cd /tmp/spplus-1.2
root@/tmp/spplus-1.2/> phpize
root@/tmp/spplus-1.2/> ./configure -with-php-config=/usr/bin/php-config
root@/tmp/spplus-1.2/> make
</pre>
<p>A ce moment-là, vous avez complié votre module <em>php_spplus.so</em>. Il vous faut maintenant le lancer au chargement de <em>PHP</em>. Pour ma part, mes modules sont dans le dossier <em>/usr/lib/php5/20060613/</em>. J'ai donc copié mon module dans ce répertoire :</p>
<pre>
root@/tmp/spplus-1.2/> cp modules/php_spplus.so /usr/lib/php5/20060613/
root@/tmp/spplus-1.2/> chmod 644 /usr/lib/php5/20060613/php_spplus.so
</pre>
<p>Ensuite, on indique à PHP5 qu'on souhaite charger se module :</p>
<pre>
root@~> echo "extension=php_spplus.so" > /etc/php5/conf.d/php_spplus.ini
root@~> chmod 644 /etc/php5/conf.d/php_spplus.ini
</pre>
<p>Enfin, relancez Apache :</p>
<pre>
root@~> /etc/init.d/apache2 restart
</pre>
<p>Si en ouvrant un <em>php_info();</em> sur votre serveur, vous voyez le texte suivant, c'est gagné :</p>
<pre>
SPPLUS
SPPLUS functions enabled
</pre>
<p>Bonne utilisation !</p>https://blog.cp2i.com/?post/2010/06/01/Installer-le-module-SPPLUS-sur-un-serveur-Debian-Lenny#comment-formhttps://blog.cp2i.com/?feed/atom/comments/16Installation d'un serveur LAMP sous Debian Linux (Lenny)urn:md5:8b4d5be886dbf34dd666e8db2b7f37522010-04-06T16:03:00+02:002014-12-31T10:53:24+01:00zokarSysadminApacheAwStatsMuninMySQLPHPProFTPSquid<p>Je vous expliquerai dans ce tutoriel comment installer et configurer un serveur LAMP complet comprenant :</p>
<ul>
<li>Apache 2 (serveur Web)</li>
<li>PHP 5 (langage)</li>
<li>MySQL (base de données)</li>
<li>PhpMyAdmin (gestion de bases de données)</li>
<li>AwStats (stats web ultra complètes)</li>
<li>Munin (monitoring)</li>
<li>Squid (proxy web)</li>
<li>ProFTPd (transfert de fichiers)</li>
<li>et bien d'autres joyeusetés</li>
</ul> <h2>Disclaimer</h2>
<p>Ce tutoriel n'a pas pour prétention d'être <strong>LE</strong> tuto a suivre par excellence, et peut présenter des erreurs et/ou incohérences. Il vous est donc fourni tel quel en insistant sur le fait que vous suivrez ce tuto à vos risques et périls, car il peut engendrer des soucis de compatibilité avec des fichiers que vous auriez déjà utilisé sur un autre serveur Web, notamment au niveau des droits <img src="/themes/default/smilies/smile.png" alt=":)" class="smiley" /></p>
<p>Voici donc ma manière de procéder lors de l'installation d'un serveur LAMP.</p>
<p>Vous noterez que je sépare bien souvent les paquets lors des commandes <em>aptitude install</em>. Ceci a été fait pour une aisance de lecture, les paquets pouvant bien évidemment être installés tous en même temps dans un même bloc.</p>
<h2>Pré-requis</h2>
<p>Nous partons du postulat que vous avez en possession un serveur Debian Lenny fonctionnant parfaitement avec un compte ayant les droits d'accès de niveau super-utilisateur. Vous avez également la possibilité de vous connecter directement à la machine en console ou bien par le biais de SSH pour exécuter les commandes que nous trouverons ci-dessous.</p>
<p>Compte tenu de la masse de fichiers à modifier et de paquets à installer, passez directement en root.</p>
<p>Nous allons commencer par mettre à jour la liste des paquets ainsi que votre distribution</p>
<pre>
root@> aptitude update
root@> aptitude dist-upgrade
</pre>
<p>Nous allons également installer VIM, évolution de VI, un éiteur de texte plutôt utile, ainsi que APG, générateur de mots de passe.</p>
<pre>
root@> aptitude install vim
root@> aptitude install apg
</pre>
<p>Voila, tout est prêt pour commencer l'installation !</p>
<h2>APACHE 2</h2>
<h3>Installation</h3>
<p>Pour installer Apache2, saisissez les commandes suivantes :</p>
<pre>
root@> aptitude install apache2-mpm-itk
root@> aptitude install libwww-perl
</pre>
<p>Nous choisissons la version ITK d'Apache2, notamment pour sa gestion des droits de fichiers et la possibilité d'affecter un utilisateur particulier au processus Apache (plutôt que de tout faire tourner en tant qu'utilisateur <em>www-data</em>). Pour plus d'information : <a href="http://mpm-itk.sesse.net/" hreflang="en">http://mpm-itk.sesse.net</a></p>
<p>Là votre serveur Web Apache2 est installé. Mais rien n'est encore configuré (sans blagues !)</p>
<h3>Configuration</h3>
<p>Nous allons donc commencer la configuration</p>
<pre>
root@> a2enmod rewrite
root@> echo #AddDefaultCharset UTF-8 > /etc/apache2/conf.d/charset
</pre>
<p>Tapez maintenant la commande :</p>
<pre>
root@> apg -a 1 -M n -m 4 -x 4
</pre>
<p>Cette commande vous donnera une suite aléatoire de 4 chiffres à conserver tout au long de ce tutoriel et qui remplacera les XXXX que vous rencontrerez.</p>
<p>Ouvrez le fichier /etc/apache2/apache2.conf, puis cherchez et remplacez ou ajoutez le cas échéant les lignes suivantes :</p>
<pre>
ServerTokens Prod
ServerAdmin [vous]@[votre_domaine].[extension]
<IfModule mpm_itk_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 250
MaxRequestsPerChild 0
</IfModule>
</pre>
<p>Sauvez le fichier, puis éditez le fichier /etc/apache2/envvars et modifiez-le pour qu'il ressemble à :</p>
<pre>
# envvars - default environment variables for apache2ctl
# Since there is no sane way to get the parsed apache2 config in scripts, some
# settings are defined via environment variables and then used in apache2ctl,
# /etc/init.d/apache2, /etc/logrotate.d/apache2, etc.
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
export APACHE_PID_FILE=/var/run/apache2.pid
umask 007
</pre>
<p>Votre Apache est quasiment configuré et il nous reste la dernière partie qui est la plus importante ; la sécurisation. Pour cela, nous allons installer le module Apache2 mod-security (original hein ?)</p>
<p>Commencez par ajouter le dépôt Debian Backports pour mod-security dans votre fichier /etc/apt/sources.list :</p>
<pre>
deb http://backports.debian.org/debian-backports squeeze-backports main
</pre>
<p>Ensuite, on oblige aptitude à utiliser ce dépôt pour installer mod-security en éditant/créant le fichier /etc/apt/preferences:</p>
<pre>
Package: libapache-mod-security
Pin: release a=lenny-backports
Pin-Priority: 999
</pre>
<p>On installe maintenant le jeu de clés GPG pour se connecter au dépôt:</p>
<pre>
root@> aptitude update
root@> aptitude install debian-backports-keyring
</pre>
<p>Puis on installe le module :</p>
<pre>
root@> aptitude update
root@> aptitude install libapache-mod-security
</pre>
<p>Ouvrez/créez le fichier /etc/apache2/conf.d/mod-security2.conf et modifiez/ajoutez les lignes suivantes :</p>
<pre>
<IfModule mod_security2.c>
# enable mod_security
SecRuleEngine On
# access to request bodies
SecRequestBodyAccess On
#SecRequestBodyLimit 134217728
#SecRequestBodyInMemoryLimit 131072
# access to response bodies
SecResponseBodyAccess On
#SecResponseBodyLimit 524288
SecResponseBodyMimeType (null) text/html text/plain text/xml
#SecServerSignature "Apache/2.2.0 (Fedora)"
SecUploadDir /tmp
SecUploadKeepFiles Off
# default action
SecDefaultAction "log,auditlog,deny,status:406,phase:2,t:none"
SecAuditEngine RelevantOnly
#SecAuditLogRelevantStatus "^[45]"
# use only one log file
SecAuditLogType Serial
# audit log file
SecAuditLog /var/log/apache2/modsec_audit.log
# what is logged
SecAuditLogParts "ABIFHZ"
#SecArgumentSeparator "&"
SecCookieFormat 0
SecDebugLog /var/log/apache2/modsec_debug.log
SecDebugLogLevel 0
SecDataDir /tmp
SecTmpDir /tmp
#########
# RULES
#########
# File name
SecRule REQUEST_FILENAME "modsecuritytest1"
# Complete URI
SecRule REQUEST_URI "modsecuritytest2"
SecRule REQUEST_FILENAME "(?:n(?:map|et|c)|w(?:guest|sh)|cmd(?:32)?|telnet|rcmd|ftp)\.exe"
</IfModule>
ErrorDocument 406 http://SERVERNAME/406.html
</pre>
<h2>PHP 5</h2>
<h3>Installation</h3>
<p>Pour installer PHP5, tapez la commande suivante :</p>
<pre>
root@> aptitude install php5 php5-gd php5-imap
root@> aptitude install php5-ldap php5-mcrypt
root@> aptitude install php5-mhash php5-mysql
root@> aptitude install php5-pgsql php-gettext
</pre>
<p>Simple et efficace...</p>
<h3>Configuration</h3>
<p>Ouvrez le fichier /etc/php5/apache2/php.ini et modifiez les valeurs suivantes ;</p>
<pre>
short_open_tags = Off
disable_functions = exec, shell-exec, system, passthru, putenv, popen
expose_php = Off
display_errors = Off
log_errors = On
allow_url_fopen = Off
</pre>
<p>Voilà, c'est tout pour PHP5. Maintenant, il faut un outil pour voir si votre serveur Web mérite de tourner <img src="/themes/default/smilies/wink.png" alt=";)" class="smiley" /></p>
<h2>Munin</h2>
<h3>Installation</h3>
<p>Comme d'habitude, l'installation se fait avec aptitude</p>
<pre>
root@> aptitude install munin
</pre>
<h3>Configuration</h3>
<p>Pour commencer, éditez le fichier /etc/apache2/mods-available/status.conf pour le remplacer par :</p>
<pre>
<IfModule mod_status.c>
<Location /server-status-XXXX>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
ExtendedStatus On
</IfModule>
</pre>
<p>Sauvez votre fichier et ouvrez le fichier /etc/munin/plugin-conf.d/munin-node puis ajoutez en fin de fichier la ligne</p>
<pre>
[apache_*]
# (XXXX = suite de chiffres générés plus haut)
env.url http://127.0.0.1:%d/server-status-XXXX?auto
# (changer si vous mettez votre apache sur un autre port)
env.port 80
</pre>
<p>Si vous utilisez un noyau GRSEC (visible avec la commande <em>uname -a</em>) ajoutez en fin du fichier /etc/munin/plugin-conf.d/munin-node</p>
<pre>
[processes]
user root
</pre>
<p>Sauvez le fichier, et créez les liens symboliques suivants :</p>
<pre>
root@> cd /etc/munin/plugins
root@/etc/munin/plugins> ln -sf /usr/share/munin/plugins/apache_accesses
root@/etc/munin/plugins> ln -sf /usr/share/munin/plugins/apache_processes
root@/etc/munin/plugins> ln -sf /usr/share/munin/plugins/apache_volume
</pre>
<p>Redémarrez enfin Munin et Apache par la commande :</p>
<pre>
root@> /etc/init.d/munin-node restart
root@> /etc/init.d/apache2 restart
</pre>
<p>Voila, c'est configuré... Pour tester que cela fonctionne :</p>
<pre>
root@> sudo -u munin munin-run apache_accesses
</pre>
<p>Ceci doit vous renvoyer une valeur du type :</p>
<pre>
accesses80.value 19372070
</pre>
<p>Si la commande vous renvoie U, vous avez un soucis d'accès à la page serveur-status-XXXX.</p>
<p>Vérifiez alors que vous avez bien ouvert les ports sur votre serveur Web en local. Vérifiez aussi que le répertoire par défaut (ici <em>/var/www</em>) autorise bien tout le monde a lire et exécuter (755 étant sans doute le plus approprié)</p>
<p>Pour terminer, il nous faut une page qui nous permettra d'accéder rapidement à tous nos outils, car on se souviendra sans doute pas des XXXX rajoutés lors de l'installation.</p>
<p>Pour cela, créez/éditez le fichier /var/www/index.html et placez-y le code suivant :</p>
<pre>[html]
<html>
<head>
<title>Hosting</title>
</head>
<body>
<h1>Accès rapide</h1>
<ul>
<li><a href="/munin/">Stats système</a></li>
<li><a href="/phpmyadmin-XXXX/">Acces PhpMyAdmin</a></li>
<li><a href="/cgi-XXXX/awstats.pl">Stats web</a></li>
<!--
<li><a href="/cgi-XXXX/awstats.pl?config=toto">Stats web du site TOTO.com</a></li>
-->
<li><a href="/info.php">Infos PHP</a></li>
</ul>
<p>
Powered by <a href="http://www.evolix.fr/">Evolix</a>
</body>
</html>
</pre>
<p>Puis, créez le fichier /var/www/info.php avec le contenu suivant :</p>
<pre class="php php" style="font-family:inherit"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;"><?php</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #990000;">phpinfo</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">?></span></div></li></ol></pre>
<p>Vous noublierez pas de donner les droits de lecture (je conseille les droits 750) sur les fichiers contenus dans /var/www/</p>
<p>Ouvrez un navigateur à l'adresse : http://<a href="https://blog.cp2i.com/?post/2008/12/05/votre_site_ou_adresse_IP" title="votre_site_ou_adresse_IP">votre_site_ou_adresse_IP</a>/</p>
<p>Vous devriez avoir une page HTML toute simple, avec des liens qui ne fonctionneront pas pour le moment (nous installerons les services plus tard). Testez le lien "Infos PHP". Si tout se passe bien, vous aurez un grand tableau. C'est que PHP fonctionne :).</p>
<h2>AwStats</h2>
<h3>Installation</h3>
<p>Pour installer Awstats, saisissez la commande :</p>
<pre>
root@> aptitude install awstats
</pre>
<p>Toujours aussi dur hein ? Mais là, on va bien moins rire avec la configuration</p>
<h3>Configuration</h3>
<p>Pour commencer, on va déplacer la configuration d'origine dans un autre fichier afin de pouvoir créer de multiples configurations qui se baseront sur la configuration d'origine.</p>
<pre>
root@> cd /etc/awstats
root@/etc/awstats> mv awstats.conf awstats.conf.local
</pre>
<p>Ensuite, créez le fichier /etc/awstats/awstats.conf et placez-y le contenu suivant :</p>
<pre>
Include "/etc/awstats/awstats.conf.local"
LogFile="/var/log/apache2/access.log"
SiteDomain="votre.site.web.SANS.le.HTTP"
DirData="/var/lib/awstats/"
ShowHostsStats=0
ShowOriginStats=0
ShowPagesStats=0
ShowKeyphrasesStats=0
ShowKeywordsStats=0
ShowHTTPErrorsStats=0
</pre>
<p>Ce fichier de configuration représentera les statistiques de votre serveur GLOBAL. Nous verrons plus tard comment créer des fichiers de configuration par sous-domaine.</p>
<p>Une fois fait, nous allons quelque peu modifier le fichier /etc/awstats/awstats.conf.local :</p>
<pre>
LogFormat=1
AllowFullYearView=3
WarningMessages=1
ErrorMessages="An error occured. Contact your Administrator"
DNSLookup=0
#Include "/etc/awstats/awstats.conf.local"
</pre>
<p>Bien. Seul soucis que j'ai rencontré lors de toutes mes installations, Awstats ne configure pas lui-même Apache2 pour lui faire comprendre qu'il a des images. Créez le fichier /etc/apache2/conf.d/awstats-icon.conf et mettez-y le contenu suivant :</p>
<pre>
Alias /awstats-icon/ /usr/share/awstats/icon/
<Directory /usr/share/awstats/icon/>
Order deny,allow
Allow from all
</Directory>
</pre>
<p>Awstats ne fonctionne pas tout seul, il s'agit d'un simple script Perl. Pour le lancer, vous avez besoin de dire a Apache que le CGI est activé :</p>
<pre>
root@> cd /etc/apache2/mods-enabled
root@> ln -sf /etc/apache2/mods-available/cgi.load cgi.load
</pre>
<p>Enfin, pour lancer régulièrement AwStats, éditez la crontab /etc/cron.d/awstats et placez-y la ligne suivante :</p>
<pre>
0 * * * * root umask 033; [ -x /usr/lib/cgi-bin/awstats.pl -a -f /etc/awstats/awstats.conf -a -r /var/log/apache2/access.log ] && /usr/lib/cgi-bin/awstats.pl -config=awstats -update >/dev/null
</pre>
<p>Pour les personnes qui ne sont pas habituées avec les cron, je vous conseille de faire un petit tour sur <a href="http://www.math-linux.com/spip.php?article16" hreflang="fr">cette page</a> (notamment pour la compréhension de 10 * * * *).</p>
<p>Sauvez la contab (comme un fichier avec VI). Votre AwStats se lancera aux moments que vous aurez défini (dans mon exemples toutes les heures). Seulement, il n'y a rien pour visualiser les résultats. Il va donc falloir ajouter un alias dans votre configuration d'Apache2 (/etc/apache2/sites-avaiable/default) :</p>
<pre>
# CGI
ScriptAlias /cgi-XXXX/ /usr/lib/cgi-bin/
<Directory /usr/lib/cgi-bin/>
Options ExecCGI -MultiViews
AllowOverride None
AuthName "Restricted"
AuthUserFile /var/www/.htpasswdXXXX
AuthGroupFile /dev/null
AuthType Basic
require valid-user
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Allow from [votre_IP]
Satisfy any
</Directory>
</pre>
<p>Vous voyez que pour vous conecter, on demande une authentification par mot de passe (avec le fichier .htpasswdXXXX). Il vous faudra le créer en saisissant la commande :</p>
<pre>
root@> htpasswd -c /var/www/.htpasswdXXXX [utilisateur]
</pre>
<p>Là, le script vous demande de taper et de confirmer un mot de passe, qui sera crypté dans le fichier.</p>
<p>Maintenant, redémarrez Apache2 :</p>
<pre>
root@> /etc/init.d/apache2 restart
</pre>
<p>Si aucune erreur n'apparaît, c'est que vous êtes très bien parti pour faire afficher votre première page !</p>
<p>Rendez-vous sur la page de liens mise en place lors de l'installation d'Apache et cliquez sur le lien "Stats web" et croisez les doigts.</p>
<p>Logiquement, on doit vous demander un login et un mot de passe (ceux saisis dans la commande "htpasswd". Renseignez-les et appréciez le spectacle (ou pas :-D).</p>
<p>Vous pouvez faire des stats séparées site par site. Imaginons que vous ayez un site toto.com (dont les fichiers seront dans /home/toto/www/, les logs dans /home/toto/log/ et les données AwStats stockées dans /home/toto/awstats/). Créez le fichier /etc/awstats/awstats.toto.conf qui sera :</p>
<pre>
Include "/etc/awstats/awstats.conf.local"
LogFile="/home/toto/log/access.log"
SiteDomain="www.toto.com"
DirData="/home/toto/awstats"
</pre>
<p>Une fois fait, vous devrez ajouter dans la crontab :</p>
<pre>
5 * * * * root umask 033; [ -x /usr/lib/cgi-bin/awstats.pl -a -f /etc/awstats/awstats.toto.conf -a -r /home/toto/log/access.log ] && /usr/lib/cgi-bin/awstats.pl -config=toto -update >/dev/null
</pre>
<p>Bien, si vous n'avez pas d'erreur, continuons par l'application de MySQL pour gérer une base de données.</p>
<h3>L'add-on GeoIP</h3>
<p>Cet aadd-on permet de voir de quel pays/ville les visiteurs proviennent. Il permet notamment de s'affranchir du paramètre DNSLookup qui est extrêmement gourmand en ressources (de part ses multiples requêtes Reverse DNS)</p>
<p>Voici comment procéder:</p>
<pre>
root@> aptitude install libgeo-ip-perl geoip-bin libgeoip1
</pre>
<p>Une fois fait, nous allons créer un script qui nous permettra de télécharger et/ou mettre à jour les bases de données de GeoIP, car aucun processus automatique n'est prévu.</p>
<p>J'ai pour ma part choisi de le mettre à jour toutes les semaines. Au cours de mes lectures sur le net, il est souvent préconisé de le mettre à jour tous les mois.</p>
<p>Voici donc le script en question :</p>
<pre class="bash bash" style="font-family:inherit"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>GeoIP</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;"># GeoIP API</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">--quiet</span> http:<span style="color: #000000; font-weight: bold;">//</span>geolite.maxmind.com<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span>geoip<span style="color: #000000; font-weight: bold;">/</span>database<span style="color: #000000; font-weight: bold;">/</span>GeoLiteCountry<span style="color: #000000; font-weight: bold;">/</span>GeoIP.dat.gz </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">[</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">]</span> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">then</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #c20cb9; font-weight: bold;">rm</span> GeoIP.dat</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #c20cb9; font-weight: bold;">gunzip</span> GeoIP.dat.gz</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">else</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #c20cb9; font-weight: bold;">rm</span> GeoIP.dat.gz</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">fi</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;"># GeoIP Cities</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">--quiet</span> http:<span style="color: #000000; font-weight: bold;">//</span>geolite.maxmind.com<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span>geoip<span style="color: #000000; font-weight: bold;">/</span>database<span style="color: #000000; font-weight: bold;">/</span>GeoLiteCity.dat.gz </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">[</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">]</span> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">then</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #c20cb9; font-weight: bold;">rm</span> GeoLiteCity.dat</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #c20cb9; font-weight: bold;">gunzip</span> GeoLiteCity.dat.gz</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">else</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #c20cb9; font-weight: bold;">rm</span> GeoLiteCity.dat.gz</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">fi</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;"># GeoIP Organisations </span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">--quiet</span> http:<span style="color: #000000; font-weight: bold;">//</span>geolite.maxmind.com<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span>geoip<span style="color: #000000; font-weight: bold;">/</span>database<span style="color: #000000; font-weight: bold;">/</span>asnum<span style="color: #000000; font-weight: bold;">/</span>GeoIPASNum.dat.gz</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">[</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">]</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">then</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #c20cb9; font-weight: bold;">rm</span> GeoIPASNum.dat</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #c20cb9; font-weight: bold;">gunzip</span> GeoIPASNum.dat.gz</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">else</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #c20cb9; font-weight: bold;">rm</span> GeoIPASNum.dat.gz</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">fi</span></div></li></ol></pre>
<p>C'est tout bête, mais placé dans <em>/etc/cron.weekly</em> sous le nom de votre choix (chez moi <em>updateGeoIP</em>), il fera le boulot tout seul. On va le lancer à la main une fois pour installer le tout (bah oui, rien n'est présent!) :</p>
<pre>
root@> chmod +x /etc/cron.weekly/updateGeoIP
root@> /etc/cron.weekly/updateGeoIP
</pre>
<p>Le script ne doit renvoyer aucun output... Si tout se passe bien, vous devriez avoir trois fichiers dans <em>/usr/share/GeoIP</em> :</p>
<ul>
<li>GeoIPASNum.dat</li>
<li>GeoIP.dat</li>
<li>GeoLiteCity.dat</li>
</ul>
<p>Une fois fait, ouvrez le fichier <em>/etc/awstats/awstats.conf.local</em> et localisez la ligne commentée :</p>
<pre class="bash bash" style="font-family:inherit"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;">#LoadPlugin="geoip GEOIP_STANDARD /usr/share/GeoIP/GeoIP.dat"</span></div></li></ol></pre>
<p>Remplacez-la par :</p>
<pre class="bash bash" style="font-family:inherit"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #007800;">LoadPlugin</span>=<span style="color: #ff0000;">"geoip GEOIP_STANDARD /usr/share/GeoIP/GeoIP.dat"</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #007800;">LoadPlugin</span>=<span style="color: #ff0000;">"geoip_city_maxmind GEOIP_STANDARD /usr/share/GeoIP/GeoLiteCity.dat"</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #007800;">LoadPlugin</span>=<span style="color: #ff0000;">"geoip_org_maxmind GEOIP_STANDARD /usr/share/GeoIP/GeoIPASNum.dat"</span></div></li></ol></pre>
<p>Vous pourrez commenter la troisième ligne si celle-ci ne vous interresse pas (savoir a qui appartient la plage IP en terme de provider).</p>
<h3>AwStats sur des sites à très fortes visites</h3>
<p>Il se peut que vous ayez des soucis quand vous essayez de faire tourner AwStats avec d'importants volumes de log (on parle la de millions de lignes de logs quotidiens).</p>
<p>Si comme moi (nan, pas sur ce blog...), aux alentours du 15 du mois, AwStats prend de plus en plus de temps et de RAM, et que vous souhaitez rendre AwStats plus rapide, vous pouvez, au sacrifice des unique IP, accélérer grandement la vitesse d'exécution de votre AwStats en lancant juste avant le parsing des logs ce script :</p>
<pre class="bash bash" style="font-family:inherit"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;">#Logs de la veille</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #007800;">MaDate</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'BEGIN{ printf("%s\n", strftime("%m%Y", systime()-86400)) }'</span><span style="color: #000000; font-weight: bold;">`</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;">#Logs du jour</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;">#MaDate=`date +%m%Y`</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">for</span> fichier <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>awstats<span style="color: #000000; font-weight: bold;">/</span>awstats<span style="color: #800000;">${MaDate}</span>.<span style="color: #000000; font-weight: bold;">*</span>.txt<span style="color: #000000; font-weight: bold;">`</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">do</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #ff0000;">'/^BEGIN_VISITOR/,/^END_VISITOR/d'</span> <span style="color: #007800;">$fichier</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">done</span></div></li></ol></pre>
<p>Il ne vous reste plus qu'a décommenter la ligne qui vous convient pour la variable <em>MaDate</em> et le tour est joué !</p>
<p>Merci a <a href="http://sourceforge.net/projects/awstats/forums/forum/43428/topic/3765458" hreflang="en">jfroot</a> pour le conseil !</p>
<p>Et voilà !</p>
<h2>MySQL 5 & PHPMyAdmin</h2>
<h3>Installation</h3>
<p>Comme d'habitude, il est très difficile d'installer ce genre d'application.... Cependant, lors des différentes demandes de mot de passe (de mémoire 5 ou 6 fois) pour le compte "root", <strong>n'en saisissez pas !!!</strong> En effet, le compte root sera a terme supprimé dans notre tuto, il est donc inutile de le sécuriser.</p>
<pre>
root@> aptitude install mysql-server phpmyadmin mytop
</pre>
<p>Une fois fait, nous allons tout de suite rajouter une petite couche sécurité.</p>
<h3>Configuration</h3>
<p>Commencez par taper la commande :</p>
<pre>
root@> apg -p [uneSeriEdeCaRacTèResComMeVousVoul€z]
</pre>
<p>Cette commande vous enverra une liste de 6 mots de passe différents, choisissez-en un que nous identifierons par MDP dans le reste du tutoriel.</p>
<p>Effectuez maintenant les opérations suivantes :</p>
<pre>
root@> mysql
mysql> use mysql;
mysql> GRANT ALL PRIVILEGES ON *.* TO mysqladmin@localhost IDENTIFIED BY 'MDP' WITH GRANT OPTION;
mysql> delete from user where user='root';
mysql> flush privileges;
mysql> \q
</pre>
<p>Comme vous venez de le voir, vous avez supprimé les droits de l'utilisateur root et ajouté un super-utilisateur nommé mysqladmin avec un mot de passe assez hardu.</p>
<p>Comme je suis persuadé que vous aurez un mal fou à le retenir, créez le fichier /root/.my.cnf (attention au POINT avant my) et placez-y les lignes suivantes :</p>
<pre>
[client]
user=mysqladmin
password=MDP
</pre>
<p>Créez également un fichier /root/.mytop dans lequel vous saisirez les commandes suivantes :</p>
<pre>
user = mysqladmin
pass = MDP
db = mysql
</pre>
<p>Cela vous permettra de vous connecter à MySQL et a MyTop sans taper votre mot de passe, <ins>mais uniquement en console en ayant effectué un <em>sudo su</em></ins>.</p>
<p>Une fois fait, ajouter l'accès à PhpMyAdmin. Editez le fichier /etc/apache2/sites-avaiable/default et ajoutez le contenu suivant :</p>
<pre>
Alias /phpmyadmin-XXXX /usr/share/phpmyadmin/
</pre>
<p>Sauvez le fichier et rechargez Apache2 :</p>
<pre>
root@> /etc/init.d/apache2 force-reload
</pre>
<p>Et voila! En vous rendant à l'adresse : http://www.domaine.tld/phpmyadmin-XXXX vous pourrez administrer votre base de données en vous identifiant avec l'utilisateur mysqladmin et le mot de passe MDP.</p>
<p>Passons ensuite au dernier élément qui vous permettra de mettre en place votre premier site : ProFTPd</p>
<h2>Squid</h2>
<h3>Installation</h3>
<p>Toujours pareil :</p>
<pre>
root@> aptitude install squid
</pre>
<h3>Configuration</h3>
<p>Pour la configuration, voici le fichier <em>squid.conf</em> que je conseille :</p>
<pre>
# ports
http_port 8888 transparent
icp_port 0
# ACL
acl all src 0.0.0.0/0.0.0.0
acl localhost src 127.0.0.1/255.255.255.255
acl INTERNE src ADRESSE_IP/32 127.0.0.0/8
acl Safe_ports port 80 # http
acl SSL_ports port 443 563
acl WHITELIST url_regex "/etc/squid/whitelist.conf"
http_access deny !WHITELIST
http_access allow INTERNE
http_access deny all
access_log /var/log/squid/access.log squid
</pre>
<p>Il vous suffit de remplacer ADRESSE_IP par l'adresse IP de votre serveur.</p>
<p>Créez ensuite un fichier <em>/etc/squid/whitelist.conf</em> et rajoutez les adresses web externes auxquelles votre serveur aura le droit de se connecter (généralement des adresses de webservices ou de dépôts de paquets). Exemples :</p>
<pre>
http://.*.facebook.com/.*
http://.*.twitter.com/.*
http://rss.laposte.net/.*
</pre>
<p>Et redémarrer Squid après avoir modifié la whitelist</p>
<pre>
root@> /etc/init.d/squid restart
</pre>
<h2>ProFTPd</h2>
<h3>Installation</h3>
<p>Je suis sur que vous avez déjà deviné que cela allait se passer de la sorte :</p>
<pre>
root@> aptitude install proftpd
</pre>
<p>Si si, j'vous jure.</p>
<p>A la question fatidique "inetd ou standalone?" répondez "standalone", Si vous ne savez pas pourquoi... Moi non plus <img src="/themes/default/smilies/cool.png" alt="8-)" class="smiley" /> Non pour faire bref, le fait de choisir "standalone" permet une plus grande souplesse pour le redémarrage du service.</p>
<h3>Configuration</h3>
<p>Ouvrez le fichier de configuration et cherchez les lignes suivantes (ou ajoutez-les le cas échéant):</p>
<pre>
ServerName "[Votre Nom/Site] FTP Server"
ServerType standalone
PassivePorts 60000 61000
UseReverseDNS off
IdentLookups off
#restrictions en kB/s
#up
#TransferRate APPE,STOR 100
#down
#TransferRate RETR 100
<IfModule mod_ctrls_admin.c>
AdminControlsEngine on
</IfModule>
DefaultRoot ~
RequireValidShell on
UseFtpUsers off
ServerIdent on "FTP Server Ready"
AccessGrantMsg "Hey, bienvenue %u sur le serveur FTP de [Votre Nom/Site] !"
Umask 027 027
</pre>
<p>Une fois fait, relancez ProFTPd :</p>
<pre>
root@> /etc/init.d/proftpd restart
</pre>
<p>Et voila, vous pouvez vous connecter sur votre FTP à l'adresse : ftp://www.domaine.tld:21/</p>
<p>Vous disposez maintenant de votre serveur Web installé et configuré pour un site dont les fichiers seront a déposer dans /var/www/.</p>
<p>Dans un futur très proche, je rédigerai un tutoriel sur la manière de rajouter un site pouvant être totalement autonome sur la même plateforme que nous venons d'installer.</p>
<p>Si vous avez des remarques, questions, corrections à apporter au sujet, n'hésitez pas à me contacter !</p>
<p>Bonne journée !</p>https://blog.cp2i.com/?post/2008/12/05/Installation-d-un-serveur-web-sous-Debian-Linux#comment-formhttps://blog.cp2i.com/?feed/atom/comments/4