centos7虚拟机中安装nginx+php+mysql

准备工作

一、配置防火墙(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

  1. 检查当前安装的PHP包
    yum list installed | grep php
     如果有安装的PHP包,先删除他们, 如:
    yum remove php.x86_64 php-cli.x86_64 php-common.x86_64
  2. 配置安装包源:
    # 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  [上面搜索到的包即可]
  3. 执行安装
    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
  4. 安装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

  1. 安装yum install mysql mysql-server(如果安装不成功,需要 下载mysql的repo源)

    成功安装之后重启mysql服务(centos7以将mysql转为mariadb的安装了)

    systemctl restart mariadb.service

  2.为root账户设置密码

    mysql_secure_installation

四. 配置nginx,php

1.配置nginx
vi /etc/nginx/nginx.conf
    server {
       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和group
   user = nginx`    
   group = nginx
   重启php-fpm服务
   systemctl restart php-fpm.service

测试是否成功
   vi /usr/share/nginx/html/test/index.php
   <?php
      phpinfo();
   ?>
   curl 127.0.0.1  (查看是否配置成功)





  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值