您的位置:首页 > 运维架构 > Nginx

在CentOS上使用EPEL安装Nginx/PHP-FPM环境

2015-11-14 00:00 1306 查看
本文介绍如何在CentOS6.2 / 6.1 / 6 / 5.8上安装配置Nginx与PHP-FPM。

PHP-FPM是一个PHP FastCGI管理器,可以在 http://php-fpm.org/download下载。 href="http://www.nowamagic.net/academy/tag/PHP-FPM" target=_blank>PHP-FPM其实是PHP源代码的一个补丁,旨在将FastCGI进程管理整合进PHP包中。必须将它patch到你的PHP源代码中,在编译安装PHP后才可以使用。

现在我们可以在最新的PHP 5.3.2的源码树里下载得到直接整合了PHP-FPM的分支,据说下个版本会融合进PHP的主分支去。相对Spawn-FCGI,PHP-FPM在CPU和内存方面的控制都更胜一筹,而且前者很容易崩溃,必须用crontab进行监控,而PHP-FPM则没有这种烦恼。

PHP5.3.3已经集成php-fpm了,不再是第三方的包了。PHP-FPM提供了更好的PHP进程管理方式,可以有效控制内存和进程、可以平滑重载PHP配置,比spawn-fcgi具有更多有点,所以被PHP官方收录了。在./configure的时候带 –enable-fpm参数即可开启PHP-FPM。

Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。

1. 安装必要的软件源

CentOS 6.2/6.1/6/5.8 及 Red Hat (RHEL) 6.2/6.1//6/5.8下安装Remi

## Remi Dependency on CentOS 6 and Red Hat (RHEL) 6 ##
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-7.noarch.rpm ## CentOS 6 and Red Hat (RHEL) 6 ##
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm ## Remi Dependency on CentOS 5 and Red Hat (RHEL) 5 ##
rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm ## CentOS 5 and Red Hat (RHEL) 5 ##
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm

CentOS 6.2/6.1/6/5.8 及 Red Hat (RHEL) 6.2/6.1/6/5.8 下配置Nginx 源

创建/etc/yum.repos.d/nginx.repo文件并写入以下内容:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

2. 安装Nginx,PHP5.4.4&PHP-FPM

CentOS 6.2/5.8 及 Red Hat (RHEL) 6.2/5.8下

yum --enablerepo=remi,remi-test install nginx php php-fpm php-common

3. 安装PHP5.4.4模块扩展

APC (php-pecl-apc) – APC缓存优化中间件

CLI (php-cli) – PHP命令行插件

PEAR (php-pear) – PHP官方扩展

PDO (php-pdo) – 数据库PDO扩展

MySQL (php-mysql) –MYSQL驱动

PostgreSQL (php-pgsql) – PostgreSQL驱动

MongoDB (php-pecl-mongo) – PHP MongoDB驱动

SQLite (php-sqlite) – SQLite V2引擎及驱动

Memcache (php-pecl-memcache) – Memcache 驱动

Memcached (php-pecl-memcached) – Memcached 驱动

GD (php-gd) – GD图片类库扩展

XML (php-xml) –XML扩展

MBString (php-mbstring) –多字节字符串处理扩展

MCrypt (php-mcrypt) – MCrypt类库扩展

CentOS 6.2/5.8 and Red Hat (RHEL) 6.2/5.8下使用命令:

yum --enablerepo=remi,remi-test install php-pecl-apc php-cli php-pear php-pdo php-mysql php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml

4. 启动Nginx HTTP服务及PHP-FPM

停止httpd

/etc/init.d/httpd stop
## OR ##
service httpd stop

启动Nginx

/etc/init.d/nginx start
## OR ##
service nginx start

启动PHP_FPM

/etc/init.d/php-fpm start
## OR ##
service php-fpm start

5. 设置Nginx&PHP-FPM开机自启动(同时禁止Httpd自启动)

禁止Httpd自启动

chkconfig httpd off

设置Nginx&PHP-FPM开机自启动

chkconfig --add nginx
chkconfig --levels 235 nginx on
chkconfig --add php-fpm
chkconfig --levels 235 php-fpm on

现在打开浏览器输入http://localhost就可以看到nginx默认页面。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: