Error Cannot find OpenSSL’s [PHP Extension mysqlnd]

While installing mysqlnd PHP extension, and when the configure script is executed, I encountered the error – Cannot find OpenSSL <evp.h>

Below is the complete error message:

[root@terra-node-01 mysqlnd]# ./configure
[...]
checking for X509_free in -lcrypto... yes
checking for pkg-config... /bin/pkg-config
configure: error: Cannot find OpenSSL's <evp.h>

Solution: Cannot find OpenSSL <evp.h>

Step1: Search for evp.h

[root@terra-node-01 mysqlnd]# locate evp.h
/opt/at12.0/include/openssl/evp.h
/opt/at12.0/share/doc/openssl/html/man7/evp.html
/usr/include/openssl/evp.h

Step 2: Set PHP_OPENSSL_DIR environment variable

The configure script needs help figuring out where to look for it. Let’s see how  configure script is trying to look for that file. Open the configure file with the help of your favorite editor and navigate to the block shown below:

[root@terra-node-01 mysqlnd]# vim configure
[...]
for i in $PHP_OPENSSL_DIR; do
if test -r $i/include/openssl/evp.h; then
OPENSSL_INCDIR=$i/include
fi
if test -r $i/$PHP_LIBDIR/libssl.a -o -r $i/$PHP_LIBDIR/libssl.$SHLIB_SUFFIX_NAME; then
OPENSSL_LIBDIR=$i/$PHP_LIBDIR
fi
test -n "$OPENSSL_INCDIR" && test -n "$OPENSSL_LIBDIR" && break
done

if test -z "$OPENSSL_INCDIR"; then
as_fn_error $? "Cannot find OpenSSL's <evp.h>" "$LINENO" 5
fi

if test -z "$OPENSSL_LIBDIR"; then
as_fn_error $? "Cannot find OpenSSL's libraries" "$LINENO" 5
fi

old_CPPFLAGS=$CPPFLAGS
CPPFLAGS=-I$OPENSSL_INCDIR
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for OpenSSL version" >&5
$as_echo_n "checking for OpenSSL version... " >&6; }
[...]

If you observe the above code, configure uses variables such as PHP_OPENSSL_DIR to search for evp.h. If you echo the PHP_OPENSSL_DIR variable, you’ll see that it doesn’t contain /usr,which is where the evp.h is present and it should be looking at. So the solution is to simply define this variable as an environment variable, export it, and run configure again.

[root@terra-node-01 mysqlnd]# PHP_OPENSSL_DIR="/usr"
[root@terra-node-01 mysqlnd]# export PHP_OPENSSL_DIR
[root@terra-node-01 mysqlnd]# ./configure
[...]
checking for X509_free in -lcrypto... yes
checking for pkg-config... /bin/pkg-config
configure: error: Cannot find OpenSSL's libraries

Oh! no more evp.h error but encountered another error: Cannot find OpenSSL’s libraries. Using the same technique as above, let’s find out the path for OpenSSL libraries.

Step 3: Find OpenSSL library path

[root@terra-node-01 mysqlnd]# locate libssl.so
locate libssl.so
/opt/at12.0/lib64/libssl.so
/opt/at12.0/lib64/libssl.so.1.1
/opt/at12.0/lib64/power8/libssl.so
/opt/at12.0/lib64/power8/libssl.so.1.1
/opt/at12.0/lib64/power9/libssl.so
/opt/at12.0/lib64/power9/libssl.so.1.1
/usr/lib64/.libssl.so.1.0.2k.hmac
/usr/lib64/.libssl.so.10.hmac
/usr/lib64/libssl.so
/usr/lib64/libssl.so.1.0.2k
/usr/lib64/libssl.so.10

Step 3: Add the OpenSSL library path to PHP_OPENSSL_DIR

Add the OpenSSL libs path /usr/lib64 to PHP_OPENSSL_DIR environment variable.

[root@terra-node-01 mysqlnd]# PHP_OPENSSL_DIR="/usr /usr/lib64"
[root@terra-node-01 mysqlnd]# export PHP_OPENSSL_DIR

Unfortunately, it alone didn’t solve the problem. After analyzing the configure code, found that we need to set another environment variable called PHP_LIBDIR. But this variable isn’t read from the environment, but by arguments as seen from the below snippet of the configure code:

[root@terra-node-01 mysqlnd]# vim configure
[...]
# Check whether --with-libdir was given.
if test "${with_libdir+set}" = set; then :
withval=$with_libdir; PHP_LIBDIR=$withval

So added a new argument --with-libdir="" while running configure

[root@terra-node-01 mysqlnd]# ./configure --with-libdir=""
[...]
creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
config.status: config.h is unchanged

The configure script is now successfully completed, go ahead with the make and make install.

Updated on May 14, 2020

Was this article helpful?

Related Articles

Leave a Comment