I recently had to work on a project that was written in PHP and was getting data from an Oracle database. Installing
php on Ubuntu is pretty straightforward but connecting to the database unfortunately required quite a few gymnastics!
In this article we will look at how to compile PHP extensions on Ubuntu 18.04 and above, specifically the
pdo_oci extension. Note that in order for this extension to work, the oracle drivers must be already installed. See this article for instructions on how to setup Oracle drivers on Ubuntu.
The general procedure to install extensions is as follows:
sudo make install
php -mshould now list PDO_OCI as an enabled module.
sudo service php7.4-fpm restart
This above method installs a
pdo_oci.so in the PHP extensions folder, without the need for recompiling
all of PHP. Note that in my case, the project in question was using the
PDO OCI driver which is actually experimental and not
recommended. The officially approved Oracle driver is OCI and can be installed via
pecl install oci8 (provide the instant client path when prompted
instantclient,/opt/oracle/instantclient_18_3). Note that if this does not work further instructions can be
Note that if you use Apache as your webserver rather than Nginx then the
pdo_oci module needs to be separately enabled in Apache as well. Create
/etc/php/7.4/mods-available/pdo_oci.ini with the following:
; priority=20 extension=pdo_oci.so
sudo phpenmod pdo_oci and
sudo service apache2 restart to enable the extension with Apache.
phpinfo() should now show all the extensions that have been enabled and you can always check your webserver error logs for any issues. Happy coding!
Back to the article list.
Subscribe to get articles as they are published direct to your inbox!