|
原文:http://blog.iyunv.com/uuleaf/article/details/7736876
本文将指导你如何在CentOS/Red Hat (RHEL) 6.2/5.8下使用Yum来搭建LEMP WEB服务器。国内
LEMP (Linux, Nginx, MySQL, PHP) 服务器目前在国内大的企业如百度腾讯使用非常普遍,但是因为LEMP不易安装配置,难为了许多运维人员。在本安装中,我尽量使用yum安装而避免编译安装,有将有效减少安装过程的时间及复杂程序。
LEMP(或LNMP)高性能的WEB服务器在CentOS6.2/5.8下的Yum搭建流程
STEP1.切换到root用户
[plain] view
plaincopy
STEP2.安装必要的软件源
1. 安装Remi源
[plain] view
plaincopy
## 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
2.配置Nginx 源
创建/etc/yum.repos.d/nginx.repo文件并写入以下内容
CentOS
[plain] view
plaincopy
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
RedHat(RHEL)
[plain] view
plaincopy
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/rhel/$releasever/$basearch/
gpgcheck=0
enabled=1
STEP3.安装Nginx
[plain] view
plaincopy
yum --enablerepo=remi,remi-test install nginx
STEP4.安装PHP5.4.4&PHP-FPM
[plain] view
plaincopy
yum --enablerepo=remi,remi-test install php php-fpm php-common
STEP5.安装PHP5.4.4模块扩展(一些扩展可能无用,请自行去除)
[plain] view
plaincopy
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
STEP6.停止并禁用httpd服务,启动Nginx HTTP服务及PHP-FPM
1. 停止httpd
[plain] view
plaincopy
/etc/init.d/httpd stop
## OR ##
service httpd stop
chkconfig httpd off
2. 启动Nginx
[plain] view
plaincopy
/etc/init.d/nginx start
## OR ##
service nginx start
3. 启动PHP_FPM
[plain] view
plaincopy
/etc/init.d/php-fpm start
## OR ##
service php-fpm start
4. 配置nginx使用PHP-FPM,修改/etc/nginx/conf.d/default.conf
(1) 先为/etc/nginx/conf.d/default.conf作一个备份
[plain] view
plaincopy
cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf_bak
(2) 在default.conf 文件中,找到以下内容。
[plain] view
plaincopy
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
修改为:
[plain] view
plaincopy
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
nginx默认的wwwroot文件夹为/usr/share/nginx/html,这里你可以修改为自己指定的目录
(3) 去除以下内容前的#号,并修改fastcgi_param所在行
[plain] view
plaincopy
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME [将此处修改为wwwroot路径]$fastcgi_script_name;
# include fastcgi_params;
#}
修改结果
[plain] view
plaincopy
location ~ \.php$ {
root 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;
}
STEP7.配置iptables防火墙开启80端口
为Nginx Web Server开放80端口,修改/etc/sysconfig/iptables文件,加入如下内容
[plain] view
plaincopy
cd /etc/nginx/sites-enabled/
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
重启iptables防火墙
[plain] view
plaincopy
cd /etc/nginx/sites-enabled/
service iptables restart
## OR ##
/etc/init.d/iptables restart
STEP8.测试Nginx及PHP-FPM
1. 重启nginx及php-fpm
[plain] view
plaincopy
service nginx restart
service php-fpm restart
yum install php-fpm php-cli php-mysql php-gd php-pear php-xml php-xmlrpc php-magickwand php-mbstring php-mcrypt php-mssql php-shout php-snmp php-soap php-tidy php-zmq
php-twig php-process php-redis php-pecl-xhprof php-pecl-xdebug php-pecl-ssh2 php-pecl-rrd php-pecl-memcached php-pecl-memcache php-pecl-imagick php-pecl-apc
|
|