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.
The OCI8 extension is being loaded twice in the system configuration:
- Main PHP Configuration:
/etc/php.ini
containsextension=oci8.so
- Modular Configuration:
/etc/php.d/20-oci8.ini
containsextension=oci8
When PHP starts, it loads extensions from both locations, causing the duplicate loading warning.
- Main config:
/etc/php.ini
- Module configs:
/etc/php.d/
directory - OCI8 module config:
/etc/php.d/20-oci8.ini
# Found in /etc/php.ini:
extension=oci8.so
# Found in /etc/php.d/20-oci8.ini:
extension=oci8
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
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
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
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);
?>
sudo cp /etc/php.ini /etc/php.ini.backup
sudo cp /etc/php.d/20-oci8.ini /etc/php.d/20-oci8.ini.backup
# Edit the main php.ini file
sudo nano /etc/php.ini
# Find and comment out or remove this line:
# extension=oci8.so
# Ensure this file exists and contains:
cat /etc/php.d/20-oci8.ini
# Should show: extension=oci8
# 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
# Test any PHP script
# Should not show OCI8 warnings
# 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 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
After implementing the fix, verify:
- No warnings:
php -r "echo 'Test';" 2>&1 | grep -i warning
should return nothing - OCI8 still works:
php -m | grep oci8
should return "oci8" - Reports work: Daily and interactive reports should run without warnings
- Database connections work: Oracle connections should function normally
- Any PHP scripts that use Oracle database connections
- 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
/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