NGINX 与 PHP 有什么关系?

NGINX 与 PHP 有什么关系?

我刚刚在 ubuntu 上安装了 nginx manual。我该如何包含 php?

答案1

首先获取 php

cd /tmp
wget http://nl3.php.net/get/php-5.3.3.tar.gz/from/nl2.php.net/mirror
tar -xzf php-5.3.3.tar.gz

然后停止 nginx

service nginx stop

安装普通 php 功能所需的所有包和模块,还可以包含其他包和模块。

apt-get install autoconf2.13 libssl-dev libcurl4-gnutls-dev libjpeg62-dev libpng12-dev  libmysql++-dev libfreetype6-dev libt1-dev libc-client-dev mysql-client libevent-dev libxml2-dev libtool libmcrypt-dev
cd php-5.3.3
./configure --enable-fpm --with-mcrypt --enable-mbstring --with-openssl --with-mysql --with-mysql-sock --with-gd --with-jpeg-dir=/usr/lib --enable-gd-native-ttf  --with-pdo-mysql --with-libxml-dir=/usr/lib --with-mysqli=/usr/bin/mysql_config --with-curl --enable-zip  --enable-sockets --with-zlib --enable-exif --enable-ftp --with-iconv --with-gettext --enable-gd-native-ttf --with-t1lib=/usr --with-freetype-dir=/usr --prefix=/usr/local/php --with-fpm-user=www-data –with-fpm-group=www-data

运行安装

make
make install

将配置和其他文件放在正确的位置

cp php.ini-development /usr/local/php/php.ini
chmod 644 /usr/local/php/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
update-rc.d -f php-fpm defaults
touch /var/run/php-fpm.pid

配置 nginx

php_fpm_PID =${prefix}/var/run/php-fpm.pid into php_fpm_PID=/var/run/php-fpm.pid

然后编辑 nginx 网页配置如下

server {
listen 80 default;
root /var/www/vhosts/yourdomain/;
index index.php;
access_log /var/log/webpage_access.log;
error_log /var/log/webpage_error.log;
# if the file is not physical there, loop trough web folder
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?q=$1 last;
}
# if the file is not imagecached, create one
location ~ /files/imagecache/ {
rewrite ^/(.*)$ /index.php?q=$1 last;
}
# just send a empty response if the favicon.ico is m.i.a
location = /favicon.ico {
try_files /favicon.ico =204;
}
# hide protected files
location ~*.(.htaccess|engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(.php)?|xtmpl)$ {
deny all;
}
# enable robots.txt
location = /robots.txt {}
# hide backup_migrate files
location ~* ^/files/backup_migrate {
deny all;
}
# Allow all files in this location to be downloaded
location ~ ^.*/files/.*$ {}
# setup the php-fpm pass-trough
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}

检查配置的完整性

service nginx configtest

如果一切正常:

service php-fpm start
service nginx start

应该是。在我的 Ubuntu 10.04 上运行良好

相关内容