我们专注攀枝花网站设计 攀枝花网站制作 攀枝花网站建设
成都网站建设公司服务热线:400-028-6601

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

1.6Apache2.4与php结合

1.6 Apache2.4与php结合 httpd主配置文件/usr/local/apache2.4/conf/httpd.conf vim /usr/local/apache2.4/conf/httpd.conf //修改以下4个地方

成都创新互联专业为企业提供东方网站建设、东方做网站、东方网站设计、东方网站制作等企业网站建设、网页设计与制作、东方企业网站模板建站服务,10年东方做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

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 //增加如下内容

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 ……


这里插入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 daemon 22383 0.1 0.9 540344 9520 ? Sl 10:13 0:00 /usr/local/apache2.4/bin/httpd -k start daemon 22384 0.1 0.9 540344 9512 ? Sl 10:13 0:00 /usr/local/apache2.4/bin/httpd -k start daemon 22386 0.1 0.9 540344 9508 ? Sl 10:13 0:00 /usr/local/apache2.4/bin/httpd -k start root 22468 0.0 0.0 112664 968 pts/0 S+ 10:13 0:00 grep --color=auto httpd root 34165 0.0 1.2 253516 12792 ? Ss 03:56 0:02 /usr/local/apache2.4/bin/httpd -k start [root@Dasoncheng ~]# netstat -lntp |grep httpd tcp6 0 0 :::80 :::* LISTEN 22383/httpd [root@Dasoncheng ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT 访问测试:

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

[root@Dasoncheng ~]# curl localhost

It works!

1.7 Apache默认虚拟主机

先编辑wins的hosts文件:

域名访问:

编辑httpd.conf开启虚拟主机:

[root@Dasoncheng ~]# vim /usr/local/apache2.4/conf/httpd.conf ##编辑主配置文件,开启虚拟主机(开启之后,原站点就会失效!) [root@Dasoncheng ~]# grep -A1 \'Virtual hosts\' /usr/local/apache2.4/conf/httpd.conf # Virtual hosts Include conf/extra/httpd-vhosts.conf 编辑虚拟主机配置文件:

[root@Dasoncheng ~]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf # VirtualHost example: # Almost any Apache directive may go into a VirtualHost container. # The first VirtualHost section is used for all requests that do not # match a ServerName or ServerAlias in any block. # # ServerAdmin webmaster@dummy-host.example.com DocumentRoot "/data/wwwroot/abc.com" ServerName abc.com ServerAlias www.abc.com 123.com ErrorLog "logs/abc.com-error_log" CustomLog "logs/abc.com-access_log" common # ServerAdmin webmaster@dummy-host2.example.com DocumentRoot "/data/wwwroot/111.com" ServerName www.111.com ErrorLog "logs/111.com-error_log" CustomLog "logs/111.com-access_log" common 编辑index页面:

[root@Dasoncheng ~]# mkdir -p /data/wwwroot/abc.com/ [root@Dasoncheng ~]# cat /data/wwwroot/abc.com/index.php [root@Dasoncheng ~]# mkdir -p /data/wwwroot/111.com [root@Dasoncheng ~]# cat /data/wwwroot/111.com/index.php

小提示:开启了虚拟主机之后,原先的主配置站点就失效!
虚拟主机配置文件可以定义多个virtual host;每一个host代表一个站点!其中第一个host就变为了主站点,访问ip就是这个主机!

测试虚拟主机访问:

[root@Dasoncheng ~]# curl -x192.168.60.11:80 www.abc.com abc.com ##ServerAlias我就没有测试,下面也没有; [root@Dasoncheng ~]# curl -x192.168.60.11:80 www.111.com 111.com [root@Dasoncheng ~]# vim /etc/hosts [root@Dasoncheng ~]# tail -1 /etc/hosts 192.168.60.11 www.abc.com www.111.com [root@Dasoncheng ~]# curl www.abc.com abc.com [root@Dasoncheng ~]# curl www.111.com 111.com [root@Dasoncheng ~]# curl


当前名称:1.6Apache2.4与php结合
分享链接:http://mswzjz.cn/article/chooii.html

其他资讯