Ubuntu 16.04源码编译安装Apache 2.4.25教程

发布时间:2022-04-22 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了Ubuntu 16.04源码编译安装Apache 2.4.25教程脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

本文为大家介绍了ubuntu 16.04码编译安装apache,供大家参考,具体内容如下

apache 安装指南:http://httpd.apache.org/docs/2.4/install.html

安装指南上面有详细的安装过程,这里我只说些注意事项

1.编译安装apache有些依赖环境必须安装,不然后面编译会报找不到相应多文件:

APR(Apache portable Run-time libraries,Apache可移植运行库)和APR-Util,apr介绍可以参见:http://www.cnblogs.com/iLumia/p/4214886.html 下载地址:http://apr.apache.org/

PCRE库 如果没有安装过pcre的话,请先下载:http://www.pcre.org
除此之外,还有些磁盘空间要求,C编译器,时间同步,PErl5 可以根据需要,自行调整即可。

2.接下来是详细安装步骤:
这里我习惯把源码放在/usr/local/src下面,根据自己习惯切换目录。

1).安装apr-1.5.2
切换到apr的源码目录

cd /usr/local/src/apr-1.5.2/

安装及编译

./configure --prefix=/usr/local/apache/apr
make -j4(根据自己脑核数×2来设定并行编译参数,提高编译速度)
sudo make install

2).安装apr-util-1.5.4

切换到apr-util的源码目录

cd /usr/local/src/apr-util-1.5.4/

安装及编译

./configure --prefix=/usr/local/apache/apr-util --wITh-apr=/usr/local/apache/apr
make -j4
make install

3).安装pcre-8.39

进入安装目录

cd /usr/local/src/pcre-8.39/

安装及编译

./configure --prefix=/usr/local/pcre
make -j4
make install

4.安装完依赖就可以安装apache了
进入apache源码目录

cd /usr/local/src/httpd-2.4.25/

安装及编译

需要用–with参数指定我们刚才安装的依赖包位置

./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre
make -j4
make install

到此,就完成了apache的源码安装,接下来我们为apache服务
添加启动脚本:

cp /usr/local/apache/bin/apachectl /etc/init.d/httpd

添加环境变量:

echo 'export PATH=$PATH:/usr/local/apache/bin' > /etc/profile.d/httpd.sh
chmod a+x /etc/profile.d/httpd.sh
source /etc/profile.d/httpd.sh

之后就可以多种方式管理httpd了,如果需要开机自启,将启动命令添加到/etc/rc.local 中即可。

sudo /usr/local/apache/bin/apachectl start

可能会报错说端口被占用,需要修改httpd.conf文件

sudo gedit /usr/local/apache/httpd/conf/httpd.conf

然后把ServerName行改成ServerName 127.0.0.1:80

把Listen 80行改成Listen 127.0.0.1:80

然后保存,启动apache服务.

service httpd start

注意:
如果启动服务时,报配置文件找不到,一种方法是,复制一份配置文件到相应路径,
或者你启动apache时,加-f 参数,指明配置文件绝对路径。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本宝典。

脚本宝典总结

以上是脚本宝典为你收集整理的Ubuntu 16.04源码编译安装Apache 2.4.25教程全部内容,希望文章能够帮你解决Ubuntu 16.04源码编译安装Apache 2.4.25教程所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:Ubuntu16.04