OCIEnvNlsCreate() failed - please check that ORACLE_HOME and > LD_LIBRARY_PATH - php

ubuntu 16.10 / nginx / php7.0 / oracle 11 xe
I'm trying to connect to the Oracle databas via PHP. And I get the following errors.
$conn = oci_connect('login', 'pass', 'localhost/xe');
Warning: oci_connect(): OCIEnvNlsCreate() failed. There is something
wrong with your system - please check that ORACLE_HOME and
LD_LIBRARY_PATH are set and point to the right directories in
/var/www/blah.php on line 26
Warning: oci_connect(): Error while trying to retrieve text for error
ORA-01804 in /var/www/blah.php on line 26
Really request variables, they will be empty. This code return empty string.
$test = getenv('LD_LIBRARY_PATH')." ".getenv('ORACLE_HOME');
print ("$test");
But in phpinfo() they are displayed.
I can write environment variables to each file, but this is not an option.
putenv("ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe");
putenv("LD_LIBRARY_PATH=-Wl,-rpath,/u01/app/oracle/product/11.2.0/xe/lib -L/u01/app/oracle/product/11.2.0/xe/lib -lclntsh");
What can I do?

I solved it by removing semicolon from the line ;clean_env=no in the file /etc/php-fpm.d/www.conf in case of php-fpm 5.6 in CentOS 6. Hope it will help in newer PHP versions. Remember to restart php-fpm service after making changes to this file.

We dont have the same infrastructure but I just solved this same issue in :
Apache
CentOS7
PHP 5
Oracle 12cR1
The message says :
please check that ORACLE_HOME and LD_LIBRARY_PATH are set and point to the right directories
In apache, there is a file where you can set the environment variable :
/etc/sysconfig/httpd. There has to be a config file for nginx.
I added the required environment variables.
Assuming that
ORACLE_HOME is /oracle/product/12.1.0/dbhome_1
Oracle client was installed under /oracle/product/12.1.0/client
Add :
ORACLE_HOME=/oracle/product/12.1.0/dbhome_1
LD_LIBRARY_PATH=/oracle/product/12.1.0/dbhome_1/lib:/oracle/product/12.1.0/dbhome_1/network/lib:/oracle/product/12.1.0/client/lib
I also added :
TNS_ADMIN=/oracle/product/12.1.0/dbhome_1/network/admin
ORACLE_SID=<your sid>
After updating /etc/sysconfig/httpd I just restarted Apache's service httpd and that was it:
$ sudo systemctl restart httpd
I hope it helps !

This is related to the incorrect NLS_LANG parameter. It was set to 'NA' in my case. The fix is:
Windows - The NLS_LANG must be unset in the Windows registry (re-named is best). Look for the NLS_LANG subkey in the registry at \HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE, and rename it.
Linux/UNIX - Here you simply issue the Linux command "unset NLS_LANG"

Related

Linux Oracle unix_odbc from PHP connection not working

I am running php v5 on RHEL using oracle client 19 (tnsnames.ora) I have odbcinst.ini and odbc.ini setup and is working from command prompt via:
isql -v myOdbc username pw
I had to specify LD_LIBRARY_PATH in order to get that to work. But now when I run test page in php and I try the odbc_connect command, it is giving me the following error: "Can't open lib '/var/opt/oracle/client2/lib/libsqora.so.19.1'" - which is the value that is in LD_LIBRARY_PATH
So it seems LD_LIBRARY_PATH isn't set correctly for Apache or PHP? If I do
php --info
That returns: _SERVER["LD_LIBRARY_PATH"] => /var/opt/oracle/client2/lib so PHP "seems" to know the LD_LIBRARY_PATH but somehow Apache or something else doesn't?
Here is odbcinst.ini
[ODBC]
Trace=Yes
TraceFile=/tmp/sql.log
ForceTrace=No
Pooling=No
UsageCount=2
[Oracle_ODBC_Driver_in_ora19c]
Description=Oracle 19c ODBC driver.
Driver=/var/opt/oracle/client2/lib/libsqora.so.19.1
Setup=
FileUsage=
CPTimeout=
CPReuse=
UsageCount=2
Here is odbc.ini
[myOdbc]
Description = wilson
Driver = Oracle_ODBC_Driver_in_ora19c
DSN = myDbCon.com
ServerName = myDbCon.com
Obviously /var/opt/oracle/client2/lib/libsqora.so.19.1 exists and is executable or isql wouldn't work, correct?
I have verified all are 64 bit architecture so I "think" I just need to know where/how to set LD_LIBRARY_PATH so when called from php it knows where the driver is?
Found the problem, if we added LD_LIBRARY_PATH and ORACLE_HOME to /etc/sysconfig/httpd then it worked!!! Hope this helps someone else!

PHP SNMP Warning: SNMP::get(): No response from 127.0.0.1

