Site Tools


index:linux:web:nginx:php

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
index:linux:web:nginx:php [2017/10/01 10:38] – créée schermiindex:linux:web:nginx:php [2024/12/17 12:04] (current) – external edit 127.0.0.1
Line 3: Line 3:
 ===== Installation des paquets ===== ===== Installation des paquets =====
  
 +<code># apt-get install nginx-full nginx-extras php5-cgi php5-mcrypt php5-curl spawn-fcgi</code>
  
 +===== Script de démarrage php =====
 +
 +<code># vim /etc/init.d/php5-fcgi</code>
 +<code>
 +#!/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
 +</code>
 +<code>chmod +x /etc/init.d/php5-fcgi</code>
 +<code>update-rc.d php5-fcgi defaults</code>
 +
 +===== Modification des configurations fastcgi de Nginx =====
 +
 +Ajouter ces lignes à la fin du fichier **/etc/nginx/fastcgi_params**
 +<code>
 +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;
 +</code>
 +
 +===== Configuration d'un site Nginx avec PHP =====
 +
 +<code># vim /etc/nginx/sites-available/toto</code>
 +
 +<code>
 +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;
 +    }
 +
 +}
 +</code>
 +
 +<code># ln -s /etc/nginx/sites-available/toto /etc/nginx/sites-enabled/toto</code>
 +<code># /etc/init.d/php5-fcgi start</code>
 +<code># service nginx reload</code>
index/linux/web/nginx/php.1506847089.txt.gz · Last modified: 2024/12/17 12:04 (external edit)