天天看點

php7.2 oci8 擴充問題How to install OCI8 on Ubuntu 18.04 and PHP 7.2

轉載:github

How to install OCI8 on Ubuntu 18.04 and PHP 7.2

Source: www.syahzul.com/2016/04/06/…

Source: medium.com/@kabeza/set…

Source: gist.github.com/hewerthomn/…

Install Oracle Instant Client and SDK

Step 1

Download the Oracle Instant Client and SDK from Oracle website. (Need to login in Oracle page)

www.oracle.com/technetwork…

Files:

instantclient-basic-linux.x64-12.2.0.1.0.zip

and

instantclient-sdk-linux.x64-12.2.0.1.0.zip

.

Step 2

Create a new folder to store Oracle Instant Client zip files on your server.

Upload the Instant Clients files inside this folder.

mkdir /opt/oracle
複制代碼
           

Step 3

Now we need to extract the files.

cd /opt/oracle
unzip instantclient-basic-linux.x64-12.2.0.1.0.zip
unzip instantclient-sdk-linux.x64-12.2.0.1.0.zip
複制代碼
           

Step 4

Next, we need to create a symlink to Instant Client files.

ln -s /opt/oracle/instantclient_12_2/libclntsh.so.12.1 /opt/oracle/instantclient_12_2/libclntsh.so
ln -s /opt/oracle/instantclient_12_2/libocci.so.12.1 /opt/oracle/instantclient_12_2/libocci.so
複制代碼
           

Step 5

Add the folder to our

ldconfig

.

echo /opt/oracle/instantclient_12_2 > /etc/ld.so.conf.d/oracle-instantclient
複制代碼
           

Step 6

Update the Dynamic Linker Run-Time Bindings

ldconfig
複制代碼
           

Done. Now we can proceed to the next part.

Install Additional Packages

To install the OCI8 extension, we need to install some additional package on our server.

Step 1

Run these command:

apt-get install php-dev php-pear build-essential libaio1
複制代碼
           

Step 2

Once installed, we need to get the OCI8 file. But, before that we need to update PECL channel.

pecl channel-update pecl.php.net

複制代碼
           

Then.

pecl install oci8
複制代碼
           

When you are prompted for the Instant Client location, enter the following:

instantclient,/opt/oracle/instantclient_12_2
複制代碼
           

Step 3

We need to tell PHP to load the OCI8 extension.

echo "extension =oci8.so" >> /etc/php/7.2/fpm/php.ini
echo "extension =oci8.so" >> /etc/php/7.2/cli/php.ini
echo "extension =oci8.so" >> /etc/php/7.2/apache2/php.ini

複制代碼
           

We also need to add on apache those environment variables.

echo "export LD_LIBRARY_PATH=/opt/oracle/instantclient_12_2" >> /etc/apache2/envvars
echo "export ORACLE_HOME=/opt/oracle/instantclient_12_2" >> /etc/apache2/envvars

echo "LD_LIBRARY_PATH=/opt/oracle/instantclient_12_2:$LD_LIBRARY_PATH" >> /etc/environment
複制代碼
           

Step 4

Refresh the server. If you are accessing through SSH, then

exit
複制代碼
           

or

sudo shutdown -r now
複制代碼
           

Check if the extension is enabled.

php -m | grep 'oci8'
複制代碼
           

If returns

oci8

, its works!

Step 5

Restart the PHP-FPM

service php7.2-fpm restart
複制代碼
           

Now you can connect to Oracle DBMS from your PHP applications.

轉載于:https://juejin.im/post/5d0065da5188257152110ffd