·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设问答 >> LNMP在CentOS 5下的配置

LNMP在CentOS 5下的配置

作者:佚名      网站建设问答编辑:admin      更新时间:2022-07-23

本文暂时做CernOS 5下LNMP的教程,因为CentOS 6目前安装使用的人不多,CentOS 6的改变较大,而且目前官方暂未给出CentOS 5升级到CentOS 6的教材。

一、系统准备

更新系统:

yum update

防火墙允许80端口通信,在/etc/sysconfig/iptables中加入:

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

重启iptables:

/etc/init.d/iptables restart

二、安装nginx

使用EPEL源来安装nginx,因为nginx没有在CentOS源中:

rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm

yum update

yum install nginx sudo

设置启动nginx并设置为开机启动服务:

/etc/init.d/nginx start

chkconfig --add nginx

chkconfig nginx on

给Web目录加入777权限和nginx用户执行权限:

chmod 777 /usr/share/nginx/html

chown -R nginx /usr/share/nginx/html/

三、安装PHP with FastCGI

yum install php-cli php spawn-fcgi wget

配置php-cgi启动服务项:

mkdir /Download

cd /Download

wget http://www.iopenv.com/download/563-php-fastcgi-rpm.sh

wget http://www.iopenv.com/download/562-init-php-fastcgi-rpm.sh

mv 563-php-fastcgi-rpm.sh /usr/bin/php-fastcgi

mv 562-init-php-fastcgi-rpm.sh /etc/init.d/php-fastcgi

chmod +x /etc/init.d/php-fastcgi

chkconfig --add php-fastcgi

chkconfig php-fastcgi on

四、配置虚拟主机

mkdir -p /usr/share/nginx/html/www.example.com

vi /etc/nginx/conf.d/virtual.conf

在其末尾增加,www.example.com为您的域名:

server {

listen 80;

server_name www.example.com;

location / {

root/usr/share/nginx/html/www.example.com;

index index.php index.html index.htm;

}

error_page 404 /404.html;

location = /404.html {

root/usr/share/nginx/html;

}

error_page500 502 503 504 /50x.html;

location = /50x.html {

root/usr/share/nginx/html;

}

location ~ \.php$ {

root html/www.example.com;

fastcgi_pass127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/www.example.com$fastcgi_script_name;

include fastcgi_params;

}

}

重新启动nginx:

/etc/init.d/nginx restart

五、安装MySQL Server

yum install mysql-server php-mysql

/etc/rc.d/init.d/mysqld start

chkconfig mysqld on

重启php:

/etc/init.d/php-fastcgi restart

*可选,除了php-mysql扩展外,如果想安装其他扩展,可以使用:

yum install php-*

六、管理LAMP服务使用

service nginx start

service php-fastcgi start

service mysqld start

*start可以替换服务对应的其他命令,比如stop。

这样LNMP在CentOS 5下的安装就完成了。

原文地址:http://www.iopenv.com/docs/lnmp-centos-5/