How does php7.2 connect to oracle database? Installation of the OCI8 extension

How does php7.2 connect to oracle database? The following article will introduce to you the method of installing OCI8 extension to support oracle database in php7.2, I hope it will be helpful to you!

When working on a project, the remote oracle database provides us with an intermediate table. Some data in my business needs to be queried from this intermediate table in the oracle database.

PHP connects to oracle database. An extension to OCI8 is required. I am ashamed to say that I have worked for so many years and have not used the oracle database seriously.

The syntax of the mysql database is different from that of the oracle database. Don’t use the mysql syntax to operate the oracle database like me… a bit embarrassing…

Today we will roughly record the installation process of the OCI8 extension.

1: Download the file

1: Download address from oracle official website:

Download the file (spotted the file name):

123oracle-instantclient19.8-basic- oracle-instantclient19.8-devel-

: PHP official website download address:

PHP-OCI8 plugin

Download command:


It is recommended to put the above three files in the /opt directory. Of course, it is your freedom to put them in the specific place. Just find it.

Two: installation

: Install the oracle plugin

12rpm -ivh oracle-instantclient11.2-basic- -ivh oracle-instantclient11.2-devel-

May report an error:

ImportError: cannot open shared object file: No such file or directory”

The reason for the error has been given above, the libiao plugin is missing, the solution:

1yum install libaio

: Install the OCI8 plugin

(1): Unzip the tar package:

1tar -zxf oci8-2.2.0.tgz

(2): Enter the decompression directory

1cd oci8-2.2.0

(3): Run the following command:


There may be an error when running: Can’t find PHP headers in /usr/include/php The php-devel package is required for use


1yum install php72w-devel

(4): Use $ORACLE_HOME or Instant Client to configure the software package

1./configure --with-oci8=shared,instantclient,/usr/lib/oracle/<version>/client/lib


1./configure -with-oci8=shared,$ORACLE_HOME

(5): Execute compile and install:

1make install

There may be an error here:

make: *** No rule to make target build', needed by default’. Stop.


1: Install the following configuration:

1yum -y install make zlib-devel gcc-c++ libtool openssl openssl-devel



3: Compile

1make && make install

(6): Configure php.ini

We add in the PHP configuration file php.ini

Restart PHP

1systemctl restart php-fpm

Restart the web server (nginx, apache, etc.).

1systemctl restart nginx

Check it out PHPinfo();as shown below:


Then, you can configure multiple database links in your PHP framework.

Recommended study: ” PHP Video Tutorial “

The above is how php7.2 connects to oracle database? For more details on the installation of the OCI8 extension, please pay attention to other related articles on the php Chinese website!

Leave a Reply

Your email address will not be published. Required fields are marked *