Fix PHP Extensions Not Loading in LiteSpeed Web Server

Fix PHP Extensions Not Loading in LiteSpeed Web Server

The Problem

After installing PHP extensions via apt-get on LiteSpeed (e.g., lsphp82-curl, lsphp82-intl), the extensions don’t appear in phpinfo() even though:

  • The .ini files exist in /usr/local/lsws/lsphp82/etc/php/8.2/mods-available/
  • The extensions load correctly via CLI (php -m shows them)
  • LiteSpeed has been restarted

The Cause

LiteSpeed’s PHP scans the mods-available directory for .ini files, but files without a numeric prefix may be ignored during the loading process.

When you install extensions via apt, they create files like curl.ini and intl.ini. However, PHP/LiteSpeed preferentially loads files with numeric prefixes (e.g., 20-curl.ini, 40-igbinary.ini).

The Solution

1. Rename the .ini files with a numeric prefix

cd /usr/local/lsws/lsphp82/etc/php/8.2/mods-available/

# Rename curl.ini
mv curl.ini 20-curl.ini

# Rename intl.ini
mv intl.ini 20-intl.ini

# Repeat for any other extensions not loading

The number determines load order (lower = earlier). Use 20- for most extensions to ensure they load before dependencies.

2. Restart LiteSpeed

/usr/local/lsws/bin/lswsctrl restart

Or for a full stop/start:

/usr/local/lsws/bin/lswsctrl stop
/usr/local/lsws/bin/lswsctrl start

3. Verify

Check phpinfo() in your browser. The “Additional .ini files parsed” section should now include your renamed files:

Additional .ini files parsed: /usr/local/lsws/lsphp82/etc/php/8.2/mods-available/20-curl.ini, /usr/local/lsws/lsphp82/etc/php/8.2/mods-available/20-intl.ini, ...

Quick Diagnostic Commands

# List all .ini files in mods-available
ls -la /usr/local/lsws/lsphp82/etc/php/8.2/mods-available/*.ini

# Check if extension loads via CLI
/usr/local/lsws/lsphp82/bin/php -m | grep -E "curl|intl"

# View contents of an .ini file
cat /usr/local/lsws/lsphp82/etc/php/8.2/mods-available/curl.ini

Prevention

When manually creating .ini files for extensions, always use a numeric prefix:

echo "extension=curl.so" | sudo tee /usr/local/lsws/lsphp82/etc/php/8.2/mods-available/20-curl.ini

Tested on LiteSpeed with lsphp82 on Ubuntu 20.04

Condividi:

Related Posts