准备工作
一、配置防火墙(iptables安装与配置)
1
、禁用/停止自带的firewalld服务
#停止firewalld服务 systemctl stop firewalld #禁用firewalld服务 systemctl mask firewalld
2、安装iptable iptable-service
#先检查是否安装了iptables
service iptables status
#安装iptables
yum install -y iptables
#升级iptables(安装的最新版本则不需要)
yum update iptables
#安装iptables-services
yum install iptables-services
3、设置现有规则
vim /etc/sysconfig/iptables
开启80端口、3306、22端口
-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
:wq保存退出,重新启动防火墙
service iptables restart
二、配置selinux
vi /etc/selinux/config
设置SELINUX = disabled //如没有就添加
#重启系统
shutdown -r now
三、安装第三方yum源
#安装下载工具 yum install wget #下载 wget http://www.atomicorp.com/installers/atomic #安装 sh ./atomic #更新yum源 yum check-update开始安装
一. 安装nginx
#删除系统自带的软件包 yum remove httpd* php* #安装nginx yum install -y nginx #设置nginx开机启动 chkconfig nginx on #启动nginx service nginx start
二. 安装PHP
- 检查当前安装的PHP包
yum list installed | grep php
如果有安装的PHP包,先删除他们, 如:yum remove php.x86_64 php-cli.x86_64 php-common.x86_64
- 配置安装包源:
# 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 [上面搜索到的包即可]
- 执行安装
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 #设置php-fpm开机启动 systemctl enable php-fpm #启动php-fpm systemctl restart php-fpm
注:如果想更换到php5.5或5.4版本, 直接把上面的56w换成55w或者54w就可以了三. 安装 MySQL
- 安装yum install mysql mysql-server(如果安装不成功,需要 下载mysql的repo源)
成功安装之后重启mysql服务(centos7以将mysql转为mariadb的安装了)
systemctl restart mariadb.service
2.为root账户设置密码
mysql_secure_installation
四. 配置nginx,php
1.配置nginxvi /etc/nginx/nginx.confserver { listen 80; server_name example.com; location / { root /usr/share/nginx/html/test/; try_files $uri $uri/ /index.php?$query_string; index index.php index.html index.htm; } error_page 404 /404.html; location = /404.html { root /usr/share/nginx/html/test/; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html/test/; } location ~ \.php$ { root /usr/share/nginx/html/test/; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
重启nginx
systemctl restart nginx.service
2.配置php-fpm
vi /etc/php-fpm.d/www.conf
修改user和groupuser = nginx` group = nginx
重启php-fpm服务
systemctl restart php-fpm.service
测试是否成功vi /usr/share/nginx/html/test/index.php<?phpphpinfo();?>curl 127.0.0.1 (查看是否配置成功)