CentOS 5 VPS的nginx+php+mysql解决方案之二

Posted by zuzhihui in vps技术 on 2009/09/05 with No Comments

本文介绍在CentOS 5 VPS下的nginx php mysql的解决方案之二,本方案使用php-fpm作为fastcgi的进程管理器。

使用php-fpm就必须重新编译php,不能使用系统自带的php。我们的观点是尽量使用系统自带的,除非功能满足不了。本方案中MySQL是使用CentOS 5自带的,Nginx是我们自己编译的。

安装Nginx

centos系统不带nginx,我们用的Nginx是自己编译的,Nginx版本是最新稳定版本0.7.61,到 http://rashost.com/download 下载nginx,然后开始安装:

rpm -ivh nginx-0.7*.rpm
chkconfig --list nginx
chkconfig nginx on
/etc/init.d/nginx start
rpm -ql nginx

上面的rpm -ql nginx命令是看看nginx的文件都安装在哪些目录下面了,可以看到nginx的缺省网页目录应该是/usr/share/nginx/html/

通过浏览器访问,应该能看到nginx的缺省网页了,说明nginx正常工作了!

安装MySQL

我们使用CentOS自带的MySQL,安装命令:

yum install -y mysql-server
chkconfig --list mysqld
chkconfig mysqld on
/etc/init.d/mysqld start

运行mysql -uroot命令,应该可以正常连接到MySQL

安装php & php-fpm

先安装php & php-fpm所依赖的一些库文件:

yum install libmhash libmcrypt libtool-ltdl libpng libjpeg curl

然后到 http://dl.rashost.com 下载我们自己编译的php-fpm并安装:

cd /opt
tar zxf php-fpm-5.2.10*.tar.gz
/opt/php/sbin/php-fpm start

然后编辑/etc/rc.local,在其中加入/opt/sbin/php-fpm start

整合

首先在/usr/share/nginx/html目录下创建文件test.php,其内容很简单,只要下面一行:

<?phpinfo();?>

假设所在VPS的地址是centos5.rashost.com,这时通过浏览器访问http://centos5.rashost.com/test.php是得不到正确的显示结果的。

修改nginx的配置文件/etc/nginx/nginx.conf,在文件内搜索fastcgi_pass,修改该部分内容为:

      location ~ \.php$ {
root           html;
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
include        fastcgi_params;
}

然后重启nginx:

/etc/init.d/nginx/restart

然后在浏览器中访问test.php页面,就应该能正确显示了,reboot VPS测试一下,各个模块应该都能自带启动。大功告成!

标签:

Leave a Comment

Back to Top

2007-2017 © 北京瑞豪开源科技有限公司 京ICP备13004995号-2