准备工作:
.更新第三方源和系统
安装centos第三方yum源(CentOS默认的标准源里没有nginx软件包)
#安装下载工具wget
yum install wget
#下载atomic yum源
wget http://www.atomicorp.com/installers/atomic
#安装
sh ./atomic
#更新yum软件包
yum check-update
#更新系统
yum update
############################################################################
准备篇
1、配置防火墙,开启80端口、3306端口vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT #允许80端口通过防火墙
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT #允许3306端口通过防火墙
备注:很多网友把这两条规则添加到防火墙配置的最后一行,导致防火墙启动失败,
正确的应该是添加到默认的22端口这条规则的下面
################################ 添加好之后防火墙规则如下所示###################
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
#最后重启防火墙使配置生效
/etc/init.d/iptables restart
2、关闭SELINUXvi /etc/selinux/config#SELINUX=enforcing #注释掉#SELINUXTYPE=targeted #注释掉SELINUX=disabled #增加:wq #保存退出shutdown -r now #重启系统
1. 安装nginx
[root@imysql ~]# rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
[root@imysql ~]# yum install -y nginx //安装nginx
[root@imysql ~]# chkconfig nginx on //nginx开机启动
2. 安装php 、php-fpm
[root@imysql ~]# rpm -ivh http://repo.webtatic.com/yum/el6/latest.rpm //安装php yum源包
[root@imysql ~]# yum install php php-cli php-curl php-fpm php-intl php-mcrypt php-mysqlnd php-gd php-mbstring php-xml php-dom
[root@imysql ~]# chkconfig php-fpm on //php-fpm开机启动
3、配置nginx
备份原配置文件cp /etc/nginx/nginx.conf /etc/nginx/nginx.confbak
去掉以下内容的#注释
[root@imysql ~]#
vi /etc/nginx/conf.d/default.conf
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;
}
修改 html$fastcgi_script_name 为 /usr/share/nginx/html$fastcgi_script_name
/usr/share/nginx/html 为网站目录
启动 Nginx 与 php-fpm 服务
[root@imysql ~]# service nginx start
[root@imysql ~]#
service php-fpm start
4、测试php是否支持
在 /usr/share/nginx/html 中新建 phpinfo.php 文件
[root@imysql ~]#
vi /usr/share/nginx/html/phpinfo.php
<?php
phpinfo();
?>
5、安装 MySQL:
[root@imysql ~]# yum install -y mysql mysql-server mysql-devel //安装
[root@imysql ~]# service mysqld start //启动
[root@imysql ~]# chkconfig mysqld on
[root@imysql ~]# mysqladmin -u root -p password "12345678" //设置密码
6、安装phpmyadmin
[root@imysql ~]# yum install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm (i386)
[root@imysql ~]# yum install -y phpmyadmin
[root@imysql ~]# vim /usr/share/phpmyadmin/config.inc.php
将里面的$cfg['blowfish_secret'] = ' '; 单引号里面随便写个数(空的会报错)
允许本机以外访问,修改如下:
[root@imysql ~]# vi /etc/httpd/conf.d/phpmyadmin.conf
将 Allow from 127.0.0.1 改成 Allow from all。
使用虚拟目录访问phpmyadmin
修改nginx配置文件
[root@imysql ~]#
mkdir /var/www/phpmyadmin //建立phpmyadmin目录
[root@imysql ~]# cp -a /usr/share/phpmyadmin/* /var/www/phpmyadmin //全部复制
[root@imysql ~]#
cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.confbak //备份配置文件
[root@imysql ~]#
vi /etc/nginx/conf.d/default.conf //修改配置文件,在
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.php index.html index.htm;
}
底部添加以下内容:
location /phpmyadmin {
alias /var/www/phpmyadmin;
index index.php;
}
location ~ /phpmyadmin/.+\.php$ {
if ($fastcgi_script_name ~ /phpmyadmin/(.+\.php.*)$) {
set $valid_fastcgi_script_name $1;
}
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/phpmyadmin/$valid_fastcgi_script_name;
}
[root@imysql ~]# service nginx restart //重启nginx
访问方式:http://ip/phpmyadmin
临时测试可以,正式使用还要做许多功课,有空再完善此文档。
参考配置:http://jingyan.baidu.com/article/5d368d1eed38ac3f60c05791.html