CakePHP 2.0:数据库连接“Mysql”缺少,或无法创建 [英] CakePHP 2.0 : Database connection "Mysql" is missing, or could not be created
问题描述
在安装CakePHP 2.0(修改,我说,我得到相同的问题,在干净的安装cakephp 2.0)我发现自己面对一个错误,我还没有能够解决。
配置:
服务器:debian weezy 7
用户:测试
wwwjail / siteroot / test / htdocs / [app /...]
nginx配置
cat / etc / nginx / sites-available / test
$ b listen IP:80 default;
server_name domain.fr;
access_log /var/log/nginx/test.access.log;
error_log /var/log/nginx/test.error.log;
autoindex off;
index index.php index.html;
root / wwwjail / siteroot / test / htdocs /;
location〜\.php $ {
try_files $ uri = 404;
fastcgi_intercept_errors on;
fastcgi_pass unix:/wwwjail/siteroot/test/php-fpm.sock;
include / etc / nginx / fastcgi_params;
fastcgi_param SCRIPT_FILENAME $ fastcgi_script_name;
}
}
php5-fpm配置
cat /etc/php5/fpm/pool.d/test.conf
[test]
listen = /wwwjail/siteroot/test/php-fpm.sock
chroot = / wwwjail / siteroot / test / htdocs
user = test
group = test
listen.allowed_clients = 127.0.0.1
listen.owner = test
listen.group = test
listen.backlog = -1
PM =动态
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_requests = 200
pm.status_path = / status_31337
request_terminate_timeout = 30秒
catch_workers_output = YES
php_value [的session.save_path = / tmp目录
$ c $ p>
页面上可见的错误:
数据库连接Mysql缺失或无法创建。
错误:发生了内部错误。
堆栈跟踪
ROOTlibROOTCakeROOTModelROOTDatasourceROOTDboSource.php线262→Mysql->连接()
ROOTlibROOTCakeROOTModelROOTConnectionManager.php线107→DboSource-> __构造(数组)
ROOTlibROOTCakeROOTModelROOTModel .PHP线3221→::的ConnectionManager了getDataSource(字符串)
ROOTlibROOTCakeROOTModelROOTModel.php线1108→型号 - >的setDataSource(字符串)
ROOTlibROOTCakeROOTModelROOTModel.php线3243→型号 - >的SetSource(字符串)
ROOTlibROOTCakeROOTModelROOTModel.php线2696→型号 - >了getDataSource()
ROOTappROOTControllerROOTAppController.php线70→型号 - >发现(字符串数组)
ROOTappROOTControllerROOTChallengesController.php线57→AppController-> beforeFilter ()
[内部功能]→ChallengesController-> beforeFilter(CakeEvent)
ROOTlibROOTCakeROOTEventROOTCakeEventManager.php线248→call_user_func(数组,CakeEvent)
ROOTlibROOTCakeROOTControllerROOTController.php线670→CakeEventManager->调度(CakeEvent)
ROOTlibROOTCakeROOTRoutingROOTDispatcher.php线184→控制器 - > startupProcess()
ROOTlibROOTCakeROOTRoutingROOTDispatcher.php线162→Dispatcher-> _invoke(ChallengesController,CakeRequest,CakeResponse)
ROOTappROOTwebrootROOTindex.php线109→Dispatcher->讯(CakeRequest,CakeResponse)
ROOTindex.php线43→需要(字符串)
CakePHP的:快速发展的PHP框架
Nginx错误日志nginx :
2013/12/24 12:23:03 [error] 17792#0:* 535 open()/wwwjail/siteroot/test/htdocs/css/default.css失败(2:没有文件或目录),客户端:myIP,服务器:domain.fr,请求:GET /css/default.css HTTP / 1.1,主机:IP:80,引用:http:// IP:80 /
2013/12/24 12:23:03 [error] 17792#0:* 536 open()/wwwjail/siteroot/test/htdocs/css/bootstrap.css失败(2:没有这样的文件或目录),客户端:myIP,服务器:domain.fr,请求:GET /css/bootstrap.css HTTP / 1.1,主机:IP:80,引用:http:// IP:80 / $ b 2013/12/24 12:23:03 [error] 17792#0:* 537 open()/wwwjail/siteroot/test/htdocs/css/jqplot.css失败(2:没有这样的文件或目录) ,client:myIP,server:domain.fr,request:GET /css/jqplot.css HTTP / 1.1,host:IP:80,referrer:http:// IP:80 /
2013/12/24 12:23:03 [错误] 17792#0:* 538 open()/wwwjail/siteroot/test/htdocs/js/jqplot.js失败(2:没有这样的文件或目录),客户端:myIP,server:domain.fr,request:GET /js/jqplot.js HTTP / 1.1,host:IP:80,referrer:http:// IP:80 /
2013 / 12/24 12:23:03 [错误] 17792#0:* 534 open()/wwwjail/siteroot/test/htdocs/js/holder.js失败(2:没有这样的文件或目录),客户端:myIP ,server:domain.fr,request:GET /js/holder.js HTTP / 1.1,host:IP:80,referrer:http:// IP:80 /
2013 / 24 12:23:03 [错误] 17792#0:* 531 open()/wwwjail/siteroot/test/htdocs/css/cake.generic.css失败(2:没有这样的文件或目录),客户端:myIP ,server:domain.fr,request:GET /css/cake.generic.css HTTP / 1.1,host:IP:80,referrer:http:// IP:80 /
2013 / 12/24 12:23:03 [错误] 17792#0:* 531 open()/wwwjail/siteroot/test/htdocs/img/cake.power.gif失败(2:没有这样的文件或目录),客户端:myIP,server:domain.fr,request:GET /img/cake.power.gif HTTP / 1.1,host:IP:80,referrer:http:// IP:80 /
2013/12/24 12:23:03 [错误] 17792#0:* 535 open()/wwwjail/siteroot/test/htdocs/js/jqplot.js失败(2:没有这样的文件或目录),客户端:myIP,server:domain.fr,request:GET /js/jqplot.js HTTP / 1.1,host:IP:80,referrer:http:// IP:80 /
2013 / 12/24 12:23:03 [错误] 17792#0:* 531 open()/wwwjail/siteroot/test/htdocs/js/holder.js失败(2:没有这样的文件或目录),客户端:myIP ,server:domain.fr,request:GET /js/holder.js HTTP / 1.1,host:IP:80,referrer:http:// IP:80 /
2013 / 24 12:23:03 [错误] 17792#0:* 531 open()/wwwjail/siteroot/test/htdocs/css/cake.generic.css失败(2:没有这样的文件或目录),客户端:myIP ,server:domain.fr,request:GET /css/cake.generic.css HTTP / 1.1,host:IP:80,referrer:http:// IP:80 /
2013 / 12/24 12:23:03 [错误] 17792#0:* 531 open()/wwwjail/siteroot/test/htdocs/img/cake.power.gif失败(2:没有这样的文件或目录),客户端:myIP,server:domain.fr,request:GET /img/cake.power.gif HTTP / 1.1,host:IP:80,referrer:http:// IP:80 /
在 mysql数据库凭据正确,用户mysql用户测试存在,测试。
cat /wwwjail/siteroot/test/htdocs/app/Config/database.php
class DATABASE_CONFIG {
public $ default = array(
'datasource'=> 'Database / Mysql',
'persistent'=> false,
'host'=> '127.0.0.1',
'login'=> 'user-test',
'password'=> 'mypassword',
'database'=> 'test',
'prefix'=> '',
'encoding'=> 'utf8'
);
}
检查与CakePHP的配置文件stackoverflow)
<?php
include(app / Config / database.php) ;
$ config = new DATABASE_CONFIG();
$ name ='default';
$ settings = $ config-> {$ name};
$ dsn ='mysql:dbname ='。$ settings ['database']。'; host ='。$ settings ['host'];
$ user = $ settings ['login'];
$ password = $ settings ['password'];
try {
$ dbh = new PDO($ dsn,$ user,$ password);
echo使用dsn:连接成功。 $ dns。 \\\
;
$ sql ='SELECT id,title FROM posts';
echo这里是表的内容`posts:;
foreach($ dbh-> query($ sql)as $ row){
print $ row ['id']。 \t。 $ row ['title']。 \\\
;
}
} catch(PDOException $ e){
echo'PDO error:'。 $ e-> getMessage();
}
?>
====>返回:连接成功与dsn:mysql:dbname = test; host = 127.0.0.1这里是表的内容
posts:`
/ strong>
* grep -i'default_socket'/etc/php5/fpm/php.ini *
default_socket_timeout = 60
pdo_mysql.default_socket = /wwwjail/var/run/mysqld/mysqld.sock
mysql.default_socket = / wwwjail / var / run / mysqld / mysqld.sock
mysqli.default_socket = /wwwjail/var/run/mysqld/mysqld.sock
验证PDO扩展的存在。
var_dump(extension_loaded('pdo_mysql') );
return => bool(true)
我希望我提供了很多关于我的问题的信息。我愿意执行各种操纵来测试。 (我认为一个问题服务器端配置必然,虽然这个配置适用于连接到mysql的其他基本应用程序)。
真诚。
解决方案在您的 /app/Config/database.php 文件中,
更改以下行:
'host'=> 'localhost',
到:
'host'=> '127.0.0.1',
following the installation of CakePHP 2.0 (modified, I said that I get the same problem on a clean install of cakephp 2.0) I found myself facing an error I have not been able to solve.
configuration:
server : debian weezy 7
user : test
structure : /wwwjail/siteroot/test/htdocs/[app/...]
nginx configuration
cat /etc/nginx/sites-available/test
server {
listen IP:80 default;
server_name domain.fr;
access_log /var/log/nginx/test.access.log;
error_log /var/log/nginx/test.error.log;
autoindex off;
index index.php index.html;
root /wwwjail/siteroot/test/htdocs/;
location ~ \.php$ {
try_files $uri =404;
fastcgi_intercept_errors on;
fastcgi_pass unix:/wwwjail/siteroot/test/php-fpm.sock;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
}
}
php5-fpm configuration
cat /etc/php5/fpm/pool.d/test.conf
[test]
listen = /wwwjail/siteroot/test/php-fpm.sock
chroot = /wwwjail/siteroot/test/htdocs
user = test
group = test
listen.allowed_clients = 127.0.0.1
listen.owner = test
listen.group = test
listen.backlog = -1
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_requests = 200
pm.status_path = /status_31337
request_terminate_timeout = 30s
catch_workers_output = yes
php_value[session.save_path] = /tmp
Visible errors on the page:
Database connection "Mysql" is missing, or could not be created.
Error: An Internal Error Has Occurred.
Stack Trace
ROOTlibROOTCakeROOTModelROOTDatasourceROOTDboSource.php line 262 → Mysql->connect()
ROOTlibROOTCakeROOTModelROOTConnectionManager.php line 107 → DboSource->__construct(array)
ROOTlibROOTCakeROOTModelROOTModel.php line 3221 → ConnectionManager::getDataSource(string)
ROOTlibROOTCakeROOTModelROOTModel.php line 1108 → Model->setDataSource(string)
ROOTlibROOTCakeROOTModelROOTModel.php line 3243 → Model->setSource(string)
ROOTlibROOTCakeROOTModelROOTModel.php line 2696 → Model->getDataSource()
ROOTappROOTControllerROOTAppController.php line 70 → Model->find(string, array)
ROOTappROOTControllerROOTChallengesController.php line 57 → AppController->beforeFilter()
[internal function] → ChallengesController->beforeFilter(CakeEvent)
ROOTlibROOTCakeROOTEventROOTCakeEventManager.php line 248 → call_user_func(array, CakeEvent)
ROOTlibROOTCakeROOTControllerROOTController.php line 670 → CakeEventManager->dispatch(CakeEvent)
ROOTlibROOTCakeROOTRoutingROOTDispatcher.php line 184 → Controller->startupProcess()
ROOTlibROOTCakeROOTRoutingROOTDispatcher.php line 162 → Dispatcher->_invoke(ChallengesController, CakeRequest, CakeResponse)
ROOTappROOTwebrootROOTindex.php line 109 → Dispatcher->dispatch(CakeRequest, CakeResponse)
ROOTindex.php line 43 → require(string)
CakePHP: the rapid development php framework
Nginx Error log nginx :
2013/12/24 12:23:03 [error] 17792#0: *535 open() "/wwwjail/siteroot/test/htdocs/css/default.css" failed (2: No such file or directory), client: myIP, server: domain.fr, request: "GET /css/default.css HTTP/1.1", host: "IP:80", referrer: "http://IP:80/"
2013/12/24 12:23:03 [error] 17792#0: *536 open() "/wwwjail/siteroot/test/htdocs/css/bootstrap.css" failed (2: No such file or directory), client: myIP, server: domain.fr, request: "GET /css/bootstrap.css HTTP/1.1", host: "IP:80", referrer: "http://IP:80/"
2013/12/24 12:23:03 [error] 17792#0: *537 open() "/wwwjail/siteroot/test/htdocs/css/jqplot.css" failed (2: No such file or directory), client: myIP, server: domain.fr, request: "GET /css/jqplot.css HTTP/1.1", host: "IP:80", referrer: "http://IP:80/"
2013/12/24 12:23:03 [error] 17792#0: *538 open() "/wwwjail/siteroot/test/htdocs/js/jqplot.js" failed (2: No such file or directory), client: myIP, server: domain.fr, request: "GET /js/jqplot.js HTTP/1.1", host: "IP:80", referrer: "http://IP:80/"
2013/12/24 12:23:03 [error] 17792#0: *534 open() "/wwwjail/siteroot/test/htdocs/js/holder.js" failed (2: No such file or directory), client: myIP, server: domain.fr, request: "GET /js/holder.js HTTP/1.1", host: "IP:80", referrer: "http://IP:80/"
2013/12/24 12:23:03 [error] 17792#0: *531 open() "/wwwjail/siteroot/test/htdocs/css/cake.generic.css" failed (2: No such file or directory), client: myIP, server: domain.fr, request: "GET /css/cake.generic.css HTTP/1.1", host: "IP:80", referrer: "http://IP:80/"
2013/12/24 12:23:03 [error] 17792#0: *531 open() "/wwwjail/siteroot/test/htdocs/img/cake.power.gif" failed (2: No such file or directory), client: myIP, server: domain.fr, request: "GET /img/cake.power.gif HTTP/1.1", host: "IP:80", referrer: "http://IP:80/"
2013/12/24 12:23:03 [error] 17792#0: *535 open() "/wwwjail/siteroot/test/htdocs/js/jqplot.js" failed (2: No such file or directory), client: myIP, server: domain.fr, request: "GET /js/jqplot.js HTTP/1.1", host: "IP:80", referrer: "http://IP:80/"
2013/12/24 12:23:03 [error] 17792#0: *531 open() "/wwwjail/siteroot/test/htdocs/js/holder.js" failed (2: No such file or directory), client: myIP, server: domain.fr, request: "GET /js/holder.js HTTP/1.1", host: "IP:80", referrer: "http://IP:80/"
2013/12/24 12:23:03 [error] 17792#0: *531 open() "/wwwjail/siteroot/test/htdocs/css/cake.generic.css" failed (2: No such file or directory), client: myIP, server: domain.fr, request: "GET /css/cake.generic.css HTTP/1.1", host: "IP:80", referrer: "http://IP:80/"
2013/12/24 12:23:03 [error] 17792#0: *531 open() "/wwwjail/siteroot/test/htdocs/img/cake.power.gif" failed (2: No such file or directory), client: myIP, server: domain.fr, request: "GET /img/cake.power.gif HTTP/1.1", host: "IP:80", referrer: "http://IP:80/"
On the mysql database credentials are correct, the user mysql user-test exist and full access to test.*
cat /wwwjail/siteroot/test/htdocs/app/Config/database.php
class DATABASE_CONFIG {
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => '127.0.0.1',
'login' => 'user-test',
'password' => 'mypassword',
'database' => 'test',
'prefix' => '',
'encoding' => 'utf8'
);
}
Checking the connection with the config file of CakePHP (script found on stackoverflow)
<?php
include("app/Config/database.php");
$config= new DATABASE_CONFIG();
$name = 'default';
$settings=$config->{$name};
$dsn = 'mysql:dbname='.$settings['database'].';host='.$settings['host'];
$user = $settings['login'];
$password = $settings['password'];
try {
$dbh = new PDO($dsn, $user, $password);
echo "Connection succeeded with dsn: ". $dsn . "\n";
$sql = 'SELECT id, title FROM posts';
echo "Here is the contents of the table `posts:";
foreach ($dbh->query($sql) as $row) {
print $row['id'] . "\t" . $row['title'] . "\n";
}
} catch (PDOException $e) {
echo 'PDO error: ' . $e->getMessage();
}
?>
====> return: Connection succeeded with dsn: mysql:dbname=test;host=127.0.0.1 Here is the contents of the table
posts:`
Checking socket with php.ini
*grep -i 'default_socket' /etc/php5/fpm/php.ini*
default_socket_timeout = 60
pdo_mysql.default_socket= /wwwjail/var/run/mysqld/mysqld.sock
mysql.default_socket = /wwwjail/var/run/mysqld/mysqld.sock
mysqli.default_socket = /wwwjail/var/run/mysqld/mysqld.sock
Verification of the existence of the PDO extension.
var_dump( extension_loaded('pdo_mysql') );
return => bool(true)
I hope I have provided much information about my problem. I am willing to perform various manipulations to test. (I think a problem server side configuration necessarily, although this configuration works for other basic applications connecting to mysql also).
Sincerely.
解决方案 In your /app/Config/database.php file,
change the following line:
'host' => 'localhost',
to:
'host' => '127.0.0.1',
这篇关于CakePHP 2.0:数据库连接“Mysql”缺少,或无法创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!