So, what did we do to make openssl_pkey_new()
and all the other openssl_
functions in PHP work...
- Enabled the extension
php_openssl.dll
in the (right/active) php.ini
. Checked.
- Checked that there exists a
openssl.cnf
in xampp\apache\conf\
(and also in two other directories within XAMPP). Checked.
- Added the environment variable
OPENSSL_CONF
in the Windows system settings with the full path to the above openssl.cnf
. Checked.
- Restarted Apache (and after that did not work restarted the computer several times...). Checked.
Still does not work, and throwing errors such as
- error:0E06D06C:configuration file routines:NCONF_get_string:no value
- error:02001002:system library:fopen:No such file or directory
- error:2006D080:BIO routines:BIO_new_file:no such file
Okay, here are another two more things to check.
1. Trouble with the environment
Run phpinfo()
from a PHP script, and go to the "Apache Environment" section. Check the value of OPENSSL_CONF
.
Surprise. This is not what we have set in the windows system settings.
The solution is simple. Set the environment variable in the PHP script.
putenv('OPENSSL_CONF=C:\xampp\apache\conf\openssl.cnf');
2. Trouble with relative filenames
Now, openssl_pkey_new()
will work, but openssl_pkey_export_to_file()
does still not work and returns false
without any further explanation?
Check the filename that you have specified as output filename. It will not work in Windows as long as you do not specify the full path.
$folder = realpath('../keyring');
$outfile = $folder.'/private.pem';
openssl_pkey_export_to_file($key, $outfile);