Install OCI8 on Ubuntu 20.04 with PHP 7.4

Etape 1

Download Oracle Instant Client and SDK from Oracle:

Download files:

Basic Package (ZIP):

SDK Package (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

    cd /usr/lib/oracle/21.1/client64

     sudo unzip
 sudo unzip
    sudo mv instantclient_21_6 lib

Step 4

Create symbolic link to the new Instant Client files:

    cd /usr/lib/oracle/21.6/client64/lib/    
    sudo ln -s (It may already exist, continue)
    sudo ln -s (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.6/client64/lib > /etc/

Step 6

Update Dynamic Linker


Step 7

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

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

Step 8

Update PECL to install OCI8 from it

	sudo pecl channel-update

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:


At the end something like this should appear:

Build process completed successfully
Installing '/usr/lib/php/20190902/'
install ok: channel://
configuration option "php_ini" is not set to php.ini location
You should add "" to php.ini

Step 9

Load OCI8 into PHP

	sudo echo "" >> /etc/php/7.3/cli/php.ini

Restart Apache

	sudo systemctl restart apache2

Step 10

Add to mods-available

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

Add this to the file:

extension =

Etape 11

Create sym link to the created ini file

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

Redémarrez Apache

	$ sudo systemctl restart apache2

Etape 12 (Tester)

Check if OCI is loaded in PHP

	php -i | grep oci

Cela devrait afficher quelque chose comme ça:

oci8.connection_class => no value => no value
oci8.default_prefetch => 100 => 100 => 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

Vous pouvez aussi tester à l’aide d’un script phpinfo.php :

Un petit script de test :


$conn = @oci_connect('monlogin', 'monmotdepasse', 'monserveur/mabase');

if (!$conn) {
   die("Database Connection Error");

$stid = oci_parse($conn, 'SELECT * FROM HOLX_SSI_LABEL_V WHERE ROWNUM <5 ' );
echo "<table>";
echo "<tr><th>Numéro de série</th><th>Référence</th></tr>";
while (($emp = oci_fetch_array($stid, OCI_BOTH)) != false) {
        echo "<tr>";
        echo "<td>".$emp['SERIAL_NO']."</td>";
        echo "<td>".$emp['ITEM_NO']."</td>";
        echo "</tr>";
echo "</table>";


Et voilà :


Based on a post from Carlos Juan

Print Friendly, PDF & Email