CentOS7下采用编译方式安装apache httpd
一、下载tar.gz文件
apache httpd官方网站链接:http://httpd.apache.org/download.cgi
Step1.下载httpd-2.4.46.tar.gz文件
Step2.利用Xftp软件,将httpd-2.4.46拷贝到Linux虚拟机中(我这里把它移动到虚拟机的/var目录下)
二、下载开发工具Development Tools
Step1.查看可用的软件包
yum grouplist
Step2.下载安装Development Tools
yum groupinstall "Development Tools"
三、解压httpd-2.4.46.tar.gz文件
Step1.解压tar.gz文件
tar zxvf httpd-2.4.46.tar.gz
zxvf是tar后面的参数。
.tar.gz是一个压缩包,.tar只是打包而没有压缩。
参数 | 解释 |
z | 通过gzip支持的压缩或解压缩。还有其他的压缩或解压缩方式,比如j表示bzip2的方式 |
x | 解压缩 |
v | 在压缩或解压缩过程中显示正在处理的文件名 |
f | f后面必须跟上要处理的文件名。 |
Step2.打开httpd-2.4.46目录
cd httpd-2.4.46/
四、检查相关包是否安装完全
./configure --prefix=/usr/local/httpd2.4.46
./表示在当前目录下执行命令
configure --prefix=/”的作用是:编译的时候用来指定程序存放路径
五、APR not found的解决方法
Step1.安装apr-devel
yum install apr-devel
Step2.安装apr-util-devel
yum install apr-util-devel
Step3.再次执行检查还有哪些包是缺少的
./configure --prefix=/usr/local/httpd2.4.46
看到上图所示的提示则表明相关环境和包已齐全,可以进行下一步。
六、编译
Step1.执行make命令
make
显示如上图所示的提示则表明编译成功。
Step2.执行make install命令,将刚刚编译好的文件安装到指定的目录中(/var/httpd-2.4.46/modules)
make install
显示如上图所示的提示则表明编译成功。
七、启动httpd服务
Step1.进入httpd目录
cd /usr/local/httpd2.4.46/
可以看到目录中已经有刚刚编译安装上去的一系列文件。
Step2.进入bin目录
cd bin/
Step3.启动apache httpd服务
/usr/local/httpd2.4.46/bin/apachectl -k start
报错一:
问题分析:因为用来演示的这台虚拟机本身已经安装了apache httpd服务并占用了80端口,因此执行/usr/local/httpd2.4.46/bin/apachectl -k start 命令时,该服务不能绑定到80端口。
解决方案:
Step1.关闭原有的httpd服务
systemctl stop httpd
Step2.启动httpd2.4.46
/usr/local/httpd2.4.46/bin/apachectl -k start
上图显示端口绑定的问题已经得到解决,测试页面如下图。
报错二、AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using fe80::6d5f:4494:d996:161a. Set the ‘ServerName’ directive globally to suppress this message
问题分析:ServerName被注释了,要取消注释。需要修改httpd.conf这个配置文件。
解决方案:
Step1.返回上级目录
cd ..
Step2.进入conf文件夹
cd conf/
Step3.备份httpd.conf文件,以免误操作
cp httpd.conf httpd.conf.bak
Step4.修改httpd.conf,取消ServerName的注释
vi httpd.conf
Step5.返回到bin目录,再次启动httpd服务
cd bin/
/usr/local/httpd2.4.46/bin/apachectl -k restart
至此可以发现,上文首次启动httpd服务时系统报的错已经得到解决。
八、拓展内容
8.1 httpd2.4.46默认网站目录
cd httpd2.4.46/htdocs/
8.2 查看历史执行过的命令
history