Home > php教程 > php手册 > body text

RedHat5 yum搭建Linux+Nginx+PHP+MYSQL(LNMP),3小时不到轻松搞

WBOY
Release: 2016-06-06 20:00:19
Original
1023 people have browsed it

最近要配置Linux服务器,RedHat5版本,如下操作配置,操作下来总共不超过3个小时搞定LNMP环境。Nginx1.2.0PHP5.3.8(fastcgi)Mysql5.5.24eAccelerator(相关版本号是源软件包的最新版本),使用Nginx官方源,Epel扩展库和remi源,remi源基于epel,必须先安装epel源,

最近要配置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>>lsb_release -a

配置yum:

        解决redhat的This system is not registered with RHN.

        基本思路就是卸载掉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源:

  • 可采用直接下载安装测试
<span> rpm -ivh <span>http://nginx.org/packages/rhel/5/noarch/RPMS/nginx-release-rhel-5-0.el5.ngx.noarch.rpm
</span></span>
Copy after login

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

安装EPEL源:

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

<span>(<span>64位系统</span>) rpm -ivh <span>ftp://ftp.muug.mb.ca/mirror/fedora/epel/5/x86_64/epel-release-5-4.noarch.rpm</span></span>
Copy after login

安装REMI源:

       ※ 同上

<span>rpm -ivh <span>ftp://ftp.pbone.net/mirror/rpms.famillecollet.com/enterprise/5/remi/i386/remi-release-5-8.el5.remi.noarch.rpm</span></span>
Copy after login

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

<span>vi /etc/yum.repos.d/remi.repo
</span>
Copy after login
<span>修改 enable=1
</span>
Copy after login
<span>esc
</span>
Copy after login
<span>:wq</span>
Copy after login

yum安装:

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

<span></span>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
Copy after login
简略配置:


1.根据需求配置 nginx配置文件,参考详细配置

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template