centos7配置APache+PHP+mysql 下载本文

Centos7 配置apache+php+mysql 一.准备工作

1.先关闭firewall

Systemctl stop firewalld.service (7)之前是service firewalld stop 2.禁止firewall 开机启动

System disable firewalld.service 3.安装IPtables防火墙

yum install iptables-services 4.配置我们的IP防火墙 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

5.重新防火墙配置生效

Systemctl restart iptables.service Systemctl enable iptables.service 6.关闭selinux

修改配置文件

Vi /etc/selinux /config

注释掉#SELINUX=enforcing #SELINUXTYPE=targeted 添加SELINUX=disabled Wq存盘退出

Setenforce 0 使配置立即生效

二.安装APache Yum install httpd

安装完成后Apache是以HTTPD服务的形式存在的,我们要想把Apache先停止后启动并且设置为开启启动

Systemctl start httpd.service 启动

Systemctl enable httpd.service 开机启动 查看HTTP服务状态的话 Systemctl status httpd.service

注意:下面的httpd.conf这个文件的内容修改的时候要注意 1.做注释的是后最好在上一行或者下行用#做注释

2.做注释的时候千万不要在一个函数里面做标识比如:

AllowOverride none 这边就是不能做注释 Require all denied

下面我们来编辑下我们的httpd.conf

首先先vi /etc/httpd/conf/httpd.conf 会看见下面的配置文件(有些地方我已经做过了修改)

配置好我们的文件后,要测试下我们的这个文本的语法有没有错误: Apachectl configtest

然后,重新启动我们的HTTPd服务 Systemctl restart httpd

注意:我们在检查文本有没有错误的时候发现

我们就要重新去修该下我们的httpd这个服务

只要找到我们的ServerName localhost:80 将其改为localhost:80就ok 了 然后再重新启动下

Systemctl restart httpd.service

三.安装PHP Yum install php

安装完成后我们就要配置下面php.conf 10-php.conf 先配置下我们的php.conf Vi /etc/httpd/conf.d/php.conf #

# Cause the PHP interpreter to handle files with a .php extension.

#文件名与正则表达式相匹配的文件,将适用这里设定的语句

SetHandler application/x-httpd-php

#SetHandler强制所有的匹配的文件使用指定的hander进行处理 # Allow php to handle Multiviews

#设置扩展名为.php的档案类型为text/html AddType text/html .php #

# Add index.php to the list of files that will be served as directory # indexes.

#默认网页文档名添加index.php DirectoryIndex index.php

#

# SetHandler application/x-httpd-php-source # #

# Apache specific PHP configuration options # those can be override in each configured vhost #

php_value session.save_handler \

php_value session.save_path \