I'm trying to get PHP SNMP to work on XAMPP PHP 7.1.9
I'm always getting this result: Warning: SNMP::get(): No response from 127.0.0.1
Here's what I did:
Enabled php_snmp.dll on php.ini
Installed net-snmp-5.5.0-2.x64
Added windows environment variable MIBDIRS with value C:\usr\share\snmp\mibs
Code I'm running to test:
<?php
$session = new SNMP(SNMP::VERSION_1, "127.0.0.1", "public");
$sysdescr = $session->get("sysDescr.0");
echo "$sysdescr\n";
$session->close();
I'm new to this so I'm not sure what I'm missing.
The problem was with the MIBDIRS path.
I followed php docs and it says:
The Windows distribution of Net-SNMP contains support files for SNMP in the mibs directory. This directory should added to Windows' environment variables, as MIBDIRS, with the value being the full path to the mibs directory: e.g. c:\usr\mibs.
Problem was I couldn't find c:\usr\mibs on my net-snmp installation so I used C:\usr\share\snmp\mibs instead.
Solution:
I tried using a device with snmp support instead of 127.0.0.1 and ran snmpget on cli and confirmed net-snmp installation actually works. I figured the problem must be with the path php is using to run snmp.
So I used where snmpget to check the command path then changed MIBDIRS environment value with the result which is C:\usr\bin\snmpget.exe

oci_connect() works only from command line

OK, so I have this terrible problem with oci, apache, php and suse. First off, versions:
PHP 5.3.15 (cli)
Apache/2.2.22 (Linux/SUSE)
OCI8 1.4.9
SUSE 12.2 32 bit
Oracle client 10.2.0.4
Problem
I have really simple php file:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
oci_connect('user', 'passwd', 'host/sid');
?>
When I run it from command line it executes fine:
machine:~ # php oci.php
machine:~ #
But when i run it in browser, it gives me:
Warning: oci_connect() [function.oci-connect]: OCIEnvNlsCreate() failed. There is something wrong with your system - please check that ORACLE_HOME and LD_LIBRARY_PATH are set and point to the right directories
Apache configuration
I've been struggling with this issue for some time now and I'm pretty sure my apache configuration is correct.
I export all required variables before any apache process is started - I added
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/oracle/home/lib; export LD_LIBRARY_PATH
ORACLE_HOME=/path/to/oracle/home; export ORACLE_HOME
TNS_ADMIN=/path/to/oracle/home/network/admin; export TNS_ADMIN
NLS_LANG=POLISH_POLAND.EE8MSWIN1250; export NLS_LANG
at the beginning of /etc/init.d/apache2 script (I start apache by /etc/init.d/apache2 start).
Apache runs from wwwrun user, who is in oinstall and dba groups:
machine:~ # cat /etc/apache2/uid.conf
User wwwrun
Group www
machine:~ # id wwwrun
uid=30(wwwrun) gid=8(www) groups=8(www),113(oinstall),114(dba)
machine:~ # l $ORACLE_HOME
total 216
drwxr-xr-x 48 oracle oinstall 4096 Jan 25 17:07 ./
drwxrwxr-x 3 oracle oinstall 4096 Jan 25 17:01 ../
...
machine:~ #
Possible problem
I don't have any environmental variables in Environment section in phpinfo(); output - could this be the problem? If yes, how can I fix this? Is it some kind of security issue? I've read about problems like that with SELinux enabled, but I don't have it, my firewall is off.
Solution?
Any help would be greatly appreciated!
Problem solved! Thanks to these (Setting the Oracle Environment section) instructions and ken_yap's answer to this thread.
To put variables in Apache's Environment section you just have to add them in /etc/sysconfig/apache2 file: LD_LIBRARY_PATH=/path/to/oracle/lib.
Another solution ( that do not need root access ) is to add this lines in the php page:
putenv("ORACLE_HOME=/opt/app/oracle/product/11.2.0/db_1");
putenv("LD_LIBRARY_PATH=/opt/app/oracle/product/11.2.0/db_1/lib:/lib:/usr/lib");
Regards
For Debian users - edit file
/etc/apache2/envvars
on the end of file add link to your OCI library - eg.
export LD_LIBRARY_PATH=/opt/oracle/instantclient_12_2
Another approach for Centos 7 with nginx
$ sudo vim /etc/ld.so.conf.d/oracle-instantclient.conf
// Add path to oracle client lib, the XX is the version, ex: /usr/lib/oracle/XX/client64/lib
$ sudo ldconfig
$ sudo service php-fpm restart
Done!

$PATH environment variable for apache2 on mac

I am trying to get apache/php to recognize the path to my git. I have been researching and looking in all corners of the web and cannot find how to do this. Basically, no matter what I try, when I run echo phpinfo(); the Apache Environment path does not change from /usr/bin:/bin:/usr/sbin:/sbin. And when I run system('echo $PATH'); in PHP, it reads the same.
System Information:
Mac OSX (Lion)
Apache 2 (running as _www)
PHP 5.3.6
Here is what I have tried editing so far:
/etc/profile
~/.bash_profile
~/.profile
/etc/path
/etc/path.d/{NEW_FILE}
Nothing I have tried so far has changed the $PATH variable. Any ideas?
SOLUTION
So here is the final solution. I edited the
/System/Library/LaunchDaemons/org.apache.httpd.plist
and added
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin</string>
</dict>
You can set the PATH environment variable in /System/Library/LaunchDaemons/org.apache.httpd.plist.
More in the docs.
Did you update the PATH environment variable of user '_www'? Apache will read environment variables from the user runs itself. Or, it looks like you didn't restart apache after updating PATH environment variable.
Check out the older discussion :
How do I add paths to the Apache PATH variable?
Setting environment variables in OS X?
And if you want to modify environment variable in PHP, getenv() and putenv() can be a better choice.
getenv : http://php.net/manual/en/function.getenv.php
putenv : http://www.php.net/manual/en/function.putenv.php
$path = getenv('PATH');
putenv( "PATH=$path:/new_path_that_you_want_to_add" );
Important note for El Capitan (Apologies for the new answer - I don't have enough Rep to comment)
On OSX 10.11, the /System/Library folder is protected, so the files can't be edited.
You need to:
Reboot into Recovery Mode (hold CMD + r after the startup sound)
Once in recovery mode, go to Utilities > Terminal
Run:
csrutil disable
Reboot back into OSX - you should now be able to change the files
Once done, go back to recovery mode and run
csrutil enable
Hope that helps
I created this gist that helped me out from the information above:
https://gist.github.com/srayhunter/5208619
My problem was that PHP was not finding a program that we had installed under /usr/local/bin. Once we did the above it all worked and played nice on mac osx.
for ubuntu server, in /etc/apache2/envvars,
for centos server, in /etc/sysconfig/httpd,
to add:
export PATH=<your php cli path>
and restart apache
A similar problem to what I was having installing Derby. The way I solved it was by opening TextEdit. Select File > Open at this point press Shift + Command + . , this will allow you to view all the documents. Head to the user directory and search for a file called ".profile" . Open it and add the export VARIABLE= Value line for example:
export DERBY_HOME=/opt/local/share/java/derby/
Save the document and restart your terminal to see if the changes went into affect.

PHP Extension (memcache|memcached) not showing in phpinfo() but showing in php -m and php -i?

I am getting both modules listed as installed / configured when I use:
php -m
or if I use:
php -i
but when I use:
$m = new Memcache;
// or
$m = new Memcache();
// or
$m = new Memcached();
//or
$m = new Memcached;
I get the following error:
Fatal error: Class 'Memcached' not found
I am running on a Mac - OS X (10.5.7) with default install of apache & php. Additionally, I have memcached running as a daemon on 127.0.0.1:11211 and libmemcache as required by the php-memcached library. I have restarted apache tons of times and even done a machine restart.
Does anyone know why the modules/extensions show up in the command line but not in my phpinfo()? I am literally stumped, after 3 hours of googling, I am just about ready to give up.
Also, please note, my phpinfo() outputs my ini files as follows AND they are both the exact same file:
Configuration File (php.ini) Path: /etc
Loaded Configuration File: /private/etc/php.ini
UPDATE:
Apache is failing to load the extension.
[Fri May 14 04:22:26 2010] [warn]
Init: Session Cache is not configured
[hint: SSLSessionCache] PHP Warning:
PHP Startup: Unable to load dynamic
library
'/usr/lib/php/extensions/no-debug-non-zts-20060613/memcached.so'
- (null) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load
dynamic library
'/usr/lib/php/extensions/no-debug-non-zts-20060613/memcache.so'
- (null) in Unknown on line 0
Does anyone know why or how this would happen? Both of the files referenced above DEFINITELY ARE there. Should I move this question to server fault?
Your webserver is probably using mod_php, which is a seperate bit of code from the standalone (CLI) interpreter. If they are both using the same ini file, and the memcache extension is configured in the ini file, then it sounds like for some reason, the mod_php is failing to load the extension - check your webserver error_log for startup errors.
It may be that the mod_php was compiled without memcache support (most extensions need to have a stub file linked into the php code, even though the bulk of the code is not linked until run time). Or it may be a permissions problem on the shared object file. Or your webserver may be running chroot, and unable to find the extension (which would also mean that although the ini files appear to have the same path, this is relative to different roots).
HTH
C.
because both versions use different php.ini
place your php.ini into location noted in the phpinfo() outout
I would suspect that the issue revolves around permissions. When you run php from comand line, it runs as the user invoking it. When run as an apache module, it runs as "nobody".
I would assume that the memcached.so file, or the directory it's in does not have proper permissions.
I stumpled upon this post and was having the exact same problem with an extension in my php -i but not in phpinfo(). Mine was a permissions problem because of selinux on a CentOS machine. I had to change ownership and permissions and now it is working as expected.
Set php path in environment variables as given below.
Right-click on "My Computer"
Properties
Advanced Tab > Environment Variables
Under System variables, scroll down to find "Path", select and click on Edit.
Add path to your php install on the end (make sure to precede with semi-colon ";"). Example: ";C:\php7"
Click Ok.

Categories