配置httpd支持PHP和httpd的默认虚拟主机
Posted 人间忽晚,山河以秋
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了配置httpd支持PHP和httpd的默认虚拟主机相关的知识,希望对你有一定的参考价值。
源码编译安装完成后,配置一些功能
看一下apache的目录的用处
一、配置httpd支持php
首先修改httpd的主配置文件
[root@shell ~]# vim /usr/local/apache2.4/conf/httpd.conf
修改下面四个地方
修改完成后,测试语法并且启动服务
[root@shell ~]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@shell ~]# /usr/local/apache2.4/bin/apachectl start
查看端口
[root@shell ~]# netstat -lnpt
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 1549/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2579/master
tcp6 0 0 :::3306 :::* LISTEN 31014/mysqld
tcp6 0 0 :::80 :::* LISTEN 17969/httpd
tcp6 0 0 :::22 :::* LISTEN 1549/sshd
tcp6 0 0 ::1:25 :::* LISTEN 2579/master
看一看默认的首页显示
[root@shell ~]# curl localhost
<html><body><h1>It works!</h1></body></html>
网页浏览是这样的
在添加PHP文件,测试一下PHP是否可以解析
[root@shell ~]# cd /usr/local/apache2.4/
[root@shell apache2.4]# ls
bin cgi-bin error icons lib man modules
build conf htdocs include logs manual
[root@shell apache2.4]# cd htdocs
[root@shell htdocs]# ls
index.html
[root@shell htdocs]# vim test.php # 编辑一个PHP的首页文件,使首页显示123
<?php
echo 123;
?>
~
~
~
~
~
"test.php" [New] 3L, 19C written
[root@shell htdocs]# curl localhost/test.php
123[root@shell htdocs]# curl localhost/test.php
123[root@shell htdocs
网页浏览
二、httpd的默认虚拟主机
1、修改http的主配置文件,找到关于虚拟主机的那一行,把注释去掉
[root@shell ~]# vim /usr/local/apache2.4/conf/httpd.conf
# 这一行注释去掉,可搜索httpd-vhost
Include conf/extra/httpd-vhosts.conf
2、修改虚拟主机配置文件,在配置文件里修改虚拟主机配置
[root@shell extra]# vim httpd-vhosts.conf
# Virtual Hosts
#
# Required modules: mod_log_config
# If you want to maintain multiple domains/hostnames on your
#
# for further details before you try to setup virtual hosts.
#
DocumentRoot "/usr/local/apache2.4/docs/dummy-host.exampl
DocumentRoot "/usr/local/apache2.4/docs/dummy-host2.examp
ServerAdmin webmaster@dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error_log"
# configuration.
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost conta
iner.
# The first VirtualHost section is used for all requests that
do not
# match a ServerName or ServerAlias in any <VirtualHost> bloc
k.
#### 根据下面的例子修改自己想要添加的虚拟主机
<VirtualHost *:80>
ServerAdmin admin@lflinux.com
DocumentRoot "/data/wwwroot/lf.com"
ServerName lf.com
ServerAlias www.lf.com
ErrorLog "logs/lf.com-error_log"
CustomLog "logs/lf.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/data/wwwroot/www.123.com"
ServerName www.123.com
</VirtualHost>
3、创建虚拟主机的数据目录,并且编辑虚拟主机的首页目录
[root@shell extra]# cd /data/wwwroot
[root@shell wwwroot]# mkdir lf.com
[root@shell wwwroot]# mkdir www.123.com
[root@shell extra]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@shell extra]# /usr/local/apache2.4/bin/apachectl graceful
[root@shell extra]# echo "lf.com">/data/wwwroot/lf.com/index.html
[root@shell extra]# echo "123.com">/data/wwwroot/www.123.com/index.html
4、查看
它会访问/data/wwwroot/lf.com/index.html
[root@shell wwwroot]# curl -x10.30.59.219:80 lf.com
lf.com
访问/data/wwwroot/www.123.com/index.html
[root@shell wwwroot]# curl -x10.30.59.219:80 www.123.com
123.com
它会访问/data/wwwroot/lf.com/index.html
[root@shell wwwroot]# curl -x10.30.59.219:80 www.abc.com lf.com
以上是关于配置httpd支持PHP和httpd的默认虚拟主机的主要内容,如果未能解决你的问题,请参考以下文章