2009年6月6日星期六

fedora10安装nginx并配置php

安装nginx
yum install nginx

安装php5
yum install lighttpd-fastcgi php-cli php-mysql php-gd php-imap php-ldap
php-odbc php-pear php-xml php-xmlrpc php-eaccelerator php-magickwand
php-magpierss php-mapserver php-mbstring php-mcrypt php-mhash php-mssql
php-shout php-snmp php-soap php-tidy

vi /etc/php.ini
添加
cgi.fix_pathinfo = 1
至文件末尾

vi /etc/rc.local
添加
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u nginx -g nginx -f /usr/bin/php-cgi -P /var/run/fastcgi-php.pid
至文件末尾
(这是配置FastCGI加入到默认启动)

配置nginx(以下都是修改 不是添加)
vi /etc/nginx/nginx.conf
(可选)
worker_processes 5;
keepalive_timeout 2;

(必选)
server {
listen 80;
server_name _;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}

error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1.sixxs.org;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}

重启nginx即可。
感觉apache对php的内置支持的确更好用一点

没有评论: