Nginx est un serveur WEB libre, open-source et haute performance. Nginx est reconnu pour ses hautes performances, sa stabilité, son ensemble de fonctionnalités, sa configuration simple ainsi que sa faible consommation de ressources.Ce serveur sera installé sur Debian 6 Squeeze
1 – Installation de NGINX, MySQL et PHP
1-1 Installation de NGINX
On va commencer par installer NGINX.
aptitude install nginx
Après l’installation il faut lancer le service nginx.
/etc/init.d/nginx start
Vous pouvez vérifier que NGINX répond en saisissant l’adresse de votre serveur dans un navigateur internet
Le message suivant doit apparaitre
1-2 Installation de PHP
aptitude install php5-cgi php5-mcrypt php5-mysql
Création du script de démarrage de php
nano /etc/init.d/php5-cgi
#! /bin/sh
### BEGIN INIT INFO
# Provides: php-fastcgi
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start and stop php-cgi in external FASTCGI mode
# Description: Start and stop php-cgi in external FASTCGI mode
### END INIT INFO
# Do NOT « set -e »
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC= »php-cgi in external FASTCGI mode »
NAME=php-fastcgi
DAEMON=/usr/bin/php-cgi
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# Exit if the package is not installed
[ -x « $DAEMON » ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
# If the daemon is not enabled, give the user a warning and then exit,
# unless we are stopping the daemon
if [ « $START » != « yes » -a « $1 » != « stop » ]; then
log_warning_msg « To enable $NAME, edit /etc/default/$NAME and set START=yes »
exit 0
fi
# Process configuration
export PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS
DAEMON_ARGS= »-q -b $FCGI_HOST:$FCGI_PORT »
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon –start –quiet –pidfile $PIDFILE –exec $DAEMON –test > /dev/null || return 1
start-stop-daemon –start –quiet –pidfile $PIDFILE –exec $DAEMON –background –make-pidfile –chuid $EXEC_AS_USER –startas $DAEMON — $DAEMON_ARGS || return 2
}
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon –stop –quiet –retry=TERM/30/KILL/5 –pidfile $PIDFILE > /dev/null # –name $DAEMON
RETVAL= »$? »
[ « $RETVAL » = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
start-stop-daemon –stop –quiet –oknodo –retry=0/30/KILL/5 –exec $DAEMON
[ « $? » = 2 ] && return 2
# Many daemons don’t delete their pidfiles when they exit.
rm -f $PIDFILE
return « $RETVAL »
}
case « $1 » in
start)
[ « $VERBOSE » != no ] && log_daemon_msg « Starting $DESC » « $NAME »
do_start
case « $? » in
0|1) [ « $VERBOSE » != no ] && log_end_msg 0 ;;
2) [ « $VERBOSE » != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ « $VERBOSE » != no ] && log_daemon_msg « Stopping $DESC » « $NAME »
do_stop
case « $? » in
0|1) [ « $VERBOSE » != no ] && log_end_msg 0 ;;
2) [ « $VERBOSE » != no ] && log_end_msg 1 ;;
esac
;;
restart|force-reload)
log_daemon_msg « Restarting $DESC » « $NAME »
do_stop
case « $? » in
0|1)
do_start
case « $? » in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
echo « Usage: $SCRIPTNAME {start|stop|restart|force-reload} » >&2
exit 3
;;
esac
Control + X pour quitter nano
Il demande si l’on sauve, dire Oui en pressant la touche O
Il demande comment le fichier doit s’appeler, faire Entrée pour ne toucher à rien.
Rendre le script exécutable
chmod +x /etc/init.d/php5-cgi
Ajouter le script au démarrage
update-rc.d php5-cgi defaults
Créer un fichier de configuration pour php fastcgi
nano /etc/default/php-fastcgi
#
# Settings for php-cgi in external FASTCGI Mode
#
# Should php-fastcgi run automatically on startup? (default: no)
START=yes
# Which user runs PHP? (default: www-data)
EXEC_AS_USER=www-data
# Host and TCP port for FASTCGI-Listener (default: localhost:9000)
FCGI_HOST=localhost
FCGI_PORT=9000
# Environment variables, which are processed by PHP
PHP_FCGI_CHILDREN=9
PHP_FCGI_MAX_REQUESTS=1000
Control + X pour quitter nano
Il demande si l’on sauve, dire Oui en pressant la touche O
Il demande comment le fichier doit s’appeler, faire Entrée pour ne toucher à rien.
Faire une sauvegarde du fichier /etc/nginx/nginx.conf
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.old
Editer le fichier /etc/nginx/nginx.conf et coller le contenu ci-dessous.
user www-data www-data;
worker_processes 3;
worker_rlimit_nofile 15000;
daemon on;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
timer_resolution 500ms;
events {
worker_connections 10240;
use epoll;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
sendfile on;
tcp_nopush on;
log_not_found on;
keepalive_timeout 65;
tcp_nodelay on;
gzip on;
server {
listen 80;
server_name localhost;
access_log /var/log/nginx/access.log;
root /var/www/;
location / {
root /var/www/;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#include fastcgi_params;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 220;
fastcgi_buffer_size 256k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
include /etc/nginx/fastcgi_params;
}
# deny access to .htaccess files, if Apache’s document root
# concurs with nginx’s one
#
location ~ /\.ht {
deny all;
}
# deny access to .htaccess files, if Apache’s document root
# concurs with nginx‘s one
#
#location ~ /\.ht {
# deny all;
#}
}
}
Control + X pour quitter nano
Il demande si l’on sauve, dire Oui en pressant la touche O
Il demande comment le fichier doit s’appeler, faire Entrée pour ne toucher à rien.
Démarrer le service PHP
/etc/init.d/php5-cgi start
Editer le fichier /etc/php5/cgi/php.ini
nano /etc/php5/cgi/php.ini
Décommenter la ligne suivante
cgi.fix_pathinfo=1
Control + X pour quitter nano
Il demande si l’on sauve, dire Oui en pressant la touche O
Il demande comment le fichier doit s’appeler, faire Entrée pour ne toucher à rien.
Après avoir lancé le service NGINX, il faut créer le dossier /var/www
mkdir /var/www
echo « <?php phpinfo();?> » > /var/www/phpinfo.php
chown www-data:www-data /var/www
On vient de créer un fichier phpinfo.php qui va nous permettre de verifier que PHP fonctionne. Pour cela, saisir http://ip.de.votre.serveur/phpinfo.php
Les infos sur PHP devraient apparaitre. Si jamais celles-ci n’apparaissent pas, redémarrer votre serveur.
1-3 Installation de MySQL
aptitude install mysql-server mysql-client
1-4 Installation et Configuration PHPMYADMIN
Pour gérer la base de données SQL facilement, je vais installer Phpmyadmin.
Téléchargement de PHPMYADMIN
cd /var/www
mv phpMyAdmin-3.3.10-all-languages.tar.gz\?r\=http\:%2F%2Fwww.phpmyadmin.net%2Fhome_page%2Fdownloads.php phpmyadmin.tar.gz
tar –xvzf phpmyadmin.tar.gz
mv phpMyAdmin-3.3.10-all-languages/ phpmyadmin
Configuration de PHPMYADMIN
cd /var/www/phpmyadmin
cp config.sample.inc.php config.inc.php
nano config.inc.php
Modifier la ligne suivante :
$cfg[‘blowfish_secret’] = ‘saisirunephrase’; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
Désinstaller le module suhosin
aptitude purge php5-suhosin
Vous pouvez désormais vous connecter sur Phpmyadmin a l’adresse suivante : http://ip.de.votre.serveur/phpmyadmin
Saisir le nom d’utilisateur et le mot de passe de passe pour vous connecter.
Vous avez maintenant un serveur web opérationnel tournant avec NGINX, MySQL, PHPMYADMIN.
Auteur : POMENTE Guillaume
Partager la publication "[TUTO] INSTALLATION & CONFIGURATION SERVEUR WEB NGINX MYSQL PHPMYADMIN SUR DEBIAN 6 SQUEEZE"