本文将指导你如何在CentOS/Red Hat (RHEL) 6.2/5.8下使用Yum来搭建LEMP WEB服务器。国内
LNMP (Linux, Nginx, MySQL, PHP) 服务器目前在国内大的企业如百度腾讯使用非常普遍,但是因为LNMP不易安装配置,难为了许多运维人员。在本安装中,我尽量使用yum安装而避免编译安装,有将有效减少安装过程的时间及复杂程序。
LEMP(或LNMP)高性能的WEB服务器在CentOS6.2/5.8下的Yum搭建流程
STEP1.切换到root用户
su - ## OR ## sudo -i
STEP2.安装必要的软件源
1. 安装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
2.配置Nginx 源
创建/etc/yum.repos.d/nginx.repo文件并写入以下内容
CentOS
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1
RedHat(RHEL)
[nginx] name=nginx repo baseurl=http://nginx.org/packages/rhel/$releasever/$basearch/ gpgcheck=0 enabled=1
STEP3.安装Nginx
yum --enablerepo=remi,remi-test install nginx
STEP4.安装PHP5.4.4&PHP-FPM
yum --enablerepo=remi,remi-test install php php-fpm php-common
STEP5.安装PHP5.4.4模块扩展(一些扩展可能无用,请自行去除)
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
/etc/init.d/httpd stop ## OR ## service httpd stop chkconfig httpd off
2. 启动Nginx
/etc/init.d/nginx start ## OR ## service nginx start
3. 启动PHP_FPM
/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作一个备份
cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf_bak
(2) 在default.conf 文件中,找到以下内容。
location / { root /usr/share/nginx/html; index index.html index.htm; }
修改为:
location / { root /usr/share/nginx/html; index index.html index.htm index.php; }
nginx默认的wwwroot文件夹为/usr/share/nginx/html,这里你可以修改为自己指定的目录
(3) 去除以下内容前的#号,并修改fastcgi_param所在行
#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; #}
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; }
评论