php抓取网页域名(修改apache的配置文件,让apache可以使用php进行解析 )
优采云 发布时间: 2022-01-03 21:15php抓取网页域名(修改apache的配置文件,让apache可以使用php进行解析
)
修改apache配置文件,使php可以解析apache
httpd配置文件在/usr/local/httpd/conf/httpd.conf路径下
修改httpd配置文件中的以下配置参数,在httpd.conf配置文件中找到关键字符配置
[root@localhost httpd]# vim conf/httpd.conf
~
这里安装了两个php模块,需要注释掉一个php模块。因为httpd不能同时加载两个php模块
LoadModule php5_module modules/libphp5.so
#LoadModule php7_module modules/libphp7.so
将ServerName行的注释去掉,这样可以使httpd能够正常启动和访问默认页
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
ServerName www.example.com:80
修改默认的目录策略,denied表示拒绝访问网页目录,granted表示允许访问网页目录,防止打开虚拟主机配置会显示网页报错状态码403
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# blocks below.
#
AllowOverride none
Require all granted
网页根目录的配置路径及权限配置,Require all granted这里配置和上面的目录访问有关联的作用,表示网页目录是否能够有权限访问
DocumentRoot "/usr/local/httpd/htdocs"
Options Indexes FollowSymLinks
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
AllowOverride None
# Controls who can get stuff from this server.
Require all granted
添加php的解析主页,添加php的解析主页,在访问时才能对php页面正确识别
DirectoryIndex index.html index.php
添加php解析的配置项,httpd中必须添加解析配置项才能让httpd的php解析请求发送到php模块进行解析
# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
检查httpd配置文件是否正确,测试配置内容,这里是一个使用习惯,修改配置文件后,首先检查配置文件是否有错误,如果配置文件有错误,不检查就重启服务,会导致服务启动时出错,服务停止,从而导致服务停止提供对外界的访问。这将导致服务在短时间内无法访问。您需要检查配置文件并重新启动服务。使用graceful重新加载服务的配置。
[root@localhost httpd]# /usr/local/httpd/bin/apachectl -t
Syntax OK
[root@localhost httpd]# /usr/local/httpd/bin/apachectl graceful
[root@localhost httpd]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1085/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1388/master
tcp6 0 0 :::3306 :::* LISTEN 8759/mysqld
tcp6 0 0 :::80 :::* LISTEN 873/httpd
tcp6 0 0 :::22 :::* LISTEN 1085/sshd
tcp6 0 0 ::1:25
httpd php解析,在httpd网页目录下写一个php测试文件内容
[root@localhost httpd]# cat htdocs/index.php
一个php页面正确解析访问结果的例子:httpd加载php模块,返回网页的header信息。响应的服务器端解析器是 PHP/5.6.37
[root@localhost httpd]# curl -I 192.168.1.233/index.php
HTTP/1.1 200 OK
Date: Sun, 29 Jul 2018 09:22:59 GMT
Server: Apache/2.4.33 (Unix) PHP/5.6.37
X-Powered-By: PHP/5.6.37
Content-Type: text/html; charset=UTF-8
如果你写了一个php测试页却无法显示php测试页,需要检查以下几个方面:
php无法解析,首先检查是否有php模块,httpd配置文件中是否有php加载配置参数,是否写解析php的配置参数,是否指定首页的索引分析页面时测试
[root@localhost httpd]# /usr/local/httpd/bin/apachectl -M
Loaded Modules:
core_module (static)
so_module (static)
-----------------------------------略-------------------------
alias_module (shared)
php5_module (shared)
[root@localhost httpd]# cat conf/httpd.conf |grep php.*so
LoadModule php5_module modules/libphp5.so
[root@localhost httpd]# cat conf/httpd.conf |grep AddType
# AddType allows you to add to or override the MIME configuration
#AddType application/x-gzip .tgz
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
[root@localhost httpd]# cat conf/httpd.conf |grep index.php
DirectoryIndex index.html index.php