---
title: "RedHat5 yum搭建Linux+Nginx+PHP+MYSQL(LNMP)，3小时不到轻松搞定LNMP"
author: "bukebuhao"
date: "2012-06-02T16:26:40Z"
tags: []
categories: ["企业架构"]
slug: "redhat5-yum-linux-nginx-php-mysql-lnmp-3-lnmp"
draft: false
lastmod: "2012-06-02T17:01:58Z"
id: 1547260
url: "https://bukebuhao.iteye.com/blog/1547260"
---

## 特别声明: 本博客参考[centos](http://www.ppkj.net/2011/11/18/centos6-yum-%E6%90%AD%E5%BB%BAlinux-nginx-php-mysql-lnmp/) 设置,可参考对应的[csdn](http://blog.csdn.net/bukebuhao/article/details/7626231) 文章

最近要配置Linux服务器,RedHat5版本，如下操作配置，操作下来总共不超过3个小时搞定LNMP环境。Nginx1.2.0+PHP5.3.8(fastcgi)+Mysql5.5.24+eAccelerator(相关版本号是源软件包的最新版本)，使用Nginx官方源,Epel扩展库和remi源,remi源基于epel,必须先安装epel源,remi包含php-fpm,mysql-server5.5,如果只需要php-fpm可以单独安装php-fpm后禁用此源.

**服务器:**

       本服务器是x86\_64的，因此所有操作都是基于x86\_64,不是i386的，请特别注意。shell&gt;&gt; lsb\_release -a

**配置[yum](http://blog.csdn.net/linuxoostudy/article/details/7076420) :**

        解决redhat的[This system is not registered with RHN.](http://blog.csdn.net/linuxoostudy/article/details/7076420)

        基本思路就是卸载掉redhat原有的yum，安装centos的yum，其中主要使用rpm命令，就是卸载=rpm -qa | grep -i yum | xargs rpm -e --nodeps，下载wget URl,安装=rpm -ivh \*.rpm,配置yum，下载yum配置源，拷贝覆盖默认的/etc/yum.repos.d/， 运行yum makecache生成缓存。

**安装[Nginx](http://nginx.org/en/download.html "Nginx稳定版官方") 源:**

- 可采用直接下载安装测试

> ```
>  rpm -ivh http://nginx.org/packages/rhel/5/noarch/RPMS/nginx-release-rhel-5-0.el5.ngx.noarch.rpm






> ```

- 配置yum源安装，对应修改一下配置内容，利用yum install nginx安装测试。

**安装EPEL源:**

      ※  到[rpm网站](http://rpm.pbone.net/) 查找，如果想设定yum, 请参考[http://blog.csdn.net/kyn/article/details/4298175](http://blog.csdn.net/kyn/article/details/4298175)

> ```
> rpm -ivh 



ftp://ftp.muug.mb.ca/mirror/fedora/epel/5/x86_64/epel-release-5-4.noarch.rpm






> ```

**安装[REMI](http://rpms.famillecollet.com/ "REMI源") 源:**

        ※  同上

> ```
> rpm -ivh ftp://ftp.pbone.net/mirror/rpms.famillecollet.com/enterprise/5/remi/i386/remi-release-5-8.el5.remi.noarch.rpm










> ```

     开启REMI,编辑 /etc/yum.repos.d/remi.repo

> ```
> vi /etc/yum.repos.d/remi.repo


> ```
> 
> ```
> 修改 enable=1


> ```
> 
> ```
> esc


> ```
> 
> ```
> :wq


> ```

**yum安装:**

执行最主要的一步，可有针对性的选择安装项，不过最好是把原来存在的删除掉，全部安装

> ```
> yum -y install nginx mysql-server php-fpm php-cli php-pdo php-mysql php-mcrypt 
php-mbstring php-gd php-tidy 
php-xml php-xmlrpc php-pear php-pecl-memcache php-eaccelerator








> ```

**简略配置:**

1.根据需求配置 nginx配置文件，参考[详细配置](http://itsoul.iteye.com/blog/1545189)

vi /etc/nginx/config/default.conf

1. location ~ \\.php$ {
2. #root           html;
3. fastcgi\_pass   127.0 . 0.1 : 9000 ;
4. fastcgi\_index  index.php;
5. fastcgi\_param  SCRIPT\_FILENAME  /var/www/html$fastcgi\_script\_name;
6. include        fastcgi\_params;
7. }

把这些代码给注释开，/var/www/html是你存放php代码的地方；   
重启nginx,访问http://localhost/index.php，一切OK。

2.修改/etc/php-fpm.conf 用户组为nginx

    找到group选项设置为nginx，user默认为apache也修改为nginx吧

3.修改/var/lib/php/session(使php能保存session)，web用户组为nginx

> chown -R nginx:nginx /var/lib/php/session(不存在则需要创建)  
> chown -R nginx:nginx /var/www/(web目录)  
> chmod -R 775 /var/www/ (同组可修改权限,方便配置ftp,ftp应该加入到nginx组,如果需要更高的安全设置,则不应当将只读的目录赋予nginx,php组可写权限)  
> service nginx start(start|stop|restart|reload)  
> service php-fpm start(start|stop|restart)  
> service mysqld start(start|stop|restart|reload)  
> 设置自启动  
> chkconfig nginx on  
> chkconfig php-fpm on  
> chkconfig mysqld on