Installing the Oracle OCI8 PHP extension on a Laravel Forge server is possible, but it requires a few steps since it's not a standard PHP extension that can be installed with a simple command. Here's a step-by-step guide to help you through the process:
-
Install Oracle Instant Client
- First, you need to download the Oracle Instant Client from the Oracle website. Choose the version that matches your Oracle Database and operating system.
- Upload the downloaded files to your server, or use
wgetorcurlto download them directly to the server. - Install the basic and SDK packages using
alienif you are on a Debian-based system orrpmif you are on a RedHat-based system.
-
Set Environment Variables
- Set the
LD_LIBRARY_PATHenvironment variable to point to the location of the Oracle Instant Client libraries. - Update the
ORACLE_HOMEenvironment variable to the directory where you installed the Oracle Instant Client.
- Set the
-
Install the OCI8 PHP Extension
- Install the necessary development tools and PHP development packages if they are not already installed.
- Use
peclto install the OCI8 extension. You might need to specify the path to the Oracle Instant Client ifpecldoes not find it automatically.
-
Configure PHP
- After the installation is complete, you need to add the extension to your
php.inifile. This can be done by creating a new.inifile in theconf.ddirectory. - Restart PHP-FPM to apply the changes.
- After the installation is complete, you need to add the extension to your
Here's a more detailed walkthrough with commands:
# Install Oracle Instant Client
cd /tmp
wget <oracle-instantclient-download-url>
unzip instantclient-basic-linux.x64-12.1.0.2.0.zip
unzip instantclient-sdk-linux.x64-12.1.0.2.0.zip
sudo mkdir -p /opt/oracle
sudo mv instantclient_12_1 /opt/oracle/
# Set environment variables
echo 'export LD_LIBRARY_PATH="/opt/oracle/instantclient_12_1:$LD_LIBRARY_PATH"' | sudo tee -a /etc/environment
echo 'export ORACLE_HOME="/opt/oracle/instantclient_12_1"' | sudo tee -a /etc/environment
source /etc/environment
# Install development tools and PHP development packages
sudo apt-get update
sudo apt-get install -y build-essential php8.0-dev
# Install OCI8
sudo pecl install oci8
# When asked for the path to the Oracle Instant Client, input:
instantclient,/opt/oracle/instantclient_12_1
# Configure PHP
echo "extension=oci8.so" | sudo tee /etc/php/8.0/cli/conf.d/20-oci8.ini
echo "extension=oci8.so" | sudo tee /etc/php/8.0/fpm/conf.d/20-oci8.ini
# Restart PHP-FPM
sudo service php8.0-fpm restart
Please replace <oracle-instantclient-download-url> with the actual URL to the Oracle Instant Client zip files.
Keep in mind that the paths and version numbers may vary depending on the specific versions of the Oracle Instant Client and PHP you are using. Adjust the commands accordingly.
As for experiences and limitations, it's important to note that the Oracle OCI8 extension can be sensitive to version mismatches between the PHP extension and the Oracle Instant Client, so ensure they are compatible. Additionally, keep an eye on the Laravel Forge release notes and documentation for any updates or changes that might affect the installation process.