由于公司服务器从Windows服务器换成Linux服务器,在迁移项目的时候,其中一个是thinkphp 3.2.2 写的项目,之前在Windows服务下面运行好好的怎么就一直报如下错误:
No such file or directory
错误位置
FILE: /phpstudy/www/shop.icloudinn.com/ThinkPHP/Library/Think/Db/Driver/MySQL.class.PHP LINE: 55
TRACE
#0 /phpstudy/www/shop.icloudinn.com/ThinkPHP/Library/Think/Db/Driver/Mysql.class.php(55): E('No such file or...')
#1 /phpstudy/www/shop.icloudinn.com/ThinkPHP/Library/Think/Db.class.php(166): Think\Db\Driver\Mysql->connect()
#2 /phpstudy/www/shop.icloudinn.com/ThinkPHP/Library/Think/Db/Driver/Mysql.class.php(92): Think\Db->initConnect(false)
#3 /phpstudy/www/shop.icloudinn.com/ThinkPHP/Library/Think/Db/Driver/Mysql.class.php(211): Think\Db\Driver\Mysql->query('SHOW COLUMNS FR...')
#4 /phpstudy/www/shop.icloudinn.com/ThinkPHP/Library/Think/Model.class.php(130): Think\Db\Driver\Mysql->getFields('st_sys_configs')
#5 /phpstudy/www/shop.icloudinn.com/ThinkPHP/Library/Think/Model.class.php(118): Think\Model->flush()
#6 /phpstudy/www/shop.icloudinn.com/ThinkPHP/Library/Think/Model.class.php(1298): Think\Model->_checkTableInfo()
#7 /phpstudy/www/shop.icloudinn.com/ThinkPHP/Library/Think/Model.class.php(95): Think\Model->db(0, '', true)
#8 /phpstudy/www/shop.icloudinn.com/ThinkPHP/Common/functions.php(521): Think\Model->__construct('System')
#9 /phpstudy/www/shop.icloudinn.com/Apps/Home/Action/BaseAction.class.php(16): D('Home/System')
#10 /phpstudy/www/shop.icloudinn.com/ThinkPHP/Common/functions.php(613): Home\Action\BaseAction->__construct()
#11 /phpstudy/www/shop.icloudinn.com/ThinkPHP/Library/Think/App.class.php(80): controller('Index', '')
#12 /phpstudy/www/shop.icloudinn.com/ThinkPHP/Library/Think/App.class.php(193): Think\App::exec()
#13 /phpstudy/www/shop.icloudinn.com/ThinkPHP/Library/Think/Think.class.php(120): Think\App::run()
#14 /phpstudy/www/shop.icloudinn.com/ThinkPHP/ThinkPHP.php(96): Think\Think::start()
#15 /phpstudy/www/shop.icloudinn.com/index.php(28): require('/phpstudy/www/s...')
#16 {main}
找了半天没有找到一个可靠的答案,是不是Linux对大小写敏感的问题,各种折腾,查看thinkphp官网文档,各种折腾没成功。暂时放我私人Windows服务上面。后面闲下来了,想起了这个坑,这个坑一定要解决才行,于是找到了,有人说了:
出现过类似的情况 要么就是socket目录没有写的权限 通常linux默认是/tmp/mysql.sock
还有一种情况是/tmp目录已满 需要清理磁盘空间。
于是去看了这个目录下mysql.sock ,发现根本没这个文件,于是我自己新建了一个这个文件,为了防止权限干扰,并给了777权限,后来发现不给足权限也可以。再次刷新网站,这次的错误提示变了,一下心情好了很多。
但是还是报如下错:
Permission denied
错误位置
FILE: /phpstudy/www/shop.icloudinn.com/ThinkPHP/Library/Think/Db/Driver/Mysql.class.php LINE: 55
TRACE
#0 /phpstudy/www/shop.icloudinn.com/ThinkPHP/Library/Think/Db/Driver/Mysql.class.php(55): E('Permission deni...')
#1 /phpstudy/www/shop.icloudinn.com/ThinkPHP/Library/Think/Db.class.php(166): Think\Db\Driver\Mysql->connect()
#2 /phpstudy/www/shop.icloudinn.com/ThinkPHP/Library/Think/Db/Driver/Mysql.class.php(92): Think\Db->initConnect(false)
#3 /phpstudy/www/shop.icloudinn.com/ThinkPHP/Library/Think/Db/Driver/Mysql.class.php(211): Think\Db\Driver\Mysql->query('SHOW COLUMNS FR...')
#4 /phpstudy/www/shop.icloudinn.com/ThinkPHP/Library/Think/Model.class.php(130): Think\Db\Driver\Mysql->getFields('st_sys_configs')
#5 /phpstudy/www/shop.icloudinn.com/ThinkPHP/Library/Think/Model.class.php(118): Think\Model->flush()
#6 /phpstudy/www/shop.icloudinn.com/ThinkPHP/Library/Think/Model.class.php(1298): Think\Model->_checkTableInfo()
#7 /phpstudy/www/shop.icloudinn.com/ThinkPHP/Library/Think/Model.class.php(95): Think\Model->db(0, '', true)
#8 /phpstudy/www/shop.icloudinn.com/ThinkPHP/Common/functions.php(521): Think\Model->__construct('System')
#9 /phpstudy/www/shop.icloudinn.com/Apps/Home/Action/BaseAction.class.php(16): D('Home/System')
#10 /phpstudy/www/shop.icloudinn.com/ThinkPHP/Common/functions.php(613): Home\Action\BaseAction->__construct()
#11 /phpstudy/www/shop.icloudinn.com/ThinkPHP/Library/Think/App.class.php(80): controller('Index', '')
#12 /phpstudy/www/shop.icloudinn.com/ThinkPHP/Library/Think/App.class.php(193): Think\App::exec()
#13 /phpstudy/www/shop.icloudinn.com/ThinkPHP/Library/Think/Think.class.php(120): Think\App::run()
#14 /phpstudy/www/shop.icloudinn.com/ThinkPHP/ThinkPHP.php(96): Think\Think::start()
#15 /phpstudy/www/shop.icloudinn.com/index.php(28): require('/phpstudy/www/s...')
#16 {main}
于是继续搜索,有人就说了:如果用的是虚拟主机的话,'DB_HOST' => '',这一项应该填数据库的主机地址,而不是本机地址的localhost或者127.0.0.1。
不管他说得正确与否,至少让我怀疑我的配置文件,于是查看我配置文件'DB_HOST' => 'localhost‘,我想是不是Linux不支持localhost,我改成127.0.0.1上传服务器,刷新网页,久违的界面出来了。
不过,后来我想我是不是走了绕路了,我就把/tmp/mysql.sock 删了,刷新网页正常,心里有一头草泥马蹦过,但我还是怀疑没有走绕路,于是我把原来的配置文件上传了,刷新网页,又出现了第一个报错:
No such file or directory
错误位置
FILE: /phpstudy/www/shop.icloudinn.com/ThinkPHP/Library/Think/Db/Driver/Mysql.class.php LINE: 55
接着上传修改后的配置文件,刷新网页,正常,再次刷新,正常,再次刷新,正常。
综上:只需要改配置文件DB_HOST' => 'localhost‘为DB_HOST' => '127.0.0.1‘,因为你的Linux不支持localhost