php fatal error: class sqlite3 is not found in

php fatal error: class sqlite3 is not found in

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Debugging Class sqlite3 Not Found in PHP

When you encounter the Fatal error: Class 'SQLite3' not found in your PHP logs, it almost always signals a missing or incorrectly loaded extension rather than a syntax error in your code. This is particularly common when migrating from legacy environments like Ubuntu 12.04 with PHP 5.x, where the package manager and PECL processes can diverge easily.

The core issue is that while you may have installed the SQLite3 development libraries (libsqlite3-dev) and the PHP CLI tools, the actual C extension required to bridge PHP and the SQLite engine might not be compiled or linked correctly. In many Linux distributions, installing php5-sqlite3 via apt-get often pulls a pre-compiled shared object (.so file) that matches your system's architecture. However, if you subsequently attempt to build it from source using PECL or phpize, you risk overwriting the working installation with a broken one or leaving the extension in an inconsistent state where Apache cannot find the compiled module.

Diagnosing the Load Failure

Before attempting to rebuild anything, verify exactly what PHP thinks is available. Run the following command in your terminal:

php -m | grep sqlite

If this returns nothing, the extension is definitely not loaded. If it lists sqlite3, but your script still throws the fatal error, there is likely a mismatch between the version of SQLite you are trying to use and the one compiled into PHP, or a path issue in your configuration.

Check the active configuration files using:

php -i | grep sqlite

Look for the sqlite3 entry under "Additional ini Files". If it points to /etc/php5/conf.d/sqlite3.ini, ensure that file exists and contains exactly:

extension=sqlite3.so

A common pitfall in Ubuntu 12.04 is that the Apache module path might differ from the CLI path. The extension compiled for php-cli often won't work if you restart Apache without explicitly loading the module into the Apache configuration, or vice versa.

Resolving Source Installation Conflicts

If you followed a tutorial that involved downloading sqlite3-0.6.tgz, extracting it, and running sudo phpize, you likely encountered version compatibility issues. The SQLite3 PECL extension version 0.6 is quite old and may not compile cleanly against newer system libraries, even on older OS versions.

When using phpize, the tool generates a Makefile based on your current PHP installation's headers. If you ran sudo make install without ensuring that the resulting .so file was placed in the correct directory (usually /usr/lib/php5/20100412/ or similar depending on the specific sub-version of PHP 5.x), Apache will fail to locate it.

The most reliable fix is to remove any manually compiled versions and reinstall the package version provided by your distribution's repository, which is guaranteed to match your system libraries:

sudo apt-get install --reinstall php5-sqlite3
sudo apache2ctl restart

After the restart, test again with php -m. If the extension loads, your application should function without errors.

Modern Context and Recommendations

While solving this specific error on Ubuntu 12.04 is a matter of legacy maintenance, it is worth noting that PHP 5.x and Ubuntu 12.04 are both End-of-Life (EOL). Continuing to run production applications on unsupported software stacks introduces significant security risks beyond just missing extensions.

For modern Laravel projects or new PHP 8+ applications, the sqlite3 extension is included by default in recent distributions, making manual PECL installations unnecessary unless you require a very specific version of SQLite that isn't available in the OS packages. If you are maintaining an existing legacy codebase, ensure that your .htaccess files (if using Apache) do not inadvertently disable extensions via php_flag engine off or similar directives that might interfere with extension loading.

If you are looking for a more robust way to manage database connections in modern PHP ecosystems, consider the official documentation and resources available at https://laravelcompany.com, which provides guidance on setting up SQLite in Laravel applications using the built-in extensions without needing manual PECL compilation.

Our network