I try to set up connection with oracle database, but I still can't even set up the module. I have rhel 7. 2 server, and I followed whole tutorial for setting up oracle instantclient and configured it with php. One thing I completely don't understand is that oci8 module displays after php -i execution:
oci8
OCI8 Support => enabled
OCI8 DTrace Support => disabled
OCI8 Version => 2.1.3
Revision => $Id: 59f993160cf983dd24bb391b68a65a17303d2dba $
Oracle Run-time Client Library Version => 12.1.0.2.0
Oracle Compile-time Instant Client Version => 12.1
Directive => Local Value => Master Value
oci8.connection_class => no value => no value
oci8.default_prefetch => 100 => 100
oci8.events => Off => Off
oci8.max_persistent => -1 => -1
oci8.old_oci_close_semantics => Off => Off
oci8.persistent_timeout => -1 => -1
oci8.ping_interval => 60 => 60
oci8.privileged_connect => Off => Off
oci8.statement_cache_size => 20 => 20
But there is no such module in phpinfo() inside the script. How to fix it?
PHP Version 7.0.13
Server Apache (httpd)
LD library path:
[![enter image description here][2]][2]
The common problem would be that LD_LIBRARY_PATH isn't set for Apache.
Try adding it to /etc/sysconfig/httpd like:
LD_LIBRARY_PATH=/full/path/to/oracle-client
If I have my versions right, this version of Apache (i) doesn't like the export keyword for setting variables (ii) requires a full path since it won't expand environment variables. If I'm wrong, try either or both of those.
There is a lot of information about setting the environment in the free Underground Oracle & PHP Manual, see, for example 'Setting Oracle Environment Variables for Apache' on p 108
You say you followed 'whole tutorial'. There are many tutorials. I'd recommend Oracle's installation instructions.
The answer is:
setsebool -P allow_execstack 1
You also can enable executable stack for only oci8.so with:
execstack -c /usr/lib64/php/modules/oci8.so
https://serverfault.com/questions/314336/centos-6-php-can-not-load-gdchart-so-and-oci8-so-compiled-by-me
make sure that the oci8.so is in the php extension folder
in centos is /usr/lib64/php/modules
in ubuntu xammp is /opt/lampp/lib/php/extensions/no-debug-non-zts-20170718
cd <extension folder >
sudo chmod 755 oci8.so
It works for me after
ps ax | grep "fpm"
check the pid of "php-fpm: master process"
sudo kill -9 <pid>
start php-fpm again
sudo service php-fpm start
inspired by https://stackoverflow.com/a/21693610/2538630
Related
I followed the steps to download oracle instant client and add it to PATH, add php extensions and enable it in php.ini. The basic information listed as follows:
OS: Windows 10 Enterprise x64
PHP: 7.3.30 (cli) (built: Aug 25 2021 09:48:17) ( ZTS MSVC15 (Visual C++ 2017) x64 )
Oracle instant client: instantclient-basic-windows.x64-12.1.0.2.0
php extension for oracle database: php_oci8-2.2.0-7.3-ts-vc15-x64
After all configuration done, I test the oracle connection with following code:
$conn = oci_connect("testuser", "testpassword", "testtns;
if (!$conn) {
$m = oci_error();
echo $m['message'], "\n";
exit;
}
else {
print "Connected to Oracle!";
}
// Close the Oracle connection
oci_close($conn);
The web page shows positive result: Connected to Oracle!
Then the problem comes: When I run the same code in command line environment, it shows:
<warning>PHP Warning: oci_connect(): OCIEnvNlsCreate() failed. There is something wrong with your system - please check that PATH includes the directory with Oracle Instant Client libraries in Psy Shell code on line 1</warning>
Here is some PHP configruation info:
$ php --ri oci8
oci8
OCI8 Support => enabled
OCI8 DTrace Support => disabled
OCI8 Version => 2.2.0
Oracle Run-time Client Library Version => 0.0.0.0.0
Oracle Compile-time Instant Client Version => 12.1
Directive => Local Value => Master Value
oci8.max_persistent => -1 => -1
oci8.persistent_timeout => -1 => -1
oci8.ping_interval => 60 => 60
oci8.privileged_connect => Off => Off
oci8.statement_cache_size => 20 => 20
oci8.default_prefetch => 100 => 100
oci8.old_oci_close_semantics => Off => Off
oci8.connection_class => no value => no value
oci8.events => Off => Off
Statistics =>
Active Persistent Connections => 0
Active Connections => 0
One obvious deviation is "Oracle Run-time Client Library Version => 0.0.0.0.0"
I tried the suggestion searched from google:
copy all contents of instantclient to Apache/bin directory and remove instantclient directory from PATH
But, it doesnot work.
This problem costs me almost 2 days time, but still not solved.
Make sure the path to Oracle Instant Client libraries is specified in the PATH environment variable.
If you're not sure try run where oci.dll from a command line. If it could not find the file, then it is not in the PATH.
I'm trying to enable extenion oci8
I uncommented its line in php.ini and added the required files for it ( oracle instant client).
Now from CMD, when I type: php --ri oci8, it shows :
oci8
OCI8 Support => enabled OCI8 DTrace Support => disabled OCI8 Version
=> 2.1.8 Revision => $Id: 4543974aab26d8a3d85257ab18d0dca4503ff9e7 $ Oracle Run-time Client Library Version => 12.1.0.2.0 Oracle
Compile-time Instant Client Version => 12.1
Directive => Local Value => Master Value oci8.max_persistent => -1 =>
-1 oci8.persistent_timeout => -1 => -1 oci8.ping_interval => 60 => 60 oci8.privileged_connect => Off => Off oci8.statement_cache_size => 20
=> 20 oci8.default_prefetch => 100 => 100 oci8.old_oci_close_semantics => Off => Off oci8.connection_class => no value => no value oci8.events => Off => Off
Statistics => Active Persistent Connections => 0 Active Connections =>
0
So it should working fine.
But when I try to connect to oracle from php I get error :
Call to undefined function Yajra\Pdo\oci_connect()
I opened to PHPINFO page, searched for oci8, the block that must be present to show it's enabled is not present.
What may be the problem?
I'm using xampp 7.2 on windows 10
Solved.
It was that my PC required restart not just Apache for PHP web to load the new enviroment variables, which is important in locating oracle instant client, which is needed by the PHP extension OCI8.
The strange thing is that PHP CLI loaded the new enviroment variables, but the PHP web didn't load it although Apache is restarted.
I noticed that from PHPinfo page, which displays the loaded envirmonment variables showing the old ones before adding oracle.
So just restated my PC and everything is now OK.
Thanks for your advice.
You must edit the php.ini file which is shown in phpinfo ("Loaded Configuration File ") option and apache restart is also required for it to work.
I am getting this error when I start my xampp server.
C:\xampp\php\ext\php_oci8.dll' - %1 is not a valid Win32 application.
I downloaded php_oci8-2.0.8-5.6-ts-vc11-x86 and extracted php_oci8.dll into C:\xampp\php\ext directory.
Also, I downloaded instantclient-basic-nt-12.1.0.2.0 (32 bit version) and added the same to the PATH variable of windows.
C:\OracleBasicClient\instantclient-basic-nt-12.1.0.2.0\instantclient_12_1 added to PATH
Still, I'm getting this error and not sure why it is coming.
My windows is 64 bit.
PHP info (xampp)
System Windows NT 6.1 (Windows 7 Professional) i586
Compiler MSVC11 (Visual C++ 2012)
Architecture x86
Thread Safety enabled
What am I possibly doing wrong and how can I fix it?
Your error shows a built-type mismatch.
Resolve it by following these steps:
Make sure you download and install oracle instantclient at: http://www.oracle.com/technetwork/topics/winsoft-085727.html, but note:
Take note of your Oracle database version; use Version 12.1.x for Oracle database 12c and Version 11.1.x for 11g releases.
In either case, make sure you download the Basic Lite version of the Oracle instantclient.
After that, do add location of your Oracle instantclient to your System variable Path under your Environment Variables. Do equally ensure that you have both the PHP of your xampp and its ext available and set there as well (if not, do add them).
Then, proceed to add a new System variable with TNS_ADMIN as variable name and the location to Oracle instantclient as variable value.
Also, define your User variables PATH with the same the location to Oracle instantclient as value.
After this stage, restart your computer for a full propagation of the newly defined environment variables.
Once on, you may open your Windows Command Prompt and run where oci* to ensure that you had your environment variables well defined; the response should look like this:
C:\Users\flex>where oci*
C:\oraclexe\app\oracle\product\11.2.0\server\bin\oci.dll
C:\oraclexe\app\oracle\product\11.2.0\server\bin\ocijdbc11.dll
C:\oraclexe\app\oracle\product\11.2.0\server\bin\ocijdbc11.sym
C:\oraclexe\app\oracle\product\11.2.0\server\bin\ociw32.dll
C:\instantclient_11_2\oci.dll
C:\instantclient_11_2\oci.sym
C:\instantclient_11_2\ocijdbc11.dll
C:\instantclient_11_2\ocijdbc11.sym
C:\instantclient_11_2\ociw32.dll
C:\instantclient_11_2\ociw32.sym
If not, your must have missed something and need to revisit the process, ensuring to completing it effectively.
You may now proceed to your php.ini file (provided environment variables are well defined) and enable your oci extensions (php_oci8.dll and php_oci8_11g.dll) by uncommenting them; you can achieve that by simply removing the semi column (;) before the said extensions.
Do remember to save your php.ini file, then, restart or start your apache if it isn't already running.
To check your PHP oci8 configurations are enabled, you may go back to your Windows Command Prompt and run: php --ri oci8; the response should be similar to the one below:
C:\Users\flex>php --ri oci8
OCI8 Support => enabled
OCI8 DTrace Support => disabled
OCI8 Version => 2.1.1
Revision => $Id: 86f22a208f89dcd5b305e82929a7429683968b11 $
Oracle Run-time Client Library Version => 11.2.0.4.0
Oracle Compile-time Instant Client Version => 10.2
Directive => Local Value => Master Value
oci8.max_persistent => -1 => -1
oci8.persistent_timeout => -1 => -1
oci8.ping_interval => 60 => 60
oci8.privileged_connect => Off => Off
oci8.statement_cache_size => 20 => 20
oci8.default_prefetch => 100 => 100
oci8.old_oci_close_semantics => Off => Off
oci8.events => Off => Off
Statistics =>
Active Persistent Connections => 0
Active Connections => 0
Alternatively, you can create a PHP file with <?php phpinfo(); ?> as content, then open it in your browser and search for oci8 occurrences; it should show enabled there as well.
It seems that you downloaded the DLL for a different architecture and pointed to it in your php.ini, instead of using the bundled DLL and simply un-commenting the default entry in php.ini.
I just downloaded the same version, XAMPP 3.2.2 x86, with PHP 7.1, and it ships with the DLL file that you need, which is installed to C:\xampp\php\ext\php_oci8_12c.dll.
You appear to have done everything else correctly.
To fix the issue, ensure that the effective php.ini (by default, C:\xampp\php\php.ini) references only the default file (remove the erroneous entry you added for php_oci8.dll), like so:
extension=php_oci8_12c.dll ; Use with Oracle Database 12c Instant Client
Restart Apache and the problem should be resolved.
I have a simple php script:
<?php
$db_user = 'myusername';
$db_pass = 'mypassword';
$db_sid = 'mysid';
$conn = oci_connect( $db_user, $db_pass, $db_sid );
?>
When I run it (from a browser or from the command line), I get the error:
Call to undefined function oci_connect
I'm using php 5.6.6 which came with php_oci8_12c.dll already there.
I have extension=php_oci8_12c.dll in my php.ini
I have installed instant client (12.1) - tried 32 bit version AND 64 bit version
I have ORACLE_HOME and TNS_ADMIN environment variables pointing at the instant client folder ( C:\instantclient_12_1 ).
I also have C:\instantclient_12_1 in my path
I have a tnsnames.ora in that same folder with this relevant entry in it:
MYSID =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = myhost.net)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = MYSERVICE)
)
)
I have also downloaded SQLDeveloper from http://www.oracle.com/technetwork/developer-tools/sql-developer/downloads/index.html
SQLDeveloper works, recognizes the above mentioned tnsnames.ora and connects and successfully runs a query on the same database that my php script is trying to access.
I have spent several hours over several days trying different things to no avail.
I'm using:
php 5.6.6
windows 8.1
IIS (so no answers involving apache please)
cmd (run as administrator)
Oracle Database 11g Enterprise Edition 11.2.0.3.0
Some other information that might prove useful:
I would ideally like to use oci 1.4.10 to match the production server, but not too worried about that for now.
pear install oci8-1.4.10.tgz
gives me this error:
The DSP oci8.dsp does not exist
I can't find any explanation on that error that means anything to me.
What am I missing - can anyone help me
EDIT:
I have tried the various suggestions in other posts on stackoverflow, namely:
extension=oci8.so with and without extension=php_oci8_12c.dll
I don't have the line extension=php_oracle.dll in my php.ini file
EDIT:
phpinfo tells me that I am using the correct php.ini file:
Loaded Configuration File => C:\php5.6.6\php.ini
This line from phpinfo might also be of use:
Configure Command => cscript /nologo configure.js "--enable-snapshot-build" "--enable-debug-pack" "--disable-zts" "--disable-isapi" "--disable-nsapi" "--without-mssql" "--without-pdo-mssql" "--without-pi3web" "--with-pdo-oci=c:\php-sdk\oracle\x86\instantclient_12_1\sdk,shared" "--with-oci8-12c=c:\php-sdk\oracle\x86\instantclient_12_1\sdk,shared" "--with-enchant=shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet=shared" "--with-mcrypt=static" "--without-analyzer" "--with-pgo"
EDIT:
It seems that dsp files are VC++ project files - I am now venturing on learning how to create a php extension, and hopefully when I've done that I'll have enough knowledge to compile the oci8 1.4.10 source code into a dll that works on windows 8 - unless somebody rescues me with the answer to this question - this looks like it is going to take me some time :-)
EDIT:
Adding display_startup_errors = On to php.ini tells me that the oci dll is not a valid Win32 application
Edit: Hmm. Trying this on Windows 8 appears to generate the same error as you specified. I'm currently investigating...
My mistake (I had enabled the wrong extension_dir line). It works in Win8 just as documented below.
The following steps should be all you need to get OCI working with PHP (I've just verified this on a freshly installed Windows 2008 R2 Standard x64 virtual machine):
Download and extract PHP (I used C:\php from php-5.6.7-nts-Win32-VC11-x86.zip).
Download and extract InstantClient (I used C:\instantclient_12_1 from instantclient-basic-nt-12.1.0.2.0.zip).
Add the above paths to the system path.
Copy c:\php\php.ini-production to c:\php\php.ini.
in php.ini:
enabled line extension_dir = "ext".
enabled line extension=php_oci8_12c.dll.
Install Microsoft Visual C++ 2010 Runtime (x86). This is needed for the OCI8 extension.
Install Microsoft Visual C++ 2012 Runtime (x86). This is needed for PHP.
At this point running php --ri oci8 in a command prompt shows me the following output:
C:\>php --ri oci8
oci8
OCI8 Support => enabled
OCI8 DTrace Support => disabled
OCI8 Version => 2.0.9
Revision => $Id: f5a3ee1083d1ffa6adb5143efda6eafa210b8414 $
Oracle Run-time Client Library Version => 12.1.0.2.0
Oracle Compile-time Instant Client Version => 12.1
Directive => Local Value => Master Value
oci8.max_persistent => -1 => -1
oci8.persistent_timeout => -1 => -1
oci8.ping_interval => 60 => 60
oci8.privileged_connect => Off => Off
oci8.statement_cache_size => 20 => 20
oci8.default_prefetch => 100 => 100
oci8.old_oci_close_semantics => Off => Off
oci8.connection_class => no value => no value
oci8.events => Off => Off
Statistics =>
Active Persistent Connections => 0
Active Connections => 0
And checking for the oci_connect function:
C:\>php -r "var_dump(function_exists('oci_connect'));"
bool(true)
In addition to what was said to fix the problem, I would like to add the php CLI side of things, as some people need to run OCI-enabled applications in CLI mode. In my case, I had to copy an instance of oci.dll into the wamp/bin/php/php<version>/ folder for php --ri oci8 to show that oci8 was correctly loaded. That doesn't prove that other files were not needed to correctly run a full-fledged application (see my technical footnote).
Including the path to the instantclient 12 distribution wouldn't do it.
Technical notes:
My environment being: Windows 7 + WAMP3 (php 5.6.15, apache 2.4.17), I was, after a number of experiments, able to narrow down the minimal set of three files that needed to be copied to the bin directory (Apache's for non-cli apps) from the instantclient 12 distribution, to allow instantiate an Oracle adapter within Zend Framework, perform an SQL query and read the recordset.
This set is: oci.dll, oraociei12.dll and orans.dll.
In particular, copying just oci.dll wouldn't allow the application to work (unknow Exception raised)
Ive installed httpd and httpd-devel packages and installed php and php-devel on a server. I downloaded and installed the basic client and sdk for oracle and then proceeded to use PECL to install OCI8 extension.
When I try running the oci_connect function page on CLI, It works fine. But when I try to load the same php page over http, i get the following error:
Fatal error: Call to undefined function oci_connect() in /var/www/html/index.php on line 10
I have compared the php ini from both and notice that /etc/php.d/oci8.ini file is loaded in the cli and the http version
however, the module details are only available on the cli version:
oci8
OCI8 Support => enabled
OCI8 DTrace Support => disabled
OCI8 Version => 2.0.8
Revision => $Id: f04114d4d67cffea4cdc2ed3b7f0229c2caa5016 $
Oracle Run-time Client Library Version => 12.1.0.2.0
Oracle Compile-time Instant Client Version => 12.1
Directive => Local Value => Master Value
oci8.connection_class => no value => no value
oci8.default_prefetch => 100 => 100
oci8.events => Off => Off
oci8.max_persistent => -1 => -1
oci8.old_oci_close_semantics => Off => Off
oci8.persistent_timeout => -1 => -1
oci8.ping_interval => 60 => 60
oci8.privileged_connect => Off => Off
oci8.statement_cache_size => 20 => 20
I cant for the life of me figure out why only one loads the extension properly when they both have the same configuration file.
Thanks for any help!
I managed to fix this by disabling SELINUX