CentOS 5.5 – Install Apache 2
FrançaisLinuxTutorials
Paramètres de configuration
Hostname : SERVER-01
Adresse IP : 192.168.2.42
Pré-requis
– CentOS 5.5 Base install
– CentOS 5.5 Réseau install
– CentOS 5.5 Config firewall
Installation Apache 2
On installe quelques librairies supplémentaires (toutes ne sont pas utiles… pour l’instant) :
yum install -y apr apr-devel apr-util apr-util-devel libxml pcre pcre-devel
Téléchargement et décompression des sources d’Apache :
cd ~ wget -c http://apache.crihan.fr/dist/httpd/httpd-2.2.17.tar.gz tar zxvf httpd-2.2.17.tar.gz cd ~/httpd-2.2.17/
Préparation de la compilation, compilation et installation :
./configure --prefix=/usr/local/apache-2.2.17 --enable-so --enable-ssl --enable-ssl=shared --enable-rewrite --enable-rewrite=shared --with-z=/usr make make install
Un petit lien symbolique qui sera bien utile en cas de migration vers une version ultérieure plus tard :
ln -s /usr/local/apache-2.2.17/ /usr/local/apache
Un peu de ménache :
cd ~ rm -Rf ~/httpd-2.2.17/
Création du groupe et de l’utilisateur pour Apache
groupadd www useradd -g www www
Création d’un script de lancement d’Apache dans /etc/init.d/
cat > /etc/init.d/httpd << "EOF"
#!/bin/bash
# chkconfig: 3 21 91
#
# httpd
#
# description: Start up the Apache Web server.
# Source function library.
. /etc/rc.d/init.d/functions
RETVAL=$?
APACHEHOME="/usr/local/apache"
# See how we were called.
case "$1" in
start)
echo -n "Starting httpd: "
daemon $APACHEHOME/bin/httpd
echo
touch /var/lock/subsys/httpd
;;
stop)
echo -n "Shutting down http: "
killproc httpd
echo
rm -f /var/lock/subsys/httpd
rm -f /var/run/httpd.pid
;;
status)
status httpd
;;
restart)
$0 stop
$0 start
;;
reload)
echo -n "Reloading httpd: "
killproc httpd -HUP
echo
;;
*)
echo "Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit 0
EOF
[/shell]
On positionne les droits sur cet exécutable :
[shell]chmod 700 /etc/init.d/httpd[/shell]
Coupons et lançons apache :
[shell]
/etc/init.d/httpd stop
/etc/init.d/httpd start
[/shell]
Et hop on active apache au lancement du serveur (puis on le coupe lors de l'arrêt) :
[shell]
/sbin/chkconfig --level 3 httpd on
/sbin/chkconfig --level 06 httpd off
[/shell]
Il faut maintenant préparer Apache.
Donc on le stoppe :
[shell]/etc/init.d/httpd stop[/shell]
Création des répertoires qui nous servirons à déployer nos sites :
[shell]
mkdir -p /home/www/html
mkdir -p /home/www/cgi-bin
[/shell]
Un petit fichier pour nos amis les robots :
[shell]cat > /home/www/html/robots.txt << "EOF"
User-agent: *
Disallow: /
EOF
[/shell]
Et un fichier d'accueil pour dire bonjour à la planète entière :
[shell]
cat > /home/www/html/index.html << "EOF"
Bonjour !
EOF
[/shell]
Affectation des droits à tous ces répertoires :
[shell]
chgrp -R www /home/www
chmod -R 775 /home/www
[/shell]
Un peu de configuration maintenant.
On commence par sauvegarder puis éditer le fichier <strong>/usr/local/apache/conf/httpd.conf</strong> :
[shell]cp /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.old
Puis on édite le fichier (pour plus d’info sur vi tapez “vi commandes de bases” dans un site de recherche quelconque) :
vi /usr/local/apache/conf/httpd.conf
Modifier les lignes suivantes pour correspondre à nos besoins :
– User www
– Group www
– ServerAdmin moncourriel@mondomaine.xx
– ServerName 192.168.2.42:80
– Listen 80
– DirectoryIndex index.html index.php index.jsp
– DocumentRoot “/home/www/html”
– /home/www/html”>
– ScriptAlias /cgi-bin/ “/home/www/cgi-bin/”
– /home/www/cgi-bin”>
Options FollowSymLinks
AllowOverride All
Allow from all
Le firewall
N’oublions pas de régler le firewall histoire qu’il autorise les connexions sur notre serveur web (http et https) :
iptables -A INPUT -p tcp --dport 80 -j ACCEPT iptables -A INPUT -p tcp --dport 443 -j ACCEPT /sbin/service iptables save
——————————————————————————–
Pour aller plus loin
– Installation de PHP
– Configuration du Backup/restore
Leave a comment