I'm attempting to set up a site which uses sqlite3 on a Digital Ocean droplet (I have SSH root access) and I've created a /var/databases/myapp
directory on my Ubuntu VPS to store the sqlite3 db.
However, after uploading a PHP script to test DB access, I get a 500 error. The PHP script is just intended to make sure I can access the sqlite3 db, and looks like this:
myfile.php
$dir = 'sqlite:/var/databases/myapp/mydb.sqlite3';
$dbh = new PDO($dir) or die("There was a problem accessing database. Please contact the admin.");
$stm = $dbh->prepare('SELECT * FROM my_table');
$stm->execute();
$results = $stm->fetchAll(PDO::FETCH_ASSOC);
foreach($results as $result):
var_dump($result);
endforeach;
When I attempt to access this file at myfile.php, I get a 500 error. Can anyone suggest what I may have configured incorrectly that would prevent the PHP file from accessing the database?
I've attempted to activate PHP error logging using the instructions here, but the error_log file I created is empty so I don't think I've configured it correctly.
As someone with little experience setting up servers, I'm very grateful for any help!
EDIT: I found the following in my apache2 error.log [Date time] [:error] [pid xxxx] [client xxx.xx.xxx.x:xxxxx] PHP Fatal error: Uncaught PDOException: could not find driver in /var/www/html/testme.php:5\nStack trace:\n#0 /var/www/html/testme.php(5): PDO->__construct('sqlite:/var/dat...')\n#1 {main}\n thrown in /var/www/html/testme.php on line 5
I think this means I need to install the pdo_sqlite
extension.