目录
一、编译源码
1、解码
[root@localhost ~] tar -zxf httpd-2.4.54.tar.gz #解码
2、配置
[root@localhost ~] cd httpd-2.4.54/ #进入文件目录
[root@localhost httpd-2.4.54]# ./configure --prefix=/usr/local/apache #配置
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
configure:
configure: Configuring Apache Portable Runtime library...
configure:
checking for APR... no
configure: error: APR not found. Please read the documentation. #逐步解决依赖问题
[root@localhost httpd-2.4.54] yum -y install apr apr-util apr-util-devel #下载依赖
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* c7-media:
正在解决依赖关系
[root@localhost httpd-2.4.54] yum -y install gcc gcc-c++ #下载依赖
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* c7-media:
正在解决依赖关系
[root@localhost httpd-2.4.54] yum -y install pcre-devel zlib-devel #继续解决依赖
正在安装 : zlib-devel-1.2.7-18.el7.x86_64 1/2
正在安装 : pcre-devel-8.32-17.el7.x86_64 2/2
验证中 : pcre-devel-8.32-17.el7.x86_64 1/2
验证中 : zlib-devel-1.2.7-18.el7.x86_64 2/2
已安装:
pcre-devel.x86_64 0:8.32-17.el7 zlib-devel.x86_64 0:1.2.7-18.el7
完毕!
[root@localhost httpd-2.4.54] ./configure --prefix=/usr/local/apache #直到解析完成
已安装:
gcc.x86_64 0:4.8.5-44.el7 gcc-c++.x86_64 0:4.8.5-44.el7
Server Version: 2.4.54
Install prefix: /usr/local/apache
C compiler: gcc -std=gnu99
CFLAGS: -pthread
CPPFLAGS: -DLINUX -D_REENTRANT -D_GNU_SOURCE
LDFLAGS:
LIBS:
C preprocessor: gcc -E
3.编译、编译安装
[root@localhost httpd-2.4.54] make &&make install
mkdir /usr/local/apache/man/man8
mkdir /usr/local/apache/manual
make[1]: 离开目录“/root/httpd-2.4.54” #显示离开即可
二、配置文件
1.优化命令
[root@localhost ~] ln -s /usr/local/apache/bin/apachectl /usr/local/bin/apachectl
#方便使用命令
2.虚拟主机头
修改主配置文件
[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf
3. 主配置文件包含虚拟主机配置文件
基于不同IP地址
[root@localhost ~] vim /usr/local/apache/conf/extra/httpd-vhosts.conf
<VirtualHost 192.168.9.254:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/usr/local/apache/htdocs/skl1" #文件路径一定要对应,错了启动不了
# ServerName dummy-host.example.com
# ServerAlias www.dummy-host.example.com
ErrorLog "logs/9.254-error_log"
CustomLog "logs/9.254-access_log" common
</VirtualHost>
<VirtualHost 192.168.10.254:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/usr/local/apache/htdocs/skl2"
# ServerName dummy-host2.example.com
ErrorLog "logs/10.254-error_log"
CustomLog "logs/10.254-access_log" common
</VirtualHost>
[root@localhost ~] cd /usr/local/apache/htdocs/
[root@localhost htdocs] mkdir skl1
[root@localhost htdocs] mkdir skl2
[root@localhost htdocs] cp index.html skl1
[root@localhost htdocs] cp index.html skl2
[root@localhost htdocs] rm index.html
rm:是否删除普通文件 "index.html"?y
[root@localhost skl1] vim index.html #进去编写
[root@localhost skl1] apachectl start #启动服务
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
基于不同端口
修改配置文件
[root@localhost extra] vim httpd-vhosts.conf #修改包含虚拟机头主配置文件
<VirtualHost 192.168.9.254:8081> #修改
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/usr/local/apache/htdocs/skl1"
# ServerName dummy-host.example.com
# ServerAlias www.dummy-host.example.com
ErrorLog "logs/8081-error_log" #修改
CustomLog "logs/8081-access_log" common #修改
</VirtualHost>
<VirtualHost 192.168.10.254:8082>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/usr/local/apache/htdocs/skl2"
# ServerName dummy-host2.example.com
ErrorLog "logs/8082-error_log"
CustomLog "logs/8082.254-access_log" common
</VirtualHost>
[root@localhost conf] vim httpd.conf #修改主配置文件
#Listen 12.34.56.78:80
#Listen 80
Listen 192.168.9.254:8081 #修改
Listen 192.168.10.254:8082
[root@localhost conf]#apachectl stop #重启
[root@localhost conf] apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
基于不同域名(需要有域名解析:DNS服务)
[root@localhost conf] vim extra/httpd-vhosts.conf #同样修改包含虚拟机主配置文件
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/usr/local/apache/htdocs/skl1"
ServerName www.skl.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/skl1-error_log"
CustomLog "logs/skl1-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/usr/local/apache/htdocs/skl2"
ServerName dns.skl.com
ErrorLog "logs/skl-error_log"
[root@localhost conf] vim httpd.conf #修改主配置文件
Listen 80
#Listen 192.168.9.254:8081
#Listen 192.168.10.254:8082
[root@localhost conf] vim /etc/hosts
192.168.9.1 www.skl.com
192.168.10.1 dns.skl.com