今天在搭建微信小程序框架后台服务时(linux+apache+thinkphp5),部署完就随便写了个
namespace app\index\controller;
use think\Db;
class User
{
public function index(){}
public function hello(){
echo "hello";
}
}
然后postman访问,正常,简简单单的打印出hello(= =|||打印出什么其他的就错了)
然后测试小程序,没想到还真出问题了。
报了个500 (Internal Server Error),但是可以看到下面的却是有返回“hello”的。
http 500内部服务器(HTTP-Internal Server Error)错误说明IIS服务器无法解析ASP代码
打开远程控制查看linux,查看了下access_log和error_log都没有异常记录,ssl_error_log才发现
[Mon Jan 07 15:51:45.944980 2019] [:error] [pid 1147] [client 183.63.135.211:60631] PHP Fatal error: Uncaught think\\exception\\ErrorException: error_log(/var/www/html/wechat/runtime/log/201901/07.log): failed to open stream: Permission denied in /var/www/html/wechat/thinkphp/library/think/log/driver/File.php:169\nStack trace:\n#0 [internal function]: think\\Error::appError(2, 'error_log(/var/...', '/var/www/html/w...', 169, Array)\n#1 /var/www/html/wechat/thinkphp/library/think/log/driver/File.php(169): error_log('---------------...', 3, '/var/www/html/w...')\n#2 /var/www/html/wechat/thinkphp/library/think/log/driver/File.php(75): think\\log\\driver\\File->write('---------------...', '/var/www/html/w...', false, true)\n#3 /var/www/html/wechat/thinkphp/library/think/Log.php(179): think\\log\\driver\\File->save(Array, true)\n#4 /var/www/html/wechat/thinkphp/library/think/Error.php(93): think\\Log::save()\n#5 [internal function]: think\\Error::appShutdown()\n#6 {main}\n thrown in /var/www/html/wechat/thinkphp/library/think/log/driver/File.php on line 169, referer: https://servicewechat.com/wx1b6eb90e853ce64c/devtools/page-frame.html
整理下:
[Mon Jan 07 15:51:45.944980 2019] [:error] [pid 1147] [client 183.63.135.211:60631] PHP Fatal error: Uncaught think\\exception\\ErrorException: error_log(/var/www/html/wechat/runtime/log/201901/07.log): failed to open stream:
Permission denied in /var/www/html/wechat/thinkphp/library/think/log/driver/File.php:52
Stack trace:
#0 [internal function]: think\\Error::appError(2, 'mkdir(): Permis...', '/var/www/html/w...', 52, Array)
#1 /var/www/html/wechat/thinkphp/library/think/log/driver/File.php(52): mkdir('/var/www/html/w...', 493, true)
#2 /var/www/html/wechat/thinkphp/library/think/Log.php(179): think\\log\\driver\\File->save(Array, true)
#3 /var/www/html/wechat/thinkphp/library/think/Error.php(93): think\\Log::save()
#4 [internal function]: think\\Error::appShutdown()
#5 {main}\n thrown in /var/www/html/wechat/thinkphp/library/think/log/driver/File.php on line 52, referer: https://servicewechat.com/wx1b6eb90e853ce64c/devtools/page-frame.html
问题很明显了,Permission denied,对于runtime下的log文件failed to open stream,用户没权限操作。
查看runtime文件夹信息:
所属用户是thain,而我们访问是apache来调用的(我用的是apache,这里根据自己情况修改,实在不懂又懒777我也无话可说),所以将所属用户改为apache:
chown -R apache runtime
重新进行访问,正常了!