配置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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值