How to install SQLite for PHP on my Apache/nginx server?

SQLite is a very popular relational database that it is designed to be embedded within software applications. If your server does not already have the SQLite drivers for PHP, please follow the guide below:

Step 1 – Install SQLite driver for your PHP version

Login to your web server via SSH and run the following command:

sudo apt-get install php-sqlite3

If the above command does not work, you can try the PHP version specific instructions below:

For PHP5, use

sudo apt-get install php5-sqlite

For PHP7.0, use

sudo apt-get install php7.0-sqlite

For PHP7.1, use

sudo apt-get install php7.1-sqlite

For PHP7.2, use

sudo apt-get install php7.2-sqlite

For PHP7.3, use

sudo apt-get install php7.3-sqlite

Step 2 – Restart Apache/Nginx

To make SQLite available for PDO usage, we will have to restart Apache/Nginx.

Restart Apache

sudo service apache2 restart

Restart Nginx

sudo service nginx restart

Step 3 – Verify

To test that everything is working fine:

  1. Create a file called test.php with the following content:
    <?php phpinfo(); ?>
  2. Point your browser to test.php where you should see the PHP info file
  3. Search the contents of this file for the string “pdo_sqlite”
  4. If you find a section titled “pdo_sqlite”, it is confirmed that SQLite has been installed
  5. Once the verification is complete delete this file

Was this helpful?