Skip to content

Instantly share code, notes, and snippets.

@steve-ross
Created June 11, 2025 17:30
Show Gist options
  • Save steve-ross/7bf71dd0978126fd585a78b037a68610 to your computer and use it in GitHub Desktop.
Save steve-ross/7bf71dd0978126fd585a78b037a68610 to your computer and use it in GitHub Desktop.
testing gist with jose

OCI8 Multiple Loading Issue - Diagnosis and Solutions

Problem Description

The PHP warning "Module 'oci8' already loaded in Unknown on line 0" occurs when the OCI8 extension (Oracle database connector) is being loaded multiple times during PHP execution.

Root Cause Analysis

The OCI8 extension is being loaded twice in the system configuration:

  1. Main PHP Configuration: /etc/php.ini contains extension=oci8.so
  2. Modular Configuration: /etc/php.d/20-oci8.ini contains extension=oci8

When PHP starts, it loads extensions from both locations, causing the duplicate loading warning.

System Configuration Found

Current PHP Configuration Locations:

  • Main config: /etc/php.ini
  • Module configs: /etc/php.d/ directory
  • OCI8 module config: /etc/php.d/20-oci8.ini

Duplicate Loading Evidence:

# Found in /etc/php.ini:
extension=oci8.so

# Found in /etc/php.d/20-oci8.ini:
extension=oci8

Impact

While this warning doesn't break functionality, it:

  • Creates noise in log files and console output
  • Appears in all PHP scripts that use Oracle connections
  • Affects our daily reports and interactive shell scripts
  • May cause confusion during debugging

Solutions (Choose One)

Option 1: Remove from php.ini (RECOMMENDED)

Remove the OCI8 extension line from the main php.ini file, keeping only the modular approach:

# Edit /etc/php.ini and comment out or remove this line:
# extension=oci8.so

# Keep /etc/php.d/20-oci8.ini as-is with:
extension=oci8

Advantages:

  • Follows modern PHP best practices
  • Modular approach is easier to manage
  • Numbered files (20-oci8.ini) control loading order
  • System package managers typically use this approach

Option 2: Remove from modular config

Remove or rename the modular configuration file:

# Option 2a: Remove the file
sudo rm /etc/php.d/20-oci8.ini

# Option 2b: Rename to disable
sudo mv /etc/php.d/20-oci8.ini /etc/php.d/20-oci8.ini.disabled

Keep in main php.ini:

extension=oci8.so

Option 3: Suppress warnings in PHP scripts

Add error suppression to PHP scripts (NOT RECOMMENDED):

<?php
// Suppress OCI8 loading warnings
error_reporting(E_ALL & ~E_WARNING);

// Or redirect stderr for specific commands
ini_set('log_errors', 0);
?>

Recommended Implementation Steps

Step 1: Backup Current Configuration

sudo cp /etc/php.ini /etc/php.ini.backup
sudo cp /etc/php.d/20-oci8.ini /etc/php.d/20-oci8.ini.backup

Step 2: Remove from php.ini (Recommended)

# Edit the main php.ini file
sudo nano /etc/php.ini

# Find and comment out or remove this line:
# extension=oci8.so

Step 3: Verify modular config is active

# Ensure this file exists and contains:
cat /etc/php.d/20-oci8.ini
# Should show: extension=oci8

Step 4: Test the change

# Restart web server (if applicable)
sudo systemctl restart httpd
# or
sudo systemctl restart apache2

# Test OCI8 loading
php -m | grep oci8
# Should show: oci8

# Test for warnings
php -r "echo 'OCI8 test successful\n';" 2>&1 | grep -i warning
# Should show no OCI8 warnings

Step 5: Verify system functionality

# Test any PHP script
# Should not show OCI8 warnings

Verification Commands

Check current PHP configuration:

# Show all loaded extensions
php -m

# Show specific OCI8 info
php -m | grep -i oci

# Show configuration files being used
php --ini

# Test for the warning
php -r "echo 'Test';" 2>&1 | grep -i oci8

Check file contents:

# Check main php.ini for OCI8
grep -n "extension=oci8" /etc/php.ini

# Check modular configs
ls -la /etc/php.d/*oci8*
cat /etc/php.d/20-oci8.ini

Post-Fix Verification

After implementing the fix, verify:

  1. No warnings: php -r "echo 'Test';" 2>&1 | grep -i warning should return nothing
  2. OCI8 still works: php -m | grep oci8 should return "oci8"
  3. Reports work: Daily and interactive reports should run without warnings
  4. Database connections work: Oracle connections should function normally

Files Affected by This Issue

  • Any PHP scripts that use Oracle database connections

Additional Notes

  • This is a system-wide PHP configuration issue, not specific to an application
  • The fix requires administrative privileges to modify PHP configuration files
  • Changes may require web server restart to take effect
  • Always test in a development environment first if possible
  • Consider coordinating with system administrators before making changes

Related Configuration Files

/etc/php.ini                    # Main PHP configuration
/etc/php.d/                     # Modular extension directory
/etc/php.d/20-oci8.ini         # OCI8 specific configuration
/var/log/httpd/error_log        # Where PHP errors are typically logged

Created: June 11, 2025
Issue: PHP Warning: Module 'oci8' already loaded
System: PHP Recommended Solution: Remove extension=oci8.so from /etc/php.ini

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment