Hướng dẫn dùng solaris explained trong PHP
Configuring PHP with OCI8Review the previous Requirements section before configuring OCI8. Show
Before starting the web server, OCI8 typically requires several Oracle environment variables (see below) to locate libraries, point to configuration files, and set some basic properties such as the character set used by Oracle libraries. The variables must be set before any PHP process starts. The PHP binary must link with the same, or more recent, major version of Oracle libraries as it was configured with. For example, if you build OCI8 with Oracle 19 libraries, then PHP should also be deployed and run with Oracle 19 libraries. PHP applications can connect to other versions of Oracle Database, since Oracle has client-server cross-version compatibility. Installing OCI8 from PECL Using the pecl CommandThe OCI8 extension can be added to an existing PHP installation by using the » PECL repository.
Installing OCI8 from PECL Using phpizeTo install OCI8 on an existing PHP installation when the pecl command is not available, manually download the » PECL OCI8 package, e.g. oci8-3.0.0.tgz.
Installing OCI8 as a Shared Extension when Building PHPIf you are building PHP from source code, the configuration shared option can be used to build OCI8 as a shared library that can be dynamically loaded into PHP. Building a shared extension allows OCI8 to be upgraded easily without impacting the rest of PHP. Configure OCI8 using one of the following configure options.
After configuration, follow the usual PHP building procedure, e.g. make install. The OCI8 shared extension oci8.so library will be created. It may need to be manually moved to the PHP extension directory, specified by the extension_dir option in your php.ini file. To complete installation of OCI8, edit php.ini and add the line: Installing OCI8 as a Statically Compiled Extension when Building PHPIf you are building PHP from source code, you can configure PHP to include OCI8 as a static extension using one of the following configure options.
After configuration, follow the usual PHP building procedure, e.g. make install. After successful compilation, you do not need to add oci8.so to php.ini. No additional build steps are required. Installing OCI8 on WindowsThe OCI8 extension can be added to an existing PHP installation by using the DLLs from » PECL repository or the libraries in your PHP installation's ext directory. With Oracle 12c (or later) libraries, uncomment one of the php.ini lines extension=php_oci8_12c.dll or extension=php_oci8_11g.dll or extension=php_oci8.dll. Only one of these DLLs may be enabled at a time. DLLs with higher versions may contain more functionality. Not all DLLs may be available for all versions of PHP. Make sure extension_dir is set to the directory containing the PHP extension DLLs. If using Instant Client, set the system PATH environment variable to the Oracle library directory. Setting the Oracle EnvironmentBefore using this extension, make sure that the Oracle environment variables are properly set for the web daemon user. If your web server is automatically started at boot time then make sure that the boot-time environment is also configured correctly.
On Red Hat Linux and variants, export variables at the end of /etc/sysconfig/httpd. Other systems with Apache 2 may use an envvars script in the Apache bin directory. A third option, the Apache SetEnv directive in httpd.conf, may work in some systems but is known to be insufficient in others. To check that environment variables are set correctly, use phpinfo() and check the Environment (not the Apache Environment) section contains the expected variables. The variables that might be needed are included in the following table. Refer to the Oracle documentation for more information on all the available variables. Common Oracle Environment Variables
Less frequently used Oracle environment variables include TWO_TASK, ORA_TZFILE, and the various Oracle globalization settings like NLS* and the ORA_NLS_* variables. TroubleshootingThe most common problem with installing OCI8 is not having the Oracle environment correctly set. This typically appears as a problem using oci_connect() or oci_pconnect(). The error may be a PHP error such as Call to undefined function oci_connect(), an Oracle error such as ORA-12705, or even an Apache crash. Check the Apache log files for startup errors and see the sections above to resolve this problem. While network errors like ORA-12154 or ORA-12514 indicate an Oracle network naming or configuration issue, the root cause may be because the PHP environment is incorrectly set up and Oracle libraries are unable to locate the tnsnames.ora configuration file. On Windows, having multiple versions of Oracle on the one machine can easily cause library clashes unless care is taken to make sure PHP only uses the correct version of Oracle. A utility to examine what libraries are being looked for and loaded can help resolve missing or clashing library issues, particularly on Windows.
f dot kheiri at ucl dot ac dot uk ¶ 16 years ago To compile PHP 4.4.2 with OCI8 / Oracle 9i / AIX 5.2 (64-bit) / GCC PHP will automatically compile against the Oracle 64-bit libraries, which PHP being a 32-bit app, will cause "make" to fail (though it will configure fine). Here's how to avoid this: 1. replace your PHP's ext/oci8 directory with the latest ext/oci8 directory downloadable from PECL - then remove the old directory entirely 2. rebuild configure by running: ./buildconf --force ...in PHP's root directory. This will rebuild the configure script. 3. using a tool like sed, in your configure file replace all instances of /path/to/oracle/lib with /path/to/oracle/lib32 - note, this may require GNU's autoconf, m4 and gnumake. 4. export LD_LIBRARY_PATH=/path/to/oracle/lib32 5. ./configure --with-oci-8=/path/to/oracle (and any other options) Then, the usual make and make install. alvaro at demogracia dot com ¶ 14 years ago If you've followed the instructions and you can't even connect to the DB server, welcome to the Oracle hell. Most of the information you'll find is deprecated, incomplete, not for your platform, unnecessary or just plain wrong. Typically, you won't need at all those complicate setups you'll read about and they'll probably make things harder. I suggest you get Systernal's "Filemon" utility (for Windows, in Unix you may do with strace) and find out what exact config files and DLLs are being tried by php.exe (or httpd.exe if PHP runs as Apache module or...). Pretty often, the issue is that (e.g.) TNSNAMES.ORA does not have the correct line ending or Apache is looking for a DLL that does not even exist in your hard disc; learning that prevents you to waste time adding more and more useless environmental variables. Goog luck. devolver at iastate dot edu ¶ 20 years ago I spent several hours tracking down error ORA 24374, which would result from only *SOME* of my select statements. This error would be caused if I made a query that would return any non-numerical value. I am running an Apache 1.3.x webserver and PHP 4.2.1.
The fix is to add entries in your httpd.conf file that would export your environment settings. I added these three lines and everything worked like a charm!
Obviously, if your NLS_LANG is different, you should set it to whatever your NLS_LANG actually is. Ask your friendly DB admin for this information. Hope this helps someone who treads down the path that I just followed! Trent Saxon Leung ¶ 10 years ago Spending long time in researching how to install this on a freshly installed [Red Hat-based (RHEL, CentOS, Fedora)] Linux, and finally I come to this: 1) Download & install
#yum install oracle-instantclient-basic
or
Download:
#rpm -i oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm
2) Check PHP version: #rpm -qa | grep php
It should looks sth like this:
3) Update if needed by: #yum --enablerepo=webtatic update php ** Make sure you have php-devel installed before updating to a newer version, or you might have problem to add package back. If it happened, you\\'ll have to reinstall all php packages (sadly I did):
#yum remove php-common
4) Remember to install a C compiler for installation use:
5) Unzip oci8-1.4.7.tgz:
6) Run phpize (php-devel required):
7) Setup Config:
8) Add a sym-link to the SDK header files (Comes with the instantclient-devel) #ln -s /usr/include/oracle/11.2/client64/ /usr/lib/oracle/11.2/client64/lib/include ** The installation defaults to use 1 dir path only, so the missing SDK files need to add back to that directory, by adding a sym-link \\"include\\" under the lib folder.
9) Compile and install:
[Please note that I'm installing on a 64-bit platform so links are pointing at client64 instead of client] semenov dot v at gmail dot com ¶ 3 years ago CentOS 7 PECL with oci8-2 After documented installation stucks $ yum install systemtap-sdt-devel aliquis at die dot spammers dot die dot link-net dot org ¶ 18 years ago I've had all kinds of errors with RedHat9(yuck), PHP 4.3.4RC1 and Oracle enterprice server 9.2. For some time I thought that --with-oci8 wouldn't work with Oracle9 but that wasn't the case, the solution was many steps.
1) install oracle, might require some tricks, on RedHat9 I had to put this in my .bashrc:
2) compile php, use --with-oci8
3) Make an init-script for the oracle9 database server, as default the TNS listener doesn't run so add that on aswell, example:
4) Configure Apache. For some reason it requires some tweaking with environment variables, in the begining I put those in the PHP-script with putenv, later in the httpd.conf with SetEnv and the mod_env module. But I was told to not do that and instead set them in the init script for Apache. So I copied apachectl to /etc/init.d and edited envvars in $APACHE_PATH/bin. First I added all kinds of env variables until I got it to work, and then I removed them one at a time and came to the following minimal configuration:
Earlier I had added NLS_LANG and TNS_ADMIN above those mentioned above (point 1), but it seems those aren't needed really. So no need for TWO_TASK or ORACLE_SID, only needed one is ORACLE_HOME and if you get missing/invalid option for your OCILogon set LANG to something else like I did. Someone earlier said it might have to do with UTF8. So if you are sure lsncrtl are started and that you have the correct env-variables set in your $APACHE_PATH/bin/envvars you can just use something like: $iDBConn=OCILogon("user","pass","netadmdb");
in your PHP-script and it should work.
Anonymous ¶ 16 years ago
# here's what it took to get it going for me on rhel4 on x86_64 w/ 10gr2 and php5.0.5
# install the instantclient basic and sdk like this
# make the full client use instantclient's files
php configure line is: --with-oci8=/app/oracle/product/10.2.0/db_1/ ben at onshop dot co dot uk ¶ 17 years ago I spent ages trying work out why I was getting the following message when when using ocilogon() on Windows 2000 using PHP 4 and 5: ORA-03106 Fatal two-task communication protocol error This problem is occurs when PHP cannot find ORACLE client environmental variables. The environmental variables can be set in several ways: 1. Within the root 'Directory' directive on Apache httpd.conf:
or 2. Within Windows: Go to the Control Panel>System>Advanced>Environmental Variables Then enter a name value/pair for each of the variables. 3. Using putenv() statements in the PHP file prior to using ocilogon(). This is not ideal because the statements are required evertime you wish to connect to Oracle. neogodo at yahoo dot com dot br ¶ 18 years ago Hey guys!!!! I have all these problems and when are solved a php show this: _oci_server ORA-12159:connection text especified is too long It's simple!!! In the TNSNAMES.ORA remove all space, tab, carriage return on the conection string and, wallah!!! All work fine!!! More info:
PHP 5.0.0 with Oci8
Regards,
NOSPAMPLZ!esartoni at omniaglobal dot net ¶ 19 years ago I had a little problem with ocilogon but only with RedHat 8.0. It always returned some kind of error during connection like 'OCISessionBegin - ... invalid character', or 'OCISessionBegin - ... missing or invalid option in ...' I have finally found what is this problem! You have to change your LANG enviroment variable disabling UTF-8. Example: LANG=en_US.UTF-8 should become LANG=en_US. lore_giver at lycos dot co dot uk ¶ 19 years ago
Running Oracle 9i on a
I was first getting "...wrong ELF class: ELFCLASS64.."
After some unsuccessfull searched I renamed the $ORACLE_HOME/lib to $ORACLE_HOME/lib.org and then renamed the
Thereafter it went passed this config, but now failed on
After setting the Environment variable:
I only had to add the php type in the httpd.conf (in your apache conf directory eg. /usr/local/apache/conf)..
I had to then reverse the $ORACLE_HOME/lib swop on top since php was now having problems with the 32 bit version of the library...so switched it back to 64 and my php script worked.... Hope this helps some out there with similar problems.. Cheers scoop at subindie dot com ¶ 16 years ago Regarding compiling with the recently updated OCI8 Extension (http://pecl.php.net/package/oci8). I ran into problems when statically compiling, such as numerous "undefined reference to `zif_oci_***'" errors. Since I likely won't be the only one to run into this problem, here's some helpful hints: If you've previously compiled your php installation, first: make clean Then replace the existing php-x.x.x/ext/oci8 directory with the latest package from: http://pecl.php.net/package/oci8
./buildconf --force
david dot reynoldsat at ipl dot com ¶ 15 years ago
I had a problem loading php_oci8.dll with php 5.2, Apache, and windows XP - a module not loaded error, on every apache restart.
Sergey ¶ 9 years ago
Lost a day on trying to make work oci8 & pdo_oci extensions in php-fpm 5.3 on OpenSuSE 12.2 (64bit) with latest oracle instant client 11.2.0.3.0. Solution was simple add ORACLE_HOME variable BEFORE running php-fpm. /etc/profile.d/oracle.sh /etc/init.d/php-fpm After "service php-fpm restart" works normally. Hope this helps. Anonymous ¶ 19 years ago Configuring/Compiling PHP as a DSO with Oracle support from source on a Sun Solaris 8 box. We had already installed Oracle 9.2.0 client tools. 1. Make sure the following tools are installed
autoconf
They can be downloaded from http://www.sunfreeware.com. 2. Make sure Apache is installed with DSO support. We ran the Apache configure/compile like so:
LIBS=-lpthread ./configure \
make
3. If you haven't already, install the Oracle client tools.
ORACLE_HOME
(technically, only $ORACLE_HOME is required, but you'll want to set the rest in order to make sure things run smoothly afterward)
5. Make sure '/usr/ccs/bin' is in your path. If not, add it.
gunzip php-4.2.3.tar.gz
7. Run PHP configure like so :
CC=gcc ./configure --with-apxs=/usr/local/apache/bin/apxs \
8. Run make: make
LoadModule php4_module /usr/local/apache/libexec/libphp4.so 11. Make sure the PHP files types are recognized in your httpd.conf file:
AddType application/x-httpd-php .php
12. Test the configuration: /usr/local/apache/bin/apachectl configtest It should return "Syntax OK" 13. Bounce Apache: /usr/local/apache/bin/apachectl restart 14. Here's a simple PHP script to test the setup. If you don't have access to the default tables Oracle provides, change the connections/tablenames/fields to match your setup:
$db_conn = ocilogon("scott", "tiger"); $cmdstr = "select ename, sal from emp";$parsed = ociparse($db_conn, $cmdstr); ociexecute($parsed); $nrows = ocifetchstatement($parsed, $results); echo "Found: $nrows results \n"; echo "
beer at myplace dot now ¶ 13 years ago I was experiencing issues with Unicode characters being saved incorrectly to my ORA 10 DB. Issue was tracked to not having a NLS_LANG environment variable specified - set this correctly in the Apache environment and the issue was resolved. benstendahl at hotmail dot com ¶ 13 years ago When using PHP on an IIS server (Windows Server 2000+): After installing the Oracle Instant Client and adding it to the "PATH" Environment Variable, be sure that you also add "Read & Execute" privileges to the Oracle Instant Client directory for the IIS user designated for the site. This is especially necessary if IIS has been hardened using the IIS Lockdown tool (http://technet.microsoft.com/en-us/library/dd450372(WS.10).aspx) as users must be explicitly granted permissions from the web. Wilber ¶ 1 month ago The OCI8 extension lets you access Oracle Database. Use 'pecl install oci8' to install for PHP 8.1. Use 'pecl install oci8-3.0.1' to install for PHP 8.0. Use 'pecl install oci8-2.2.0' to install for PHP 7. Use 'pecl install oci8-2.0.12' to install for PHP 5.2 - PHP 5.6. Use 'pecl install oci8-1.4.10' to install for PHP 4.3.9 - PHP 5.1. [username@hostname ~]# php -v rainer dot klier at gmx dot at ¶ 16 years ago estoreic (note from 15-May-2006 10:54) is right. there seems to be a problem with the oci8-api-functions in php 4.4.x.
there are error-messages like these in the error_log:
using php 4.4.x with oracle 10.x is impossible, until you do the following:
memory_limit = 128M ; Maximum amount of memory a script may consume (8MB)
11. edit Makefile:
12. make install
have fun!
denis dot delamarre at chu-rennes dot fr ¶ 17 years ago php5 + Apache 2 + solaris 2.10 + oracle9i (64bits) './configure' '--with-oracle=/prod/dba/oraeve/ora9i' '--with-apxs2=/usr/local/apache2/bin/apxs' '--with-zlib' '--with-gd' '--without-mysql' '--with-oci8=/prod/dba/oraeve/ora9i'
fail with :
the solution is between ./configure and make command to edit Makefile and replace /ora9i/lib with /ora9i/lib32 all it's ok oddbec_no_more_spam_kthx at online dot no ¶ 18 years ago I had trouble with norwegian characters using oracle 8.7.1 / php 4something and Apache 2. The only trouble was that '?' appeared instead of the norwegian characters. The solution to it all was to add this to the apachectl script:
export NLS_LANG="norwegian_norway.WE8ISO8859P1"
I'm not sure if all of these are necessary, but I took no change, and it works now :) mike at macgirvin.com ¶ 14 years ago Some notes to save somebody some grief: Installing the Oracle libraries and access module into an existing PHP5 installation on Debian etch without rebuilding php... First grab the Linux instantclient from oracle.com - you'll also need the client SDK kit. Here I'm using instantclient 11.1 create a directory for these such as /home/oracle and unpack both of them to that directory. Go into the oracle directory (and into the instantclient_11_1 directory) and create a symlink: $ ln -s libclntsh.so.11.1 libclntsh.so Grab the oci8 PECL package and unpack it somewhere (~/oci). Make sure you have the following packages (in addition to php5, php5-cli, apache2, etc). php5-dev libaio1 php-pear Go to the oci8 directory (~/oci/). You need to run 'pecl build' once to create the configure script. $pecl build But the problem is that pecl build will claim the files are installed and they are not. I wasted half a day on this one. Now go into the oci8-1.3.0 directory and build again by hand: $ cd oci8-1.3.0 $ ./configure --with-oci8=instantclient,/home/oracle/instantclient_11_1 $ make Fix any errors/warnings before continuing Don't make install, which won't work. $ cp ./modules/oci8.so /usr/lib/php5/20060613+lfs Replace 20060613+lfs with whatever module directory has been setup for you in /usr/lib/php5 Create /etc/php5/conf.d/oci8.ini: ---- extension=oci8.so ---- Now run the php cmdline in verbose mode (php -v) and see if everything loaded. Fix it if it didn't. You may need some env variables setup in your /etc/init.d/apache2 file to make everything work and actually execute queries, but a phpinfo() at this point should show your oci8 extension. See the php.net Oracle pages if you need help with the env variables. Restart the web server $ /etc/init.d/apache2 restart jay dot couture at gmail dot com ¶ 15 years ago
# Here's what it took to get it going for me on Red Hat on
# install the instantclient basic and sdk like this
# make the full client use instantclient's files
#php configure line is:
# I had to do this, or the OCI8 would not compile when
make make install
#In apache2 edit the envvars and add
#Restart Apache Jay MSapp ¶ 17 years ago Problems compiling 5.0.4 with Oracle Instant Client 10? (i.e. cannot find -lirc) Remove the "-lirc" from sdk/demo/sysliblist and rerun configure. kucerar at hhmi dot org ¶ 17 years ago Great Solaris patch! Finally built. Here's some tips on connecting: Just made this on solaris8 32bit, actually works.
1) put everything in one directory
http://www.oracle.com/technology/
These env vars worked when put at the top of apachectl script as well. To build you may have to fake it out with an ORACLE_HOME var, but unset it later. You may also have to fake out the build by putting header files where it is looking for them, e.g. in the rdbms/demo directory or some such other place. When running though, make sure you have only the files required in only one directory. Oracle has not put up a link to the 32bit solaris sqlplus--you have to guess it--it's there though:
http://download.oracle.com/otn/solaris/instantclient/
...and don't forget to add ".world" on to the end of your SID. It's very common to have to specify DBNAME.WORLD to connect. mark at magpies dot net ¶ 18 years ago For those trying to use the Oracle Instant Client 10g in a win32 environment, heres a nice easy howto. If you fully read the docs properly and understand what your reading you will be able to set it up, but if like me you want a quick easy fix, heres how I did it.
1. Download and install the Oracle Instant Client to where ever (lets say c:\ora\client )
Option 7 was required as the oci8 extension or php wouldn't pick up the path change. Also my problem was how to use other programs like sqlplus without creating extra Environment Variables etc the TNS_ADMIN / tnsnames.ora part makes that simpler and allows you to call things the same as you would before. PS: This should apply to all the Instant Clients. I haven't tried it with any others but 10g though. Hope this helps. ed000001 at hotmail dot com ¶ 18 years ago If you get your connectivity working with putenv on ORACLE_SID and ORACLE_HOME, but you do not want to use putenv because you want safemode on. You will need to pass these from your environment variables. Somehow setenv in httpd.conf did not do the trick for me... the values are set but the connectivity does not work. Then you will need to set the environment in your /etc/init.d/apachectl or /etc/profile and use a "PassEnv ORACLE_HOME ORACLE_SID" directive in httpd.conf so that these variables are picked up by php. However, when you suexec in Apache 2.0, the server will only allow you to pass a given set of variables which are defined in the apache source code in the file apache-dir/support/suexec.c In order to pass ORACLE_SID and ORACLE_HOME to PHP you need to add these to that file. The relevant changed piece of code where I added "ORACLE_" looks something like this:
char *safe_env_lst[] =
/* variable name is */
You will have to do a "make clean", "./configure", "make", "make install". Do not forget to do the "make clean" or the apache changes will not be picked up. Here is a nice php test script :)
// test-oracle.php
function dump_array($a_value)
aleigh at tessier dot com ¶ 18 years ago Warning: ocilogon(): _oci_open_session: OCIHandleAlloc OCI_HTYPE_SVCCTX: OCI_INVALID_HANDLE can also be caused by running the webserver with an ORACLE_HOME of a (radically?) different version than PHP was linked against. I experienced this when I accidently used an Oracle 8 ORACLE_HOME for a PHP that was linked against Oracle 9. kakukkfu at mailbox dot hu ¶ 19 years ago Better to insert needed variables into apache(!) (or your webserver - respectively) start script. For example on UNIX systems /etc/init.d/apache would contain following lines before anything else: #!/bin/bash
if [ -f ~oracle/.profile ]; then
The ~oracle/.profile has the appropiate settings to start an Oracle database so it is always up-to-date for PHP, too. (If settings are changed, don't forget to restart your webserver.) This way you just no need to worry what to include or define for PHP. Marinne at ilovechocolate dot com ¶ 21 years ago One simple but useful note:check whether your TNS Listener is running! By default, it's not started automatically when an Oracle instance is started. Login as oracle then type : lsnrctl START After it's started, I can sucessfully run the sample code on this page! I used to got ora-12514 error before doing this. bluei at phpworld dot org ¶ 21 years ago check your tnsnames.ora permission.
ex)
chmod 755 /home/oracle/oracle/network/admin -R Yahoo!!!!!! I solved it!!! shmengie_2000 at yahoo dot com ¶ 21 years ago couple of notes about startup/shutdown on linux: (redhat, maybe others) export LD_PRELOAD=/usr/lib/libpthread.so
Caused the start/stop script to fail to stop the httpd process.
Easiest fix I could think of was to move all the oracle/php varialble exports so they are only set in the start section of the httpd script. Never thought setting those vars globally in the script would cause problems. That's what I get for thinking... One other note: Make sure the httpd process is shutdown before Oracle.
eg:
Lingering connections to oracle may cause shutdown to take forever. gl & hf -Joe modir at huanga dot com ¶ 11 years ago For those of you who would like to install this extension on an RedHat/CentOS server. It is actually pretty simple. Here is what you have to do: 2) yum install php-oci8 3) And as the last step you edit /etc/sysconfig/httpd and write the following line at the end: export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib/ (Attention: Path changes depending on the version you have downloaded from the Oracle website.) nicodenboer (at) yahoo (dot) com ¶ 13 years ago
Hi, I use Oracle Database 10g Express Edition Release
# Use the package manager to install the packages php5-pear and
# Download the instantclient_11_1, zip files basic, sdk, sqlplus from the Oracle web site # Switch to user root here, since not all commands to some work sudo
# Unzip these files to /opt/oracle/.
ln -s /opt/oracle/instantclient_11_1/libclntsh.so.11.1 \
pecl install oci8 # interactively enter option 1,
# if needed, add extension=oci8.so to your php.ini /etc/init.d/apache2 reload # finished!
Kind regards,
john at john-warner dot com ¶ 19 years ago In addition to the earlier posts here is a further explaination; Problem: Regular and Remote authentication does not work using Windows 2000 + PHP and Oracle 8i, 9i.
Secondary Issue if using Oracle 9.2.0.1
Using Oracle 9.0.1.1 the error message returned is any of the following depending on your situation;
Warning: _oci_open_server: ORA-12638: Credential retrieval failed in ...
Resolution:
In reference to ORA-12154 and ORA-12505 you need to do the following;
Live long and prosper. |