Laravel 5.1找不到SQLite驱动程序

时间:2016-02-27 16:30:53

标签: sqlite laravel pdo driver

我正在使用NGINX和PHP-FPM来提供一个使用SQLite作为我的数据库的Laravel 5.1 Web应用程序。

但是,当我的网络应用尝试创建新用户(来自浏览器)时,我收到异常PDOException in Connector.php line 55: could not find driver。想想我忘了安装/启用一些sqlite包......但是:

我确认安装了SQLite:dpkg --get-selections | grep sqlite

libsqlite0                  install
libsqlite3-0:amd64          install
php5-sqlite                 install
sqlite3                     install

然后检查sqlite是否已启用php -m

[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dba
dom
ereg
exif
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
imagick
intl
json
libxml
mbstring
mhash
openssl
pcntl
pcre
PDO
pdo_sqlite
Phar
posix
readline
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3 <--- there it is!
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlwriter
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache

确保我使用以下内容正确设置权限:sudo chmod 775 database.sqlite

还尝试运行php artisan tinker以查看我是否可以在服务器上重现错误:

\App\User::firstOrCreate(array('id' => 'afasdfadsf', 'name' => 'Matthew Mitchener', 'email' => 'mattjmitchener@gmail.com'));

输出:

App\User {#719
   id: "afasdfadsf",
   name: "Matthew Mitchener",
   email: "mattjmitchener@gmail.com",
   updated_at: "2016-02-27 16:01:25",
   created_at: "2016-02-27 16:01:25",
}

所以似乎工作正常。我作为root用户运行它,也许这是问题的一部分?我不知道我还能尝试什么。

HALP! :(

这里还有整个堆栈跟踪:

in Connector.php line 55
at PDO->__construct('sqlite:/var/www/soqool/database/database.sqlite', null, null, array('0', '2', '0', false, false)) in Connector.php line 55
at Connector->createConnection('sqlite:/var/www/soqool/database/database.sqlite', array('driver' => 'sqlite', 'database' => '/var/www/soqool/database/database.sqlite', 'prefix' => '', 'name' => 'sqlite'), array('0', '2', '0', false, false)) in SQLiteConnector.php line 37
at SQLiteConnector->connect(array('driver' => 'sqlite', 'database' => '/var/www/soqool/database/database.sqlite', 'prefix' => '', 'name' => 'sqlite')) in ConnectionFactory.php line 60
at ConnectionFactory->createSingleConnection(array('driver' => 'sqlite', 'database' => '/var/www/soqool/database/database.sqlite', 'prefix' => '', 'name' => 'sqlite')) in ConnectionFactory.php line 49
at ConnectionFactory->make(array('driver' => 'sqlite', 'database' => '/var/www/soqool/database/database.sqlite', 'prefix' => ''), 'sqlite') in DatabaseManager.php line 175
at DatabaseManager->makeConnection('sqlite') in DatabaseManager.php line 67
at DatabaseManager->connection(null) in Model.php line 3224
at Model::resolveConnection(null) in Model.php line 3190
at Model->getConnection() in Model.php line 1870
at Model->newBaseQueryBuilder() in Model.php line 1813
at Model->newQueryWithoutScopes() in Model.php line 1787
at Model->newQuery() in Model.php line 3435
at Model->__call('firstOrCreate', array(array('id' => '005o0000000yosIAAQ', 'name' => 'Matthew Mitchener', 'email' => 'mattjmitchener@gmail.com')))
at User->firstOrCreate(array('id' => '005o0000000yosIAAQ', 'name' => 'Matthew Mitchener', 'email' => 'mattjmitchener@gmail.com'))
at call_user_func_array(array(object(User), 'firstOrCreate'), array(array('id' => '005o0000000yosIAAQ', 'name' => 'Matthew Mitchener', 'email' => 'mattjmitchener@gmail.com'))) in Model.php line 3451
at Model::__callStatic('firstOrCreate', array(array('id' => '005o0000000yosIAAQ', 'name' => 'Matthew Mitchener', 'email' => 'mattjmitchener@gmail.com'))) in SalesforceAuthentication.php line 33
at User::firstOrCreate(array('id' => '005o0000000yosIAAQ', 'name' => 'Matthew Mitchener', 'email' => 'mattjmitchener@gmail.com')) in SalesforceAuthentication.php line 33
at SalesforceAuthentication->callback() in AuthorizeController.php line 25
at AuthorizeController->callback()
at call_user_func_array(array(object(AuthorizeController), 'callback'), array()) in Controller.php line 256
at Controller->callAction('callback', array()) in ControllerDispatcher.php line 164
at ControllerDispatcher->call(object(AuthorizeController), object(Route), 'callback') in ControllerDispatcher.php line 112
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 114
at ControllerDispatcher->callWithinStack(object(AuthorizeController), object(Route), object(Request), 'callback') in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\AuthorizeController', 'callback') in Route.php line 203
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134
at Route->run(object(Request)) in Router.php line 708
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 710
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 675
at Router->dispatchToRoute(object(Request)) in Router.php line 635
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 122
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 54

正在运行ls -la /etc/php5/fpm/conf.d

total 8
drwxr-xr-x 2 root root 4096 Feb 27 12:27 .
drwxr-xr-x 4 root root 4096 Feb 27 12:18 ..
lrwxrwxrwx 1 root root   32 Feb 24 21:46 05-opcache.ini -> ../../mods-available/opcache.ini
lrwxrwxrwx 1 root root   28 Feb 24 21:46 10-pdo.ini -> ../../mods-available/pdo.ini
lrwxrwxrwx 1 root root   29 Feb 24 21:53 20-curl.ini -> ../../mods-available/curl.ini
lrwxrwxrwx 1 root root   27 Feb 24 21:54 20-gd.ini -> ../../mods-available/gd.ini
lrwxrwxrwx 1 root root   28 Feb 24 21:53 20-gmp.ini -> ../../mods-available/gmp.ini
lrwxrwxrwx 1 root root   32 Feb 24 21:54 20-imagick.ini -> ../../mods-available/imagick.ini
lrwxrwxrwx 1 root root   29 Feb 24 21:53 20-intl.ini -> ../../mods-available/intl.ini
lrwxrwxrwx 1 root root   29 Feb 24 21:46 20-json.ini -> ../../mods-available/json.ini
lrwxrwxrwx 1 root root   35 Feb 27 12:27 20-pdo_sqlite.ini -> ../../mods-available/pdo_sqlite.ini
lrwxrwxrwx 1 root root   33 Feb 24 21:46 20-readline.ini -> ../../mods-available/readline.ini
lrwxrwxrwx 1 root root   32 Feb 27 12:27 20-sqlite3.ini -> ../../mods-available/sqlite3.ini

正在运行:cat /etc/php5/fpm/conf.d/10-pdo.ini

; configuration for php PDO module
; priority=10
extension=pdo.so

2 个答案:

答案 0 :(得分:1)

看来你对cli和web有不同的php.ini。你应该为php.ini添加pdo-sqllite驱动程序用于web并重启Apache或php-fpm。

尝试创建简单文件:

<?php 
echo php_info();

找到php.ini路径。

答案 1 :(得分:0)

问题原来是一些模块没有被php-fpm加载。

使用service php5-fpm restart重新启动fpm不会加载它们。所以我用reboot重新启动了整个服务器并加载了它们。