linux 安装apache

 
 

进入 apache 主页

Paste_Image.png

寻找 apache http server 项目

Paste_Image.png

进入 apache http server 项目主页

Paste_Image.png

寻找下载地址

Paste_Image.png

使用 wget 命令进行下载

http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.25.tar.bz2
wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.25.tar.bz2

下载完成


Paste_Image.png

解压

tar -jxvf ./httpd-2.4.25.tar.bz2

Paste_Image.png

进入解压目录


Paste_Image.png

运行 ./configure , 注意这里因为是源码包安装 , 因此需要手工指定安装路径

./configure --prefix=/usr/local/apache2

Paste_Image.png

出现报错

configure: 
checking for APR... no
configure: error: APR not found.  Please read the documentation.

出现报错 , 缺少 APR , 在 apache 官网下载 APR 并编译安装

进入apache官网


Paste_Image.png

进入APR项目主页


Paste_Image.png

找到下载地址并下载


Paste_Image.png

解压缩


Paste_Image.png

Paste_Image.png

运行 ./configure , 注意这里因为是源码包安装 , 因此需要手工指定安装路径

sudo ./configure --prefix=/usr/local/apr && make && sudo make install

Paste_Image.png

安装完成现在尝试重新编译 apache http server


Paste_Image.png
configure: 
checking for APR-util... no
configure: error: APR-util not found.  Please read the documentation.

发现又少了这个包 , 同理去 apache 官网下载


Paste_Image.png

下载完成 , 准备解压


Paste_Image.png

解压完成 , 进行编译

./configure --prefix=/usr/local/apr-util

Paste_Image.png

Applying apr-util hints file rules for x86_64-unknown-linux-gnu
checking for APR... no
configure: error: APR could not be located. Please use the --with-apr option.

提示没有找到 APR , 并提示让我们使用 --with-apr 来手动指定 APR 的目录
之前在安装 APR 的时候我们手动指定了 APR 的目录是 : /usr/local/apr
因此重新调整参数 , 重新编译 :

./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

Paste_Image.png
make && sudo make install

安装完成


Paste_Image.png

编译安装 apr-util 完成 , 重新返回去编译 apache http server , 同时需要加上 --with-apr 与 --with-apr-util 参数

./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util && make && sudo make install

Paste_Image.png

checking for pcre-config... false
configure: error: pcre-config for libpcre not found. 
PCRE is required and available from http://pcre.org/

发现又缺少一个依赖库 : PCRE
根据提示继续进行下载编译安装


根据提示进入官网


Paste_Image.png

进入下载地址


Paste_Image.png

找到最新的版本进行下载

ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre2-10.22.zip

Paste_Image.png

解压

unzip ./unzip pcre2-10.22.zip

Paste_Image.png

进入进行编译

./configure --prefix=/usr/local/pcre && make && sudo make install

Paste_Image.png

又返回重新编译 apache http server

./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre && make && sudo make install

有报错 :

configure: error: Did not find pcre-config script at /usr/local/pcre

既然提示没有找到这个配置文件 , 我们就到这个目录下面看看是不是真的没有这个配置文件


Paste_Image.png

可以看到 , 应该是因为我们编译安装的 pcre 版本较高 , 这里将配置文件改名为 prce2-config
既然我们都已经下载了高版本的 prce , 那就试试看看能不能编译成功呗
如果要正确编译的话 , 应该是要修改 configure 文件了
我们使用 vim 打开 configure 文件 , 对 pcre-config 这个字符串进行搜索
发现总共有6处 , 因为新版本的 pcre 修改了脚本的文件名 , 我们尝试在 configure 脚本中对文件名进行替换 , 但是一定要注意在修改之前要对文件进行备份

:%s/pcre-config/pcre2-config/

替换成功后 , 显示总共有6处被vim替换 , 保存退出 , 然后重新运行刚才的编译命令 :

./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre && make && sudo make install

Paste_Image.png

又提示找不到 pcre.h 这个文件

util_pcre.c:49:18: fatal error: pcre.h: No such file or directory
compilation terminated.
/home/sun/Desktop/apache2/httpd-2.4.25/build/rules.mk:206: recipe for target 'util_pcre.lo' failed
make[2]: *** [util_pcre.lo] Error 1
make[2]: Leaving directory '/home/sun/Desktop/apache2/httpd-2.4.25/server'
/home/sun/Desktop/apache2/httpd-2.4.25/build/rules.mk:75: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/sun/Desktop/apache2/httpd-2.4.25/server'
/home/sun/Desktop/apache2/httpd-2.4.25/build/rules.mk:75: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1

那就再看看呗


Paste_Image.png

终于我们在这个目录找到了类似 pcre.h 的文件 pcre2.h


我们可以根据这条报错 util_pcre.c:49:18: fatal error: pcre.h: No such file or directory 知道 , 报错是产生在 util_pcre.c 这个文件中的
我们在 apache http server 源码包的目录下对这个文件进行定位

find -name util_pcre.c

Paste_Image.png

对其进行编辑 : (当然记住修改之前备份)


Paste_Image.png

继续开始工作

./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre && make && sudo make install

Paste_Image.png

T_T 放弃了 ... 还是老老实实装个低版本的 pcre 好好做人吧...


回滚 :

  1. 恢复 configure
  2. 恢复 ./server/util_pcre.c
  3. 删除 pcre 安装目录 (由于是源码包安装 , 因此删除安装路径即可 , 轻松无污渍残留)
  4. 重新下载低版本 pcre , 进行编译安装
  5. 重新编译 apache http server

好 , 继续
这次没有下载 pcre2-xxx , 而是下载了 pcre-8.39.zip


Paste_Image.png

Paste_Image.png

继续编译我们的 apache http server

./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre && make && sudo make install

Paste_Image.png

成功了 , 启动一下试试

sudo /usr/local/apache2/

查看一下IP地址

ifconfig

Paste_Image.png


作者:王一航
链接:http://www.jianshu.com/p/3d441e514d3e
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值