====== Ngninx et PHP ======
===== Installation des paquets =====
# apt-get install nginx-full nginx-extras php5-cgi php5-mcrypt php5-curl spawn-fcgi
===== Script de démarrage php =====
# vim /etc/init.d/php5-fcgi
#!/bin/sh
### BEGIN INIT INFO
# Provides: php5-fcgi
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: PHP5 FastCgi Spawned processes
### END INIT INFO
COMMAND=/usr/bin/spawn-fcgi
ADDRESS=127.0.0.1
PORT=9000
USER=www-data
GROUP=www-data
PHPCGI=/usr/bin/php5-cgi
PIDFILE=/var/run/fastcgi-php.pid
RETVAL=0
PHP_FCGI_MAX_REQUESTS=500
PHP_FCGI_CHILDREN=2
start() {
export PHP_FCGI_MAX_REQUESTS PHP_FCGI_CHILDREN
$COMMAND -a $ADDRESS -p $PORT -u $USER -g $GROUP -f $PHPCGI -P $PIDFILE
}
stop() {
/usr/bin/killall -9 php5-cgi
}
case "$1" in
start)
start
RETVAL=$?
;;
stop)
stop
RETVAL=$?
;;
restart|reload)
stop
start
RETVAL=$?
;;
*)
echo "Usage: fastcgi {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL
chmod +x /etc/init.d/php5-fcgi
update-rc.d php5-fcgi defaults
===== Modification des configurations fastcgi de Nginx =====
Ajouter ces lignes à la fin du fichier **/etc/nginx/fastcgi_params**
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
===== Configuration d'un site Nginx avec PHP =====
# vim /etc/nginx/sites-available/toto
server {
listen 80;
server_name toto.tld;
access_log /var/log/nginx/toto.access.log;
error_log /var/log/nginx/toto.error.log;
location ~ ^(.+\.php)(/.*)?$ {
fastcgi_pass localhost:9000;
include /etc/nginx/fastcgi_params;
}
}
# ln -s /etc/nginx/sites-available/toto /etc/nginx/sites-enabled/toto
# /etc/init.d/php5-fcgi start
# service nginx reload