CakePHP 4 Error: Database driver Cake\Database\Driver\Sqlite cannot be used

Reading Time: 6 minutes
7,914 Views

Inside this article we will see how to fix a CakePHP 4 error i.e Database driver Cake\Database\Driver\Sqlite cannot be used due to a missing PHP extension or unmet dependency. Requested by connection “test”.

Article contains classified information about to fix this issue. To fix this issue you need to take care of the cases in which you are facing the issue. We will discuss all the cases here.

When you install CakePHP 4 and start development server, probably you will see this error into very fifirst screen. We will see here about fixing this “Database driver Cake\Database\Driver\Sqlite cannot be used due to a missing PHP extension” issue.

Learn More –

Let’s get started.


CakePHP 4 Installation

To create a CakePHP project, run this command into your shell or terminal. Make sure composer should be installed in your system.

$ composer create-project --prefer-dist cakephp/app:~4.0 mycakephp

Above command will creates a project with the name called mycakephp.


Start Development Server

Open project into terminal and run this command.

$ bin/cake server --port 8080

URL: http://localhost:8080/

If everything is Okay, then you will get the landing page.

Otherwise you will see this error page.

To fix this issue we need to assume few cases –

  • Check and install sqlite package for your Nginx or Apache server
  • Check CakePHP DebugKit
  • Check test connection of database source

Case #1: Check and install sqlite package for your Nginx or Apache server

Step 1 – Install SQLite driver for your PHP version

Log in 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

For PHP7.4, use

sudo apt-get install php7.4-sqlite

In general, you have to insert the PHP version in the command and below is the syntax for how the command will look:

sudo apt-get install php[x.y]-sqlite3

(Without square brackets) where x is the major version and y is the minor version. for example, php7.1, php7.4, etc. Do note that this method is NOT applicable to PHP 5

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. Create a file called test.php with the following content:

<?php phpinfo(); ?>

Search the contents of this file for the string “pdo_sqlite” into output screen.

Case #2: Check CakePHP DebugKit

We need to disable DebugKit inside CakePHP application.

Open Application.php from /src folder.

public function bootstrap(): void
{
    //...

    /*
        * Only try to load DebugKit in development mode
        * Debug Kit should not be installed on a production system
        */
    if (Configure::read('debug')) {
        //$this->addPlugin('DebugKit');
    }

    //...
}

When you comment DebugKit plugin then you will get the landing page as expected.

Case #3: Check test connection of database source

As you can see inside second case we have disabled DebugKit plugin from application. It means we will not be able to use it.

In this case you need to remove test connection from app_local.php which is inside /config folder.

//...

'Datasources' => [
 
    /*
         * The test connection is used during the test suite.
         */
        'test' => [
            'host' => 'localhost',
            //'port' => 'non_standard_port_number',
            'username' => 'my_app',
            'password' => 'secret',
            'database' => 'test_myapp',
            //'schema' => 'myapp',
            'url' => env('DATABASE_TEST_URL', 'sqlite://127.0.0.1/tests.sqlite'),
        ],

]
  
//...  
  

As we can see we have test connection. Remove test group from Datasources. Also in this case we don’t need to comment DebugKit plugin from Application.php

We hope this article helped you to learn How To fix CakePHP 4 Database driver CakeDatabaseDriverSqlite cannot be used due to a missing PHP extension or unmet dependency. Requested by connection “test” in a very detailed way.

Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.

Sanjay KumarHello friends, I am Sanjay Kumar a Web Developer by profession. Additionally I'm also a Blogger, Youtuber by Passion. I founded Online Web Tutor and Skillshike platforms. By using these platforms I am sharing the valuable knowledge of Programming, Tips and Tricks, Programming Standards and more what I have with you all. Read more