5 compiling dynamic-linking openssl apache-httpd
我正在从源代码编译 Apache,并静态链接mod_ssl
. 我希望使用与系统安装版本不同的 OpenSSL 版本。我希望以一种不影响系统其余部分(即 CentOS)的方式执行此操作,因为我希望不更改核心系统的 SSL 版本,该版本由其他已安装的软件使用,这些软件将继续由包管理器。
我怎样才能正确地做到这一点?
我尝试编译 Apache --with-ssl
,它可以很好地编译它,但在尝试运行它时却找不到它。
./httpd: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我想也许我可以LD_LIBRARY_PATH
在启动 Apache 时进行设置,效果很好,但不确定这是一个合适的方法。解决这个问题的推荐方法是什么?有没有更好的方法来添加替代库搜索路径的目录?
首先,您应该获取所需版本的OpenSSL并将其安装在不会干扰您的系统版本的位置,例如/opt
:
$ ./config \
--prefix=/opt/openssl-VERSION \
--openssldir=/opt/openssl-VERSION
$ make
$ sudo make install
Run Code Online (Sandbox Code Playgroud)
接下来,获取最新的Apache 2.4.x、APR 和 APR-Util库。您需要将所有三个包解压到同一源代码树中,后两个包位于 Apache 期望的位置。例如:
$ tar zxvf httpd-VERSION.tar.gz
$ cd httpd-VERSION/srclib/
$ tar zxvf ../../apr-VERSION.tar.gz
$ ln -s apr-VERSION/ apr
$ tar zxvf ../../apr-util-VERSION.tar.gz
$ ln -s apr-util-VERSION/ apr-util
Run Code Online (Sandbox Code Playgroud)
然后,配置并安装 Apache。该mod_ssl
模块将静态编译,所有其他模块将动态编译,如下所示:
$ ./configure \
--prefix=/opt/httpd \
--with-included-apr \
--enable-ssl \
--with-ssl=/opt/openssl-VERSION \
--enable-ssl-staticlib-deps \
--enable-mods-static=ssl
$ make
$ sudo make install
Run Code Online (Sandbox Code Playgroud)