阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Linux下编译安装Apache httpd服务器

143次阅读
没有评论

共计 2742 个字符,预计需要花费 7 分钟才能阅读完成。

环境:Ubuntu 16.0.4

Apache 官网下载 Apache httpd 压缩包:httpd-2.4.27.tar.gz,安装之前请确定安装了 make 工具,我安装的是 GNU make

  1. 解压文件
    sudo tar -zxvf '/home/fanchao/ 桌面 /share/apache http server/httpd-2.4.27.tar.gz' -C /etc/httpd

    在解压后的文件目录下有个 install 文件,里面写着

    For complete installation documentation, see [ht]docs/manual/install.html or
    http://httpd.apache.org/docs/2.4/install.html
  2. 通过查看文档,安装所需要的环境:

安装 APR(其实不用安装,后面说明):下载 apr-1.6.2.tar.gz

解压:

sudo tar -zxvf '/home/fanchao/ 桌面 /share/apache http server/apr-1.6.2.tar.gz' -C /etc/httpd

  编译和安装:

sudo
cd /etc/httpd/apr-1.6.2 #进入解压后的文件目录 sudo ./configure #这里可以添加参数 --prefix= 你要安装的目录,我这里没有加,默认安装在 /user/loacl 目录下 以下所有的./configure 都可以添加这个参数 sudo make sudo make install

安装 APR-UTIL(其实不用安装,后面说明):下载 apr-util-1.6.0.tar.gz

解压:

sudo tar -zxvf '/home/fanchao/ 桌面 /share/apache http server/apr-util-1.6.0.tar.gz'  -C /etc/httpd

编译和安装

cd /etc/httpd/apr-util-1.6.0
sudo ./configure --with-apr=/usr/local/apr/bin/apr-1-config
sudo make

这里报错

xml/apr_xml.c:35:19: fatal error: expat.h: 没有那个文件或目录
compilation terminated.
/etc/httpd/apr-util-1.6.0/build/rules.mk:206: recipe for target 'xml/apr_xml.lo' failed
make[1]: *** [xml/apr_xml.lo] Error 1
make[1]: Leaving directory '/etc/httpd/apr-util-1.6.0'
/etc/httpd/apr-util-1.6.0/build/rules.mk:118: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1

解决办法就是安装 libexpat1-dev

sudo apt-get install libexpat1-dev

重新输

sudo make
sudo make install

  安装 httpd 所需要的 prce 库:下载 prce-8.41.zip

 解压:

sudo unzip   '/home/fanchao/ 桌面 /share/apache http server/pcre-8.41.zip' -d /etc/httpd

编译和安装:

cd /etc/httpd/pcre-8.41
sudo ./configure
sudo make 
sudo make install

最后编译安装 apache httpd

sudo ./configure --with-apr='/usr/local/apr/bin/apr-1-config' --with-apr-util='/usr/local/apr/bin/apu-1-config' --with-prce='/usr/local/bin/pcre-config' #这里还有其他参数可以配置,具体参照官方
sudo make
sudo make install

到现在按照官方文档的说明应该就已经安装好了,但是我到 make 这步就报错了

collect2: error: ld returned 1 exit status
Makefile:48: recipe for target 'htpasswd' failed
make[2]: *** [htpasswd] Error 1
make[2]: Leaving directory '/etc/httpd-2.4.27/support'
/etc/httpd-2.4.27/build/rules.mk:75: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/etc/httpd-2.4.27/support'
/etc/httpd-2.4.27/build/rules.mk:75: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1

我查了很多地方都没有遇到这个错误或者说这个错误是怎么发生的。这个错误是因为在 httpd 目录下的 srclib 目录里面没有 apr 和 apr-util 所导致的,但是./configure 又不会报错,到 make 才会报错,所以把下载下来到 apr 和 apr-util 解压到 srclib 目录下到 apr 和 apr-util 目录,注意目录名字要一致。

这就是我之前说的不用安装 apr 和 apr-util 的原因,它会自动安装,手动安装后去指定安装路径是会报错的。

重新生成 make 文件和 make

 sudo ./configure  --with-prce='/usr/local/bin/pcre-config' --with-included-apr #其他参数请参照官方
sudo make
sudo make install

现在就可以安装成功了,如果没有指定文件夹那么就会默认安装在  /usr/local/apache2

运行

sudo '/usr/local/apache2/bin/apachectl' -k start #启动
sudo '/usr/local/apache2/bin/apachectl' -k stop #停止 

完结。

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2017-08/146567.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计2742字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中