This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
|
nginx_php_fastcgi [2007/11/28 09:47] kyxap создано |
nginx_php_fastcgi [2013/12/15 16:48] (current) kyxap |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Совмещение Nginx и PHP (fast cgi) ====== | + | {{tag>debian etch php php-fpm fcgi apache nginx}}====== Совмещение Nginx и PHP (fast cgi) ====== |
| * Ставим nginx стандартными средствами OS | * Ставим nginx стандартными средствами OS | ||
| Line 7: | Line 7: | ||
| * В директории с пропатченными исходниками создаем файлик ''MyConfig.cgi.sh'' со следующим содержимым: | * В директории с пропатченными исходниками создаем файлик ''MyConfig.cgi.sh'' со следующим содержимым: | ||
| - | #!/bin/sh | + | <code bash> |
| - | CFLAGS="-O2" ./configure --prefix=/opt/php-x.x.x-fcgi \ | + | #!/bin/sh |
| - | --enable-calendar \ | + | CFLAGS="-O2" ./configure --prefix=/opt/php-x.x.x-fcgi \ |
| - | --enable-sysvsem \ | + | --enable-calendar \ |
| - | --enable-sysvshm \ | + | --enable-sysvsem \ |
| - | --enable-sysvmsg \ | + | --enable-sysvshm \ |
| - | --enable-ftp \ | + | --enable-sysvmsg \ |
| - | --with-mcrypt \ | + | --enable-ftp \ |
| - | --with-mysql \ | + | --with-mcrypt \ |
| - | --with-mysqli \ | + | --with-mysql \ |
| - | --enable-bcmath \ | + | --with-mysqli \ |
| - | --with-bz2 \ | + | --enable-bcmath \ |
| - | --with-gd \ | + | --with-bz2 \ |
| - | --with-jpeg-dir \ | + | --with-gd \ |
| - | --with-zlib-dir \ | + | --with-jpeg-dir \ |
| - | --with-curl \ | + | --with-zlib-dir \ |
| - | --enable-sockets \ | + | --with-curl \ |
| - | --with-iconv \ | + | --enable-sockets \ |
| - | --enable-mbstring \ | + | --with-iconv \ |
| - | --enable-mbregex \ | + | --enable-mbstring \ |
| - | --enable-ctype \ | + | --enable-mbregex \ |
| - | --enable-shmop \ | + | --enable-ctype \ |
| - | --enable-wddx \ | + | --enable-shmop \ |
| - | --with-imap \ | + | --enable-wddx \ |
| - | --with-freetype-dir \ | + | --with-imap \ |
| - | --with-xmlrpc \ | + | --with-freetype-dir \ |
| - | --enable-dbase \ | + | --with-xmlrpc \ |
| - | --with-mime-magic \ | + | --enable-dbase \ |
| - | --with-mhash \ | + | --with-mime-magic \ |
| - | --with-gettext \ | + | --with-mhash \ |
| - | --with-imap-ssl \ | + | --with-gettext \ |
| - | --with-pear \ | + | --with-imap-ssl \ |
| - | --with-kerberos \ | + | --with-pear \ |
| - | --with-openssl \ | + | --with-kerberos \ |
| - | --with-snmp \ | + | --with-openssl \ |
| - | --with-config-file-path=/opt/etc/phpX \ | + | --with-snmp \ |
| - | --enable-fastcgi \ | + | --with-config-file-path=/opt/etc/phpX \ |
| - | --enable-force-cgi-redirect \ | + | --enable-fastcgi \ |
| - | --enable-fpm | + | --enable-force-cgi-redirect \ |
| + | --enable-fpm | ||
| + | </code> | ||
| * Собираем командами | * Собираем командами | ||
| Line 55: | Line 57: | ||
| * Создаем в **/opt/scripts** скрипт ''fcgi.sh'' со следующим содержимым: | * Создаем в **/opt/scripts** скрипт ''fcgi.sh'' со следующим содержимым: | ||
| - | #!/bin/bash | + | <code bash> |
| - | # ABSOLUTE path to the PHP binary | + | #!/bin/bash |
| - | PHPFCGI="/opt/php-x.x.x-fcgi/bin/php-cgi" | + | # ABSOLUTE path to the PHP binary |
| - | # tcp-port to bind on | + | PHPFCGI="/opt/php-x.x.x-fcgi/bin/php-cgi" |
| - | FCGIPORT="8888" | + | # tcp-port to bind on |
| - | # IP to bind on | + | FCGIPORT="8888" |
| - | FCGIADDR="127.0.0.1" | + | # IP to bind on |
| - | # number of PHP children to spawn | + | FCGIADDR="127.0.0.1" |
| + | # number of PHP children to spawn | ||
| + | PHP_FCGI_CHILDREN=5 | ||
| + | # number of request before php-process will be restarted | ||
| + | PHP_FCGI_MAX_REQUESTS=1000 | ||
| + | # allowed environment variables sperated by spaces | ||
| + | ALLOWED_ENV="PATH USER" | ||
| + | # if this script is run as root switch to the following user | ||
| + | USERID=www-data | ||
| + | ################## no config below this line | ||
| + | if test x$PHP_FCGI_CHILDREN = x; then | ||
| PHP_FCGI_CHILDREN=5 | PHP_FCGI_CHILDREN=5 | ||
| - | # number of request before php-process will be restarted | + | fi |
| - | PHP_FCGI_MAX_REQUESTS=1000 | + | ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_CHILDREN" |
| - | # allowed environment variables sperated by spaces | + | ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_MAX_REQUESTS" |
| - | ALLOWED_ENV="PATH USER" | + | ALLOWED_ENV="$ALLOWED_ENV FCGI_WEB_SERVER_ADDRS" |
| - | # if this script is run as root switch to the following user | + | if test x$UID = x0; then |
| - | USERID=www-data | + | EX="/bin/su -m -c \"$PHPFCGI -q -b $FCGIADDR:$FCGIPORT\" $USERID" |
| - | ################## no config below this line | + | else |
| - | if test x$PHP_FCGI_CHILDREN = x; then | + | EX="$PHPFCGI -b $FCGIADDR:$FCGIPORT" |
| - | PHP_FCGI_CHILDREN=5 | + | fi |
| - | fi | + | echo $EX |
| - | ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_CHILDREN" | + | # copy the allowed environment variables |
| - | ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_MAX_REQUESTS" | + | E= |
| - | ALLOWED_ENV="$ALLOWED_ENV FCGI_WEB_SERVER_ADDRS" | + | for i in $ALLOWED_ENV; do |
| - | if test x$UID = x0; then | + | E="$E $i=${!i}" |
| - | EX="/bin/su -m -c \"$PHPFCGI -q -b $FCGIADDR:$FCGIPORT\" $USERID" | + | done |
| - | else | + | # clean environment and set up a new one |
| - | EX="$PHPFCGI -b $FCGIADDR:$FCGIPORT" | + | nohup env - $E sh -c "$EX" &> /dev/null & |
| - | fi | + | </code> |
| - | echo $EX | + | |
| - | # copy the allowed environment variables | + | |
| - | E= | + | |
| - | for i in $ALLOWED_ENV; do | + | |
| - | E="$E $i=${!i}" | + | |
| - | done | + | |
| - | # clean environment and set up a new one | + | |
| - | nohup env - $E sh -c "$EX" &> /dev/null & | + | |
| * За что отвечают параметры, думается мне, можно понять и по комментариям, так что добавляем скрипт в автозагрузку методом OS, для которой проводится установка. | * За что отвечают параметры, думается мне, можно понять и по комментариям, так что добавляем скрипт в автозагрузку методом OS, для которой проводится установка. | ||
| * Шаблон виртуального хоста в ''nginx'' будет выглядеть таким образом: | * Шаблон виртуального хоста в ''nginx'' будет выглядеть таким образом: | ||