準(zhǔn)備工作
配置防火墻,開啟80端口撩独、3306端口
刪除原有的 iptables , 添加合適的配置
rm -rf /etc/sysconfig/iptables
vi /etc/sysconfig/iptables
添加如下內(nèi)容 :
################################ 添加好之后防火墻規(guī)則如下所示################################
# 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
#######################################################################################
:wq保存退出, 重啟防火墻使配置生效
/etc/init.d/iptables restart
關(guān)閉SELINUX
rm -rf? /etc/selinux/config
vi /etc/selinux/config
添加一行內(nèi)容:
SELINUX=disabled
:wq保存退出
#重啟系統(tǒng)
shutdown -r now
安裝第三方y(tǒng)um源
#安裝下載工具
yum install wget
#下載
wget http://www.atomicorp.com/installers/atomic
#安裝
sh ./atomic
#更新yum源
yum check-update
開始安裝
一. 安裝nginx
#刪除系統(tǒng)自帶的軟件包
yum remove httpd* php*
#安裝nginx
yum install -y nginx
#設(shè)置nginx開機啟動
chkconfig nginx on
#啟動nginx
service nginx start
二. 安裝PHP
檢查當(dāng)前安裝的PHP包
yum list installed | grep php
如果有安裝的PHP包拉庵,先刪除他們, 如:
yum remove php.x86_64 php-cli.x86_64 php-common.x86_64
配置安裝包源:
# Centos 5.X
rpm -Uvh http://mirror.webtatic.com/yum/el5/latest.rpm
# CentOs 6.x
rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
# CentOs 7.X
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
如果想刪除上面安裝的包冯键,重新安裝
rpm -qa | grep webstatic
rpm -e? [上面搜索到的包即可]
執(zhí)行安裝
yum -y install php56w.x86_64
yum -y --enablerepo=webtatic install php56w-devel
yum -y install php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64 php56w-opcache.x86_64
安裝PHP FPM
yum -y install php56w-fpm
#設(shè)置php-fpm開機啟動
chkconfig php-fpm on
#啟動php-fpm
/etc/init.d/php-fpm start
注:如果想更換到php5.5或5.4版本, 直接把上面的56w換成55w或者54w就可以了
三. 安裝 MySQL
安裝
yum install -y mysql mysql-server
#啟動MySQL
/etc/init.d/mysqld start
#設(shè)為開機啟動
chkconfig mysqld on
#拷貝配置文件(注意:如果/etc目錄下面默認有一個my.cnf乔询,直接覆蓋即可)
cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
為root賬戶設(shè)置密碼
mysql_secure_installation
# 回車屯吊,根據(jù)提示輸入Y,輸入2次密碼怔鳖,回車朴沿,根據(jù)提示一路輸入Y,最后出現(xiàn):Thanks for using MySQL!
#? MySql密碼設(shè)置完成败砂,重新啟動 MySQL:
#重啟
/etc/init.d/mysqld restart
#停止
/etc/init.d/mysqld stop
#啟動
/etc/init.d/mysqld start
配置
1. 配置nginx
rm -rf /etc/nginx/conf.d/*
vi /etc/nginx/conf.d/default.conf
添加如下內(nèi)容 :
server{
listen? ? ? 80;
server_name _;
index index.php index.html index.htm;
root? /var/www;
location ~ .*\.(php|php5)?$
{
#fastcgi_pass? unix:/tmp/php-cgi.sock;
fastcgi_pass? 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
}
說明: /var/www 為web根目錄, location / ... 為url的rewrite,隱藏 index.php
2. 配置php-fpm
vi /etc/php-fpm.d/www.conf
將用戶和用戶組設(shè)置為nginx, 如:
#修改用戶為nginx
user = nginx
#修改組為nginx
group = nginx
開始測試
cd /var/www
vi index.php
添加以下代碼
phpinfo();
?>
:wq! 保存退出
#設(shè)置權(quán)限
chown nginx.nginx /var/www -R
#重啟nginx
service nginx restart
#重啟php-fpm
service php-fpm restart