1.关闭防火墙
[root@CentOS ~]# chkconfig iptables off
2.关闭selinux
vi /etc/sysconfig/selinux
//将SELINUX=enforcing修改为disabled然后重启生效
3、配置CentOS 6.0 第三方yum源(CentOS默认的标准源里没有nginx软件包)
[root@CentOS ~]# yum install wget
//下载wget工具
[root@CentOS ~]# wget http://www.atomicorp.com/installers/atomic
//下载atomic yum源
[root@CentOS ~]# sh ./atomic
//安装提示输入时输yes
[root@CentOS ~]# yum check-update
//更新yum软件包
4.安装开发包和库文件
[root@CentOS ~]# yum -y install ntp make openssl openssl-devel pcre pcre-devel libpng
libpng-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel zlib zlib-devel
gcc gcc-c++ libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2
libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel
5.卸载已安装的apache、mysql、php
[root@CentOS ~]# yum remove httpd
[root@CentOS ~]# yum remove mysql
[root@CentOS ~]# yum remove php
6.安装nginx
[root@CentOS ~]# yum install nginx
原因:EPEL未被启动,且指示的 rpm包不可用
//如果安装nginx的时候出现上面情况做下面的操作
解决方法:
1.首先检查系统是否安装epel-release:
[root@flc ~]# rpm -q epel-release
package epel-release is not installed
2.如果没有安装,则install:
[root@flc ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm --force --nodeps
[root@flc ~]# rpm -q epel-release
epel-release-6-8.noarch
#查看其所依附的软件文件
[root@flc ~]# rpm -qR epel-release
/bin/sh
/bin/sh
config(epel-release) = 6-8
redhat-release >= 6
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(FileDigests) <= 4.6.0-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rpmlib(PayloadIsXz) <= 5.2-1
3导入key:
[root@flc ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
别忘了安装yum-priorities
[root@flc ~]#yum install yum-priorities
[root@flc ~]#cd /etc/yum.repos.d
[root@localhost yum.repos.d]# ls |grep epel
epel.repo
epel-testing.repo
然后安装nginx,即不报错:
[root@wmct-server yum.repos.d]# yum install nginx
[root@CentOS ~]# service nginx start
[root@CentOS ~]# chkconfig --levels 235 nginx on
//设2、3、5级别开机启动
7.安装mysql
[root@CentOS ~]# yum install mysql mysql-server mysql-devel
[root@CentOS ~]# service mysqld start
[root@CentOS ~]# chkconfig --levels 235 mysqld on
[root@CentOS ~]# mysqladmin -u root password "123456"
//为root用户设置密码
[root@CentOS ~]#mysql -uroot -p123456
//登录一下试试是否能进去
[root@CentOS ~]# service mysqld restart
//重启mysql
8.安装php
[root@CentOS ~]# yum install php lighttpd-fastcgi php-cli php-mysql php-gd php-imap php-ldap
php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mssql php-snmp php-soap
php-tidy php-common php-devel php-fpm
//安装php和所需组件使PHP支持MySQL、FastCGI模式
[root@CentOS ~]# service php-fpm start
[root@CentOS ~]# chkconfig --levels 235 php-fpm on
9.配置nginx支持php
[root@CentOS ~]# mv /etc/nginx/nginx.conf /etc/nginx/nginx.confbak
//将配置文件改为备份文件
[root@CentOS ~]# cp /etc/nginx/nginx.conf.default /etc/nginx/nginx.conf
//由于原配置文件要自己去写因此可以使用默认的配置文件作为配置文件
[root@CentOS ~]# vi /etc/nginx/nginx.conf //修改nginx配置文件,添加fastcgi支持
index index.php index.html index.htm; //加上index.php 43页-46页左右
location ~ .php$ { //65页-71页左右
root /usr/share/nginx/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;
}
//将以上代码注释去掉,并修改成nginx默认路径
10.配置php
//编辑文件php.ini,在文件末尾添加 cgi.fix_pathinfo = 1
[root@CentOS ~]# vi /etc/php.ini
11.重启nginx php-fpm
[root@CentOS ~]# service nginx restart
[root@CentOS ~]# service php-fpm restart
12.建立info.php文件
[root@CentOS ~]# vi /usr/share/nginx/html/info.php
<?php
phpinfo();
?>
13.测试nginx是否解析php
输入:IP地址或域名/info.php
显示php界面说明解析成功