一、配置防火墙,开启80端口、3306端口

CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。

1、关闭firewall:

#停止firewall服务

  • systemctl stop firewalld.service
  • #禁止firewall开机启动

  • systemctl disable firewalld.service
  • 2、安装iptables防火墙

    #安装

  • yum install iptables-services
  • #编辑防火墙配置文件

  • vi /etc/sysconfig/iptables
  • # 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! #保存退出

     #最后重启防火墙使配置生效

  • systemctl restart iptables.service
  • #设置防火墙开机启动

  • systemctl enable iptables.service
  • 二、关闭SELINUX
    #修改配置文件

  • vi /etc/selinux/config

  • #SELINUX=enforcing #注释掉

    #SELINUXTYPE=targeted #注释掉

    SELINUX=disabled #增加

    :wq! #保存退出

    #使配置立即生效

  • setenforce 0

  • 三.安装apache

    1. yum install httpd

      可能会用到的:

      systemctl start httpd.service #启动apache

      systemctl stop httpd.service #停止apache

      systemctl restart httpd.service #重启apache

      systemctl enable httpd.service #设置apache开机启动

      restart一下,然后:
      输入localhost
      出现之后代表已经安装上去了。
    centOS 7配置Apache + MySQL + PHP

    四.安装mysql

    CentOS7的yum源中默认好像是没有mysql的。为了解决这个问题,我们要先下载mysql的repo源。

    1. 下载mysql的repo源

    # wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

     

    2. 安装mysql-community-release-el7-5.noarch.rpm包

    sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

    3. 安装mysql

    # yum install mysql-server

    4.启动

    # service mysqld restart

    5.停止

    # service mysqld stop

      到此处 MySql 已经安装成功 在本机是可以进去mysql了 接下来就需要设置权限了:

      1.1 进入mysql控制台

      1. mysql -u root -p mysql  //<span style="white-space: pre;">第一个</span>mysql是执行命令,第二个mysql是系统数据库 

          如果顺利进入mysql控制台,请跳到1.2步骤。

      1. update user set password=PASSWORD('123456') where user='root'; 
      2. flush privileges;//记得要执行这句话,否则如果关闭先前的终端,又出现原来的错误
      3. exit();

      1.2在mysql控制台下修改权限

           grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;  //root 是用户名,% 表示任意主机,'123456' 指定的登录密码(这个和本地的root密码可以设置不同,互不影响) 

     

    五.安装PHP

  • yum install php
  •    2.安装PHP组件,使PHP支持mysql

        yum install php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash

      3.重启对应服务

      1. systemctl restart mysqld.service
      2. systemctl restart httpd.service

     注意: 进入localhost页面 是找不到index.php页面 而现实403页面,关闭403显示的页面:

        vi /etc/httpd/conf.d/welcome.conf

        注解以下代码

        #<LocationMatch "^/+$">
        #    Options -Indexes
        #   ErrorDocument 403 /error/noindex.html
        #</LocationMatch>

    相关文章: