PHP7 + Oracle — how to set encoding?

Available ubuntu 16.04 server. Installed instantclient 11.2.0.4.0 (basic, devel and sqlplus) from rpm using alien is OK (install from zip gives a similar result). The environment variables ORACLE_HOME, LD_LIBRARY_PATH and NLS_LANG spelled out in /etc/environment and /etc/profile, also created the file /etc/profile.d/oracle.sh and imported to ~/.profile. 7.0.8 installed PHP from the standard repository. The extension oci8 and pdo_oci successfully compiled and connected.
Code
try {
 $pdo = new PDO("oci:dbname=DEVELOP", "user", "passwd");
 echo "good connection with PDO";
} catch (Exception $e) {
 echo $e->getMessage();
}

quietly fulfills the connection passes.
But we need only add in the DSN encoding, that is, "oci:dbname=DEVELOP;charset=AL32UTF8" as here we catch the error in the form of "OCIEnvNlsCreate: Check the character set is valid and that PHP has access to Oracle libraries and NLS data". In this case the connectivity test using function oci_connect library oci8 works on "hurrah", even specifying encodings.

What has been done and not helped to overcome the above error:
  • prescribed environmental variables in the configuration file php7.0-fpm
  • environment variables in the startup file fpm-a, as suggest here
  • the owner of the /usr/lib/oracle/ put www-data:www-data
  • run php-fpm as root


P. S. As shown by the tests - are guilty of all that is php-fpm, because the run test script connecting to the CLI through the banal "php -f ./index.php" gives a positive result.

Need help.
July 2nd 19 at 17:33
2 answers
July 2nd 19 at 17:35
On the old version I don't remember such problem on a new install in cli everything is OK, and fpm no.
Tried everything, returned everything back then, and helped as it is written here
in the file /etc/php/5.6/fpm/pool.d/www.conf register (12.2 replace with your version)
env[LD_LIBRARY_PATH] = /usr/lib/oracle/12.2/client64/lib 
env[ORACLE_HOME] = /usr/lib/oracle/12.2/client64/lib
prescribed environmental variables in the configuration file php7.0-fpm

For 5.6 works for 7.0.8 fails to start. Now working in conjunction with Apache. There will be time, will try php 7.1 and 12 th customer, and can fly... - Blair_Litt commented on July 2nd 19 at 17:38
July 2nd 19 at 17:37
For the specified link contains a script to generate the current environment variables (environment) to the database.
As a good example of environment file for the database.

dbpilot.net/2018/01/30/generating-an-enviroment-fi...

...
This, of course, all very nice, but excuse me, why the heck is this here?.. - Blair_Litt commented on July 2nd 19 at 17:40

Find more questions by tags OraclePHP-FPMPHP