good day

On a VPS Ubuntu server, the application is deployed (oracle-XE + PHP), running apache2. PHP communicates with the database via oci8.

All values ​​that return from the database to the page are returned in the form "?????????". Ie, all Cyrillic is unreadable. At the same time, static text on the page is reflected correctly.

At the same time, on another VPS server everything works fine. Obviously, where there is a difference in the configs, but so far I have not found where.

SELECT * FROM V$NLS_PARAMETERS NLS_LANGUAGE AMERICAN NLS_TERRITORY AMERICA NLS_CURRENCY $ NLS_ISO_CURRENCY AMERICA NLS_NUMERIC_CHARACTERS ., NLS_CALENDAR GREGORIAN NLS_DATE_FORMAT DD-MON-RR NLS_DATE_LANGUAGE AMERICAN NLS_CHARACTERSET AL32UTF8 NLS_SORT BINARY NLS_TIME_FORMAT HH.MI.SSXFF AM NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR NLS_DUAL_CURRENCY $ NLS_NCHAR_CHARACTERSET AL16UTF16 NLS_COMP BINARY NLS_LENGTH_SEMANTICS BYTE NLS_NCHAR_CONV_EXCP FALSE 

Also in all php scripts that return values, there is a line:

 header('Content-Type: application/json; charset=utf-8'); 

Also in apache2.conf I tried to add

 AddDefaultCharset Utf-8 

did not help.

.bashrc

 export ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe export ORACLE_SID=XE export NLS_LANG=`$ORACLE_HOME/bin/nls_lang.sh` export ORACLE_BASE=/u01/app/oracle export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH export PATH=$ORACLE_HOME/bin:$PATH NLS_LANG=AMERICAN_AMERICA.CL8MSWIN1251 LANG=en_US.C 

SELECT returns the Cyrillic text directly from the database correctly

  • Questions like orakl return when encoding does not understand. apache would give out abracadabra and not questions. My pearl barley scripts always explicitly set the environment variable NLS_LANG=RUSSIAN.AL32UTF8 before connecting to the database. php is unlikely to perform .bashrc. it is also possible to indicate directly in the code via putenv or somehow transfer it to the driver. - Mike
  • I had a recommendation: In the configuration file, you need to register the setting of database environment variables: SetEnv NLS_LANG AMERICAN_CIS.CL8MSWIN1251 Question: where to prescribe this line? I tried in php.ini, did not help - Vyacheslav Groshenkov
  • SetEnv is an apache directive. In the apache config or .htacess. It only looks a little strange to ask 1251 here, and in the encoding of Apache’s pages utf8 ... And AMERICAN_CIS, there should be no spaces - Mike
  • Yes, and write, if possible, in response, then I will redo it. - Mike
  • So far, nothing happened, I compared the settings of the two servers (on the first one it works, on the second one it doesn't) - I did not find the difference. Honestly, I do not understand where I should prescribe "SetEnv ...". As it is everywhere (for example, here: docs.oracle.com/cd/B19306_01/server.102/b14225/ch3globenv.htm ) is superficially described. In php code, it doesn’t cost anything to change, because the code on the two servers is the same. In my opinion, this is clearly configured in apache2 or php, but I still don’t understand what to do with it :( - Vyacheslav Groshenkov

1 answer 1

To set the encoding for the oracle client, the environment variables NLS_LANG , ORACLE_HOME and possibly LD_LIBRARY_PATH must be set correctly.

As it was found out after various experiments, oci8 php did not want to take in any environment variables specified in the apache config. It accepted them after they were added as export NLS_LANG=.... lines to the export NLS_LANG=.... file, which was loaded at the start of apache. For debian, it is in /etc/apache2/envvars , for gentoo in /etc/conf.d/apache2 . In other distributions, its mention can be found in /etc/init.d/apache2 or add the required lines directly to it.