1.6 Apache2.4与php结合

2018-02-24 10:34:42来源:oschina作者:脑洞老湿_人点击

分享
1.6 Apache2.4与php结合
httpd主配置文件/usr/local/apache2.4/conf/httpd.conf
vim /usr/local/apache2.4/conf/httpd.conf //修改以下4个地方
ServerName
Require all denied
AddType application/x-httpd-php .php
DirectoryIndex index.html index.php
/usr/local/apache2.4/bin/apachectl -t //测试语法
/usr/local/apache2.4/bin/apachectl start //启动服务
netstat -lntp
curl localhost
vim /usr/local/apache2.4/htodcs/test.php //增加如下内容

<?php
echo 123;
?>


curl localhost/test.php


要想实现php的效果先编辑Apache测试文件!


[root@Dasoncheng ~]# vim /usr/local/apache2.4/conf/httpd.conf
……
ServerName www.app.com
……

AllowOverride none
Require all granted

……
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
……

DirectoryIndex index.html index.php

……

mark




这里插入Linux防火墙知识:
selinux //临时关闭 setenforce 0
selinux //永久关闭 vi /etc/selinux/config
centos7之前使用netfilter防火墙、
centos7开始使用firewalld防火墙
关闭firewalld开启netfilter方法:
systemctl stop firewalld
systemctl disable firewalld
yum install -y iptables-services
systemctl enable iptables
systemctl start iptables


##关于selinux:
##临时关闭:
[root@Dasoncheng ~]# getenforce
Enforcing
[root@Dasoncheng ~]# setenforce 0
[root@Dasoncheng ~]# getenforce
Permissive
##永久关闭:
[root@Dasoncheng ~]# vim /etc/selinux/config
[root@Dasoncheng ~]# grep -B2 -w '^SELINUX' /etc/selinux/config
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
##关于关闭firewalld开启netfilter:
[root@Dasoncheng ~]# systemctl stop firewalld
[root@Dasoncheng ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[root@Dasoncheng ~]# yum install -y iptables-services
[root@Dasoncheng ~]# systemctl enable iptables.service
Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service.
[root@Dasoncheng ~]# systemctl start iptables.service
[root@Dasoncheng ~]# iptables -F
[root@Dasoncheng ~]# iptables -nvL
Chain INPUT (policy ACCEPT 6 packets, 428 bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 4 packets, 448 bytes)
pkts bytes target prot opt in out source destination
[root@Dasoncheng ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[OK]


编辑好了httpd.conf之后,测试:


[root@Dasoncheng ~]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@Dasoncheng ~]# /usr/local/apache2.4/bin/apachectl graceful
[root@Dasoncheng ~]# ps aux |grep httpd
daemon223830.10.9 5403449520 ? Sl 10:13 0:00 /usr/local/apache2.4/bin/httpd -k start
daemon223840.10.9 5403449512 ? Sl 10:13 0:00 /usr/local/apache2.4/bin/httpd -k start
daemon223860.10.9 5403449508 ? Sl 10:13 0:00 /usr/local/apache2.4/bin/httpd -k start
root224680.00.0 112664 968 pts/0S+ 10:13 0:00 grep --color=auto httpd
root341650.01.2 253516 12792 ? Ss 03:56 0:02 /usr/local/apache2.4/bin/httpd -k start
[root@Dasoncheng ~]# netstat -lntp |grep httpd
tcp600 :::80 :::*LISTEN22383/httpd
[root@Dasoncheng ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
访问测试:

如果无法访问,从selinux、防火墙、端口等进行排查!


[root@Dasoncheng ~]# curl localhost

It works!


mark
mark

最新文章

123

最新摄影

闪念基因

微信扫一扫

第七城市微信公众平台