手机版
你好,游客 登录 注册
背景:
阅读新闻

在CentOS 5.6 中安装 Nginx + PHP5 + MySQL

[日期:2011-07-28] 来源:imcn.me  作者:imcn [字体:大 中 小]
要开始一个PHP FastCGI的守护进程侦听端口 9000 localhost 上的用户和组运行nginx的,我们运行下面的命令 :
/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
当然,你不想在键入该命令时手动启动系统,使系统在开机时自动执行命令,打开/etc/rc.local:
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

配置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;
#}

# 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的:

/etc/init.d/nginx restart
创建一个探针文件:info.php,看看那些模块正常运行了
vi /usr/share/nginx/html/info.php
内容如下:

<?php
phpinfo();
?>

把双引号改为英文半角输入的单引号。
然后浏览器输入:http://192.168.0.100/info.php查看运行结果:

继续往下浏览,看看MYSQL运行情况:

相关软件连接:

linux
相关资讯       CentOS 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款