问题:
环境:Ubuntu系统,xampp1.8.3-5建站工具
描述:以root的身份运行。Apache的 DocumentRoot = "/var/www" 。thinkphp的安装包直接放在该目录下面,浏览器访问:http://127.0.0.1/htdocs/thinkphp/public/,出现提示:
Fatal error: Uncaught exception 'think\exception\ErrorException' with message 'error_log(/var/www/htdocs/thinkphp/public/../runtime/log/16_10_28.log): failed to open stream: 权限不够' in /var/www/htdocs/thinkphp/thinkphp/library/think/log/driver/File.php:78 Stack trace: #0 [internal function]: think\Error::appError(2, 'error_log(/var/...', '/var/www/htdocs...', 78, Array)
#1 /var/www/htdocs/thinkphp/thinkphp/library/think/log/driver/File.php(78): error_log('[ 2016-10-28T22...', 3, '/var/www/htdocs...')
#2 /var/www/htdocs/thinkphp/thinkphp/library/think/Log.php(149): think\log\driver\File->save(Array)
#3 /var/www/htdocs/thinkphp/thinkphp/library/think/Error.php(84): think\Log::save()
#4 [internal function]: think\Error::appShutdown() #5 {main} thrown in /var/www/htdocs/thinkphp/thinkphp/library/think/log/driver/File.php on line 78
#1 /var/www/htdocs/thinkphp/thinkphp/library/think/log/driver/File.php(78): error_log('[ 2016-10-28T22...', 3, '/var/www/htdocs...')
#2 /var/www/htdocs/thinkphp/thinkphp/library/think/Log.php(149): think\log\driver\File->save(Array)
#3 /var/www/htdocs/thinkphp/thinkphp/library/think/Error.php(84): think\Log::save()
#4 [internal function]: think\Error::appShutdown() #5 {main} thrown in /var/www/htdocs/thinkphp/thinkphp/library/think/log/driver/File.php on line 78
解决:
涉及linux系统的文件的两个属性:文件的拥有者和文件的用户组,以及程序的执行权限问题。
程序没有权限在DocumentRoot目录及其子目录使用mkdir函数,新建目录,而Apache的发布目录的文件拥有者和归属组都是root。查看可执行程序文件的上面两个文件属性。
整个系统的运行,都是有Apache启动,查看其服务进程。
ps -ef | grep "httpd"
Apache的启动进程属于daemon用户,Apache的发布目录并没有开放权限给其他用户或者同组用户相应的执行或者写权限。
执行:
chown -R daemon:daemon /var/www/
解决权限问题的过程中,发现Apache的发布目录最好定位到ThinkPHP的public目录,不然访问会出现问题,这是良好的习惯。