个人工具

“UbuntuHelp:PHPOracle”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
 
(未显示同一用户的3个中间版本)
第1行: 第1行:
 
{{From|https://help.ubuntu.com/community/PHPOracle}}
 
{{From|https://help.ubuntu.com/community/PHPOracle}}
 
{{Languages|UbuntuHelp:PHPOracle}}
 
{{Languages|UbuntuHelp:PHPOracle}}
To be able to access Oracle databases from PHP, you will need to have the Oracle OCI library installed in your machine.
+
To be able to access Oracle databases from PHP, you will need to have PHP compiled / linked with the Oracle OCI (oci8) library.
 
+
You could use the [http://www.oracle.com/technology/tech/php/zendcore/index.html pre-built PHP 5 from Zend] or there are two other ways to get PHP working with OCI8:
There are two ways to get this library:
+
<ol><li>Install the Oracle Database [Oracle10g] [Oracle9i]
 
+
</li><li>Install Oracle Instant Client</li></ol>
* Install the Oracle Database [Oracle10g] [Oracle9i]
+
* Install Oracle Instant Client
+
  
 
If your Oracle database is in another machine, the Oracle Instant Client is a smaller install.
 
If your Oracle database is in another machine, the Oracle Instant Client is a smaller install.
 
 
=== PHP using Oracle Database Server ===
 
=== PHP using Oracle Database Server ===
 
 
TODO
 
TODO
 
 
=== PHP using Oracle Instant Client ===
 
=== PHP using Oracle Instant Client ===
 
 
Tested Environment:
 
Tested Environment:
 
+
Ubuntu Server 10.04 LTS
Ubuntu Server 6.06 LTS
+
Oracle Instant Client 11.2
Oracle Instant Client 10.2.0.2
+
 
+
 
Prerequisites:
 
Prerequisites:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo apt-get install build-essential
 
sudo apt-get install build-essential
 
sudo apt-get install php5-dev php-pear
 
sudo apt-get install php5-dev php-pear
 
</nowiki></pre>
 
</nowiki></pre>
 
+
Instant Client installation requires some environment variables to be able to see the library folder. Edit /etc/environment and add at the end:
Also download the Oracle Instant Client
+
<pre><nowiki>
http://www.oracle.com/technology/tech/oci/instantclient/index.html
+
# Oracle Instant Client
 
+
LD_LIBRARY_PATH="/usr/local/lib/instantclient_11_2"
You will need the Basic (34MB) and SDK (600K). The Basic Lite version does not work.
+
TNS_ADMIN="/usr/local/lib/instantclient_11_2"
 
+
ORACLE_BASE="/usr/local/lib/instantclient_11_2"
 +
ORACLE_HOME=$ORACLE_BASE
 +
</nowiki></pre>
 +
Then download the [http://www.oracle.com/technology/tech/oci/instantclient/index.html Oracle Instant Client from Oracle.com] (you will need to create an account)
 +
You will need the Basic (48MB) and SDK (600K). The Basic Lite version does not work.
 
<pre><nowiki>
 
<pre><nowiki>
 
cd /usr/local/lib
 
cd /usr/local/lib
 
sudo unzip <location-of-instant-client-basic>
 
sudo unzip <location-of-instant-client-basic>
 
sudo unzip <location-of-instant-client-sdk>
 
sudo unzip <location-of-instant-client-sdk>
cd instantclient_10_2
+
cd instantclient_11_2
sudo ln -s libclntsh.so.10.1 libclntsh.so
+
sudo ln -s libclntsh.so.11.1 libclntsh.so
 
</nowiki></pre>
 
</nowiki></pre>
 
 
The symbolic link is needed by during the compilation step later.
 
The symbolic link is needed by during the compilation step later.
 
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo pecl install oci8
 
sudo pecl install oci8
 
</nowiki></pre>
 
</nowiki></pre>
 
 
You will be prompted for the location of the library:
 
You will be prompted for the location of the library:
 
 
<pre><nowiki>
 
<pre><nowiki>
instantclient,/usr/local/lib/oracle_10_2
+
instantclient,/usr/local/lib/oracle_11_2
 +
</nowiki></pre>
 +
You will be prompted also for the ORACLE_HOME location, type 'all', accept and then insert:
 +
<pre><nowiki>
 +
instantclient,/usr/local/lib/oracle_11_2
 
</nowiki></pre>
 
</nowiki></pre>
 
 
If successful, you may now add the following line at the bottom of php.ini
 
If successful, you may now add the following line at the bottom of php.ini
 
 
<pre><nowiki>
 
<pre><nowiki>
extension = oci8.so
+
extension=oci8.so
 
</nowiki></pre>
 
</nowiki></pre>
 
 
The php.ini is found in 2 places: /etc/php5/apache2/php.ini and /etc/php5/cli/php.ini
 
The php.ini is found in 2 places: /etc/php5/apache2/php.ini and /etc/php5/cli/php.ini
 
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo /etc/init.d/apache2 reload
 
sudo /etc/init.d/apache2 reload
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Check <?php echo phpinfo() ?> to verify if the OCI8 module is available.
 
Check <?php echo phpinfo() ?> to verify if the OCI8 module is available.
 
 
=== Further Reading ===
 
=== Further Reading ===
 
 
* [http://www.orafaq.com/wiki/PHP Oracle PHP Wiki]
 
* [http://www.orafaq.com/wiki/PHP Oracle PHP Wiki]
  
 
[[category:UbuntuHelp]]
 
[[category:UbuntuHelp]]

2010年5月19日 (三) 23:53的最新版本


To be able to access Oracle databases from PHP, you will need to have PHP compiled / linked with the Oracle OCI (oci8) library. You could use the pre-built PHP 5 from Zend or there are two other ways to get PHP working with OCI8:

  1. Install the Oracle Database [Oracle10g] [Oracle9i]
  2. Install Oracle Instant Client

If your Oracle database is in another machine, the Oracle Instant Client is a smaller install.

PHP using Oracle Database Server

TODO

PHP using Oracle Instant Client

Tested Environment: Ubuntu Server 10.04 LTS Oracle Instant Client 11.2 Prerequisites:

sudo apt-get install build-essential
sudo apt-get install php5-dev php-pear

Instant Client installation requires some environment variables to be able to see the library folder. Edit /etc/environment and add at the end:

# Oracle Instant Client
LD_LIBRARY_PATH="/usr/local/lib/instantclient_11_2"
TNS_ADMIN="/usr/local/lib/instantclient_11_2"
ORACLE_BASE="/usr/local/lib/instantclient_11_2"
ORACLE_HOME=$ORACLE_BASE

Then download the Oracle Instant Client from Oracle.com (you will need to create an account) You will need the Basic (48MB) and SDK (600K). The Basic Lite version does not work.

cd /usr/local/lib
sudo unzip <location-of-instant-client-basic>
sudo unzip <location-of-instant-client-sdk>
cd instantclient_11_2
sudo ln -s libclntsh.so.11.1 libclntsh.so

The symbolic link is needed by during the compilation step later.

sudo pecl install oci8

You will be prompted for the location of the library:

instantclient,/usr/local/lib/oracle_11_2

You will be prompted also for the ORACLE_HOME location, type 'all', accept and then insert:

instantclient,/usr/local/lib/oracle_11_2

If successful, you may now add the following line at the bottom of php.ini

extension=oci8.so

The php.ini is found in 2 places: /etc/php5/apache2/php.ini and /etc/php5/cli/php.ini

sudo /etc/init.d/apache2 reload

Check <?php echo phpinfo() ?> to verify if the OCI8 module is available.

Further Reading