Undefined symbol when loading Apache2 mod_xml2enc - apache

I am so frustrated installing reverse-proxy-related modules to Apache2 HTTP server on a CentOS 5 box. Since it's an old version of Apache2 server, I had to compile the modules from source using Apache tool 'apxs'. I got no warnings or errors installing the module by 'apxs' but got runtime error when trying to restart the Apache server.
Starting httpd: httpd: Syntax error on line 206 of /etc/httpd/conf/httpd.conf: Cannot load /usr/lib64/httpd/modules/mod_xml2enc.so into server: /usr/lib64/httpd/modules/mod_xml2enc.so: undefined symbol: xmlDetectCharEncoding
[FAILED]
The following are more details.
OS: CentOS 5.11; Linux 2.6.18-400.1.1.el5 #1 SMP Thu Dec 18 00:59:53 EST 2014 x86_64 x86_64 x86_64 GNU/Linux
Apache: version 2.2.3
For historical reason, I cannot upgrade either of them to newer version to fix the issue.
The OS was originally lack of libxml2, which I installed by yum successfully with no issue. I downloaded the source files of mod_proxy_html including 1) mod_xml2enc.c, 2) mod_proxy_html.h and 3) mod_proxy_html.c
I used the following commands to at first install mod_xml2enc and then mod_proxy_html.
apxs -i -a -c -I /usr/include/libxml2/ mod_xml2enc.c
apxs -i -a -c -I /usr/include/libxml2/ -I ./ mod_proxy_html.c
Both seemed OK and showed some output like the following:
/usr/lib64/apr-1/build/libtool --silent --mode=compile gcc -prefer-pic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fno-strict-aliasing -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/include/httpd -I/usr/include/apr-1 -I/usr/include/apr-1 -I/usr/include/libxml2/ -c -o mod_xml2enc.lo mod_xml2enc.c && touch mod_xml2enc.slo
/usr/lib64/apr-1/build/libtool --silent --mode=link gcc -o mod_xml2enc.la -rpath /usr/lib64/httpd/modules -module -avoid-version mod_xml2enc.lo
/usr/lib64/httpd/build/instdso.sh SH_LIBTOOL='/usr/lib64/apr-1/build/libtool' mod_xml2enc.la /usr/lib64/httpd/modules
/usr/lib64/apr-1/build/libtool --mode=install cp mod_xml2enc.la /usr/lib64/httpd/modules/
cp .libs/mod_xml2enc.so /usr/lib64/httpd/modules/mod_xml2enc.so
cp .libs/mod_xml2enc.lai /usr/lib64/httpd/modules/mod_xml2enc.la
cp .libs/mod_xml2enc.a /usr/lib64/httpd/modules/mod_xml2enc.a
chmod 644 /usr/lib64/httpd/modules/mod_xml2enc.a
ranlib /usr/lib64/httpd/modules/mod_xml2enc.a
PATH="$PATH:/sbin" ldconfig -n /usr/lib64/httpd/modules
----------------------------------------------------------------------
Libraries have been installed in:
/usr/lib64/httpd/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
chmod 755 /usr/lib64/httpd/modules/mod_xml2enc.so
[activating module `xml2enc' in /etc/httpd/conf/httpd.conf]
However, when I tried to restart the server, the error message I put at the top was raised.
I've tried many ways to fix this issue, however, nothing worked. Maybe it's worth noting that I took the exact steps installing the same modules on a CentOS 5.11 32bit machine and got no problem at all. The only difference between these two machines is just one is 32-bit and the other is 64-bit.
Hope someone would know how to fix this issue.
Thanks a lot in advance.

I found the solution to this issue on my own. It is a stupid one. I forgot to load the libxml2 to the Apache server. After I added LoadFile /usr/lib64/libxml2.so, the error was gone.

Related

How to compile apache2 own module in dockerfile?

I want to compile my own Apache module when building my image, so i wrote the following Dockerfile.
FROM httpd:2.4.25
COPY conf/httpd.conf /usr/local/apache2/conf/httpd.conf
COPY modules/mod_example.c /usr/local/apache2/modules/mod_example.c
RUN apxs -i -a -c modules/mod_example.c
EXPOSE 80
But i get an error :
/usr/share/apr-1.0/build/libtool --silent --mode=compile x86_64-linux-gnu-gcc -std=gnu99 -prefer-pic -DLINUX -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/local/apache2/include -I/usr/include/apr-1.0 -I/usr/include/apr-1.0 -I/usr/include -c -o mod_example.lo mod_example.c && touch mod_example.slo
/usr/share/apr-1.0/build/libtool: line 1114: x86_64-linux-gnu-gcc: command not found
apxs:Error: Command failed with rc=65536
I tried apt-get install gcc or libtool it say it's unable to locate the package.
My goal is to compile the ".c" file in a ".so" file.
Installing gcc, or the build-deps of say libapr1, is all that's needed. You probably just have a problem with your unspecified attempt at adding the compiler from your dockerfile.
For referene, here's how the httpd layer adds the compiler:
https://github.com/docker-library/httpd/blob/master/2.4/Dockerfile
I needed to do an apt-get update then :
apt-get install build-essential libtool
Since the docker image is a prod image, it doesn't contain dev tools.

"OpenSSL version is too old" while compiling http 2.4.16 on MacOS 10.11

I encounter an error with OpenSSL while compiling http 2.4.16 on El Capitan 10.11.1.
It is looking for OpenSSL version >= 0.9.8a:
checking for OpenSSL... checking for user-provided OpenSSL base directory... none
checking for OpenSSL version >= 0.9.8a... FAILED
configure: WARNING: OpenSSL version is too old
The default OpenSSL version is 0.9.8zg:
$ openssl version
OpenSSL 0.9.8zg 14 July 2015
And finally here is a part of my compilation line:
./configure --prefix=/usr/local/MyWebserver/httpd-2.4.12 \
--enable-ssl \
--with-few-things… \
--disable-lots-of-things…
I don't want to install another openssl even with brew.
For me, the problem was solved by installing the package 'openssl-devel'.
None of the above solutions worked for me.
I resolved it by telling "configure" which open-ssl to use:
When doing ./configure, please add the following:
--with-ssl=/usr/local/Cellar/openssl/1.0.2r
whereas, 1.0.2r is your current version of openssl, usually installed by brew.
I prefer doing this method rather than messing about with the system files (i.e. don't like to link anything on /usr/... directories as it messes up with the system, especially Apple will always do an update to prevent you from doing this), therefore, the following command works:
./configure --enable-ssl --enable-so --prefix=/(Wherever you like to
install location) --with-included-apr --with-mpm=prefork
--with-ssl=/usr/local/Cellar/openssl/1.0.2r
For my installation to work, I also needed to download the apr and apr-util, unzip and place them onto the srclib folder before installing.
I hope this helps.
You don't necessarily need to copy things if you have a current version of OpenSSL installed (using Homebrew), creating a symlink is sufficient to ensure it is picked up by the configure command:
ln -s /usr/local/opt/openssl/include/openssl /usr/local/include
More details: https://medium.com/#timmykko/using-openssl-library-with-macos-sierra-7807cfd47892
I’ve found a way :
Copy the folder /usr/incude/openssl from a Yosemite (MacOS 10.10) to /usr/local/include/openssl on my computer (El Capitan MacOS 10.11).
Then compile apache by adding a flag to the compilation environment variables gcc and g++ : -I/usr/local/include
Here are all the variables that I use :
ARCH="-arch x86_64 -mmacosx-version-min=10.7"
LDFLAGS="-O3 $ARCH"
CFLAGS="-O3 -fno-common $ARCH"
CXXFLAGS="-O3 -fno-common $ARCH"
CC="gcc $ARCH -I/usr/local/include"
CXX="gcc $ARCH -I/usr/local/include"
CPP="gcc -E"
CXXCPP="g++ -E »
Actually, you just need to provide the headers.
Download the Openssl source code here, and then copy to /usr/local/include/ as below,
$ sudo cp -r include/openssl /usr/local/include/
then everything will work fine.
Edit:
The openssl being outdated was the result of not having the proper libraries install.
installing libssl via : sudo apt-get install libssl-dev
caused --enable-ssl to function without extra configuration

string.h:29:8: error: expected identifier

I'm trying to compile nginx with custom openssl »libressl« using this script: https://gist.github.com/Belphemur/3c022598919e6a1788fc
Everything works fine using libressl 2.1.1.
Problem is that libressl 2.1.1 has some security issues, which have been resolved by newer releases.
However I can't get the build to work with libressl 2.1.2 or libressl 2.1.3 (latest version).
The issue I get:
..
cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I /tmp/build/pcre-8.36 -I /tmp/build/libressl-2.1.2/.openssl/include -I objs \
-o objs/src/core/nginx.o \
src/core/nginx.c
In file included from /usr/include/string.h:635:0,
from /tmp/build/libressl-2.1.2/.openssl/include/string.h:6,
from src/os/unix/ngx_linux_config.h:27,
from src/core/ngx_config.h:26,
from src/core/nginx.c:8:
/tmp/build/libressl-2.1.2/.openssl/include/string.h:29:8: error: expected identifier or ‘(’ before ‘__extension__’
char * strndup(const char *str, size_t maxlen);
^
make[1]: *** [objs/src/core/nginx.o] Error 1
make[1]: Leaving directory `/tmp/build/nginx-1.7.9'
make: *** [build] Error 2
All done.
..
What's the problem & how to resolve it?
Thanks for helping.
I'm the creator of the script you use to build Nginx with LibreSSL.
It is now corrected, the previous way to build and use libressl doesn't work with previous version of the script. (Simply copying all the include and stripping the lib)
The script now install libressl in a set directory and give it to nginx, this way, all the include not needed to use the library (like this string.h) is not part of the building process of nginx.
strndup is provided in string.h. You don't need to provide it here:
/tmp/build/libressl-2.1.2/.openssl/include/string.h:29:8: error: expected identifier or ‘(’ before ‘__extension__’
char * strndup(const char *str, size_t maxlen);
I would delete the copy of string.h from the sources, and use the platform's supplied string.h for strndup.
As a matter of fact, I don't know where that string.h is coming from because its not present on my system (and I regularly build and use the latest OpenSSL):
$ find /usr/local/ssl/ -name string.h
$ find /usr/local/ssl/ -name *.h
/usr/local/ssl/include/openssl/rc4.h
/usr/local/ssl/include/openssl/crypto.h
/usr/local/ssl/include/openssl/ts.h
/usr/local/ssl/include/openssl/ecdsa.h
/usr/local/ssl/include/openssl/opensslconf.h
...
I'm trying to compile nginx with custom openssl »libressl« using this script: https://gist.github.com/Belphemur/3c022598919e6a1788fc
OK, this can be a pain as I've had to do similar with nginx (FIPS validated OpenSSL).
The easiest way to handle it is build OpenSSL from sources and install it into /usr/local/ssl. Then, grep nginx's files for -lcrypto and -lssl. When you find them, replace them with the static archive of OpenSSL:
change -lcrypto to /usr/local/ssl/lib/libcrypto.a
change -lssl to /usr/local/ssl/lib/libssl.a
And drop the -L related to OpenSSL.
This will ensure you use your version of OpenSSL at compile time and run time without the need for LD_PRELOAD and DYLD_LIBRARY_PATH tricks. It will just always work.

Install Danginx and REMOTE_ADDR shows server ip

I installed Danginx and when REMOTE_ADDR shows server ip instead of user ip.
I tryed use mod_remoteip (I have apache 2.4) but its shows me error.
apxs -cia mod_remoteip.c
/var/www/build/libtool --silent --mode=compile gcc -prefer-pic -DLINUX -D_REENTRANT-D_GNU_SOURCE -D_LARGEFILE64_SOURCE -g -O2 -pthread -I/usr/include/apache -I/usr/includ/apache -I/usr/include/apache -c -o mod_remoteip.lo mod_remoteip.c && touch mod_remoteip.slo
gcc: mod_remoteip.c: No such file or directory
gcc: no input files
apxs:Error: Command failed with rc=65536
After that I tryed to download this module and compile it, and than when I tryed enable httpd service it told me that I try enable build-in module.
What can I do for show real IP of users?
Thank you!

using homebrew apxs from homebrew apache httpd24 fails with libtool: compile: unable to infer tagged configuration

using homebrew apxs from homebrew apache httpd24 fails with libtool: compile: unable to infer tagged configuration
$ apxs -i -c -Wc,"-arch x86_64" -Wl,"-arch x86_64 " mod_uwsgi.c
/usr/share/apr-1/build-1/libtool --silent --mode=compile cc -prefer-pic -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK -I/usr/local/Cellar/httpd24/2.4.3/include/apache2 -I/usr/include/apr-1 -I/usr/include/apr-1 -arch x86_64 -c -o mod_uwsgi.lo mod_uwsgi.c && touch mod_uwsgi.slo
libtool: compile: unable to infer tagged configuration
libtool: compile: specify a tag with `--tag'
apxs:Error: Command failed with rc=65536
.
What environment must I export to have libtool not complain about tag?
after digging through the source I found that if LTFLAGS is set to --tag=cc things work.
$ LTFLAGS=--tag=cc apxs -i -c mod_uwsgi.c