How to Install OCI8 Extension for PHP on CentOS 7


OCI8 is a PHP extension that facilitates communication between PHP and Oracle databases. If you're working with Oracle databases and need to use OCI8 with PHP on CentOS 7, this guide will walk you through the installation process step by step.

Step 1: Install Apache on CentOS 7

Before installing OCI8, ensure you have Apache installed on your CentOS 7 server. If not, you can install Apache using the following command:

sudo yum install httpd

Start the Apache service and enable it to start on boot:

sudo systemctl start httpd
sudo systemctl enable httpd

Step 2: Download Oracle Instant Client RPM Packages

Download the Oracle Instant Client RPM packages from the Oracle Instant Client Downloads page:

- oracle-instantclient12.1-basic-

- oracle-instantclient12.1-devel-

Step 3: Install Oracle Instant Client

Install the Oracle Instant Client RPM packages using the following commands:

sudo yum install oracle-instantclient12.1-basic-
sudo yum install oracle-instantclient12.1-devel-


Step 4: Install PHP Development Tools

Install PHP development tools such as php-pecl-pear, php-devel, php-pear, and systemtap-sdt-devel:

sudo yum install php-pecl-pear php-devel php-pear systemtap-sdt-devel -y

Step 5: Set PHP_DTRACE Environment Variable

Before installing OCI8, set the PHP_DTRACE environment variable to yes. This step is required for some PHP installations:

export PHP_DTRACE=yes

Step 6: Install OCI8 Extension

Install the OCI8 extension using the pecl command:

pecl install oci8-2.2.0

During the installation, you'll be prompted to provide the path to the Oracle Instant Client directory. Use the following path:


Step 7: Configure PHP

After installing OCI8, configure PHP to load the OCI8 extension. Open the PHP configuration file in a text editor:

sudo nano /etc/php.ini
Add the following line to enable the OCI8 extension:

Save the file and exit the text editor.

Step 8: Verify OCI8 Installation

Verify that the OCI8 extension is installed correctly:

php -m | grep oci8

If installed properly, you should see oci8 in the output.

Step 9: Restart Apache

Restart the Apache web server to apply the changes:

sudo systemctl restart httpd

You've now successfully installed OCI8 extension for PHP on CentOS 7. This enables PHP to interact with Oracle databases, facilitating the development of web applications with Oracle database support.