Skip to content

Instantly share code, notes, and snippets.

@eSkiSo
Created March 12, 2021 16:05
Show Gist options
  • Star 41 You must be signed in to star a gist
  • Fork 21 You must be signed in to fork a gist
  • Save eSkiSo/781269c79b4dd740e90fcc059c1985ae to your computer and use it in GitHub Desktop.
Save eSkiSo/781269c79b4dd740e90fcc059c1985ae to your computer and use it in GitHub Desktop.
Install OCI8 (Oracle) in Ubuntu 20 with PHP 7.4

Install OCI8 on Ubuntu 20.04 with PHP 7.4

Step 1

Download Oracle Instant Client and SDK from Oracle:

http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html

Download files:

Basic Package (ZIP): instantclient-basic-linux.x64-21.1.0.0.0.zip

SDK Package (ZIP): instantclient-sdk-linux.x64-21.1.0.0.0.zip

Step 2

Create new folders for Oracle Instant Client on server

    sudo mkdir /usr/lib/oracle
    sudo mkdir /usr/lib/oracle/21.1
    sudo mkdir /usr/lib/oracle/21.1/client64

Step 3

Extract files

    sudo cp instantclient-basic-linux.x64-21.1.0.0.0.zip /usr/lib/oracle/21.1/client64
    sudo cp instantclient-sdk-linux.x64-21.1.0.0.0.zip /usr/lib/oracle/21.1/client64

    cd /usr/lib/oracle/21.1/client64

    sudo unzip instantclient-basic-linux.x64-21.1.0.0.0.zip
    sudo unzip instantclient-sdk-linux.x64-21.1.0.0.0.zip

    sudo mv instantclient_21_1 lib

Step 4

Create symbolic link to the new Instant Client files:

    cd /usr/lib/oracle/21.1/client64/lib/    
    sudo ln -s libclntsh.so.21.1 libclntsh.so (It may already exist, continue)
    sudo ln -s libocci.so.21.1 libocci.so (It may already exist, continue)

Step 5

Edit/Create this file with the path to the lib (for LDCONFIG):

	sudo echo /usr/lib/oracle/21.1/client64/lib > /etc/ld.so.conf.d/oracle.conf

Step 6

Update Dynamic Linker

	ldconfig

Step 7

Install php-dev php-pear build-essential and libaio1

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

Step 8

Update PECL to install OCI8 from it

	sudo pecl channel-update pecl.php.net

Install OCI8 from PCEL (desired version, default seems not to find it for me, i used php7.)

    sudo pecl install oci8 (php 8)
    sudo pecl install oci8-2.2.0  (php 7.)

During install it will require the path to Instant Client, write this:

	instantclient,/usr/lib/oracle/21.1/client64/lib

At the end something like this should appear:

Build process completed successfully
Installing '/usr/lib/php/20190902/oci8.so'
install ok: channel://pecl.php.net/oci8-2.2.0
configuration option "php_ini" is not set to php.ini location
You should add "extension=oci8.so" to php.ini

Step 9

Load OCI8 into PHP

	sudo echo "extension=oci8.so" >> /etc/php/7.4/cli/php.ini

Restart Apache

	sudo systemctl restart apache2

Step 10

Add to mods-available

	cd /etc/php/7.4/mods-available/
	sudo nano oci.ini

Add this to the file:

extension = oci8.so

Step 11

Create sym link to the created ini file

	cd /etc/php/7.4/apache2/conf.d
	sudo ln -s /etc/php/7.4/mods-available/oci.ini 20-oci.ini

Restart Apache

	sudo systemctl restart apache2

Step 12 (Testing)

Check if OCI is loaded in PHP

	php -i | grep oci

Should output something like this:

oci8
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

Credits

Based on a post from Carlos Juan

https://www.cjorellana.net/2020/12/como-instalar-oci8-en-ubuntu-2004-y-php.html

@lhervi
Copy link

lhervi commented Mar 1, 2023

aashestakov

God bless you aashestakov :)

@ngoanhphong19730708
Copy link

ngoanhphong19730708 commented Apr 27, 2023

I installed, all the step are the same guide. After that php not working . I can not run any php file.
Pls tell me why ?. Thanks

@acaciobernardo
Copy link

Thank you!!

@Ishak-ali
Copy link

Thank you so much Eskiso, it worked like charm

@hopeseekr
Copy link

hopeseekr commented Jan 13, 2024

Hi the process work fine till step 8, when i run "sudo pecl install oci8-2.2.0" i have got this response

Notice: Trying to access array offset on value of type bool in PEAR/REST.php on line 187 PHP Notice: Trying to access array offset on value of type bool in /usr/share/php/PEAR/REST.php on line 187 No releases available for package "pecl.php.net/oci8" install failed and can't find any way to go further!!

I’m on PHP 7.4.2, have found how to “Manually Installing OCI8 on Linux as a Shared Extension” here , but i’d like understand the pecl problem.

Hey @marcoriccine: This problem is caused when your PHP doesn’t have ext-xml installed. I found that out while running this very tutorial and getting blocked myself.

@hopeseekr
Copy link

For PHP 8.1 and above, you have to use pecl install oci8-3.2.1.

What a mess! The extension writers should hold their heads in absolute shame for pushing distinct PECL packages per oracle versions. Can you imagine if we had 7 different mysqli extensions for each version of MySQL??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment