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:
http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
Download the file (spotted the file name):
123 | oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm oracle-instantclient19.8-devel-19.8.0.0.0-1.x86_64.rpm |
2 : PHP official website download address:
PHP-OCI8 plugin
Download command:
1 | wget http: //pecl.php.net/get/oci8-2.2.0.tgz |
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
1 : Install the oracle plugin
12 | rpm -ivh oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm rpm -ivh oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm |
May report an error:
ImportError: libaio.so.1: 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:
1 | yum install libaio |
2 : Install the OCI8 plugin
(1): Unzip the tar package:
1 | tar -zxf oci8-2.2.0.tgz |
(2): Enter the decompression directory
1 | cd oci8-2.2.0 |
(3): Run the following command:
1 | phpize |
There may be an error when running: Can’t find PHP headers in /usr/include/php The php-devel package is required for use
solution
1 | yum 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 |
or
1 | ./configure -with-oci8=shared, $ORACLE_HOME |
(5): Execute compile and install:
1 | make install |
There may be an error here:
make: *** No rule to make target build', needed by
default’. Stop.
solution:
1: Install the following configuration:
1 | yum -y install make zlib-devel gcc-c++ libtool openssl openssl-devel |
2 : Reconfigure
1 | ./configure |
3: Compile
1 | make && make install |
(6): Configure php.ini
We add in the PHP configuration file php.ini
1 | extension=oci8.so |
Restart PHP
1 | systemctl restart php-fpm |
Restart the web server (nginx, apache, etc.).
1 | systemctl 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!