简体   繁体   English

Laravel对Apache的文件权限

[英]Laravel file permissions for Apache

I'm installing a Laravel app on a Centos 7 distro. 我正在Centos 7发行版上安装Laravel应用。 I'm using PHP 7.2 and I've successfully installed apache and my project. 我正在使用PHP 7.2,并且已经成功安装了apache和我的项目。

I was able to get the Apache splash page to show but as soon as I point my virtual host to my laravel public folder I get file permission errors in apache2 logs. 我能够显示Apache启动页面,但将虚拟主机指向laravel公共文件夹后,我立即在apache2日志中收到文件许可权错误。

I've made both my public and storage folders read/write/executable by all for a short period and I am still getting the errors. 我已经使公共文件夹和存储文件夹在短时间内可以所有人读取/写入/执行,但仍然出现错误。

My virtual host: 我的虚拟主机:

<VirtualHost *:80>

DocumentRoot /var/www/html/checkers/public

<Directory /var/www/html/checkers/public>
    Options +Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
    </Directory>

My permissions (after temporary chmod 777 on public and bootstrap): 我的权限(在公共和引导程序上临时使用chmod 777之后):

drwxr-xr-x. 13 root root   4096 Jul  6 03:16 .

drwxr-xr-x.  3 root root     22 Jul  6 03:16 ..

drwxr-xr-x.  6 root root    106 Jul  6 03:16 app

-rw-r--r--.  1 root root   1686 Jul  6 03:16 artisan

drwxrwxrwx.  3 root root     34 Jul  6 03:16 bootstrap

-rw-r--r--.  1 root root   1477 Jul  6 03:16 composer.json

-rw-r--r--.  1 root root 143918 Jul  6 03:16 composer.lock

drwxr-xr-x.  2 root root    247 Jul  6 03:16 config

drwxr-xr-x.  5 root root     72 Jul  6 03:16 database

-rw-r--r--.  1 root root    651 Jul  6 03:16 .env.example

drwxr-xr-x.  8 root root    198 Jul  6 03:22 .git

-rw-r--r--.  1 root root    111 Jul  6 03:16 .gitattributes

-rw-r--r--.  1 root root    155 Jul  6 03:16 .gitignore

-rw-r--r--.  1 root root   1022 Jul  6 03:16 package.json

-rw-r--r--.  1 root root   1134 Jul  6 03:16 phpunit.xml

drwxrwxrwx.  4 root root    116 Jul  6 03:16 public

-rw-r--r--.  1 root root   3675 Jul  6 03:16 readme.md

drwxr-xr-x.  5 root root     45 Jul  6 03:16 resources

drwxr-xr-x.  2 root root     75 Jul  6 03:16 routes

-rw-r--r--.  1 root root    563 Jul  6 03:16 server.php

drwxr-xr-x.  5 root root     46 Jul  6 03:16 storage

drwxr-xr-x.  4 root root     83 Jul  6 03:16 tests

drwxr-xr-x. 37 root root   4096 Jul  6 03:22 vendor

-rw-r--r--.  1 root root    549 Jul  6 03:16 webpack.mix.js

The errors in /etc/httpd/logs/error_log: / etc / httpd / logs / error_log中的错误:

[php7:error] [pid 9120] [client 192.168.10.1:46658] PHP Fatal error: Uncaught ErrorException: file_put_contents(/var/www/html/checkers/storage/framework/views/27ab4a7b5ea3854dc076406e3c218364a7743be0.php): failed to open stream: Permission denied in /var/www/html/checkers/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:122\\nStack trace:\\n#0 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(2, 'file_put_conten...', '/var/www/html/c...', 122, Array)\\n#1 /var/www/html/checkers/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(122): file_put_contents('/var/www/html/c...', 's...', 0)\\n#2 /var/www/html/checkers/vendor/laravel/framework/src/Illuminate/View/Compilers/BladeCompiler.php(122): Illuminate\\Filesystem\\Filesystem->put('/var/www/html/c...', 's...')\\n#3 /var/www/html/checkers/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(51): Illuminate\\View\\Compilers\\BladeCompiler->compile('/var/www/html/c...' [php7:错误] [pid 9120] [客户端192.168.10.1:46658] PHP致命错误:未捕获的ErrorException:file_put_contents(/var/www/html/checkers/storage/framework/views/27ab4a7b5ea3854dc076406e3c218364a7743be0.php):无法打开流:/var/www/html/checkers/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:122\\nStack trace:\\ n#0 [内部功能]:Illuminate \\ Foundation \\ Bootstrap \\ HandleExceptions拒绝的权限-> handleError(2,'file_put_conten ...','/ var / www / html / c ...',122,Array)\\ n#1 / var / www / html / checkers / vendor / laravel / framework / src / Illuminate / Filesystem / Filesystem.php(122):file_put_contents('/ var / www / html / c ...','s ...',0)\\ n#2 / var / www / html / checkers /vendor/laravel/framework/src/Illuminate/View/Compilers/BladeCompiler.php(122):Illuminate \\ Filesystem \\ Filesystem-> put('/ var / www / html / c ...','s ... ')\\ n#3 /var/www/html/checkers/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(51):Illuminate \\ View \\ Compilers \\ BladeCompiler-> compile('/ var / www / html / c ...” )\\n#4 /var/www/html/checkers/vendor/laravel/framework/src/Illuminate/Vi in /var/www/html/checkers/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php on line 122 [Fri Jul 06 03:41:01.295172 2018] [php7:error] [pid 9120] [client 192.168.10.1:46658] PHP Fatal error: Uncaught ErrorException: file_put_contents(/var/www/html/checkers/storage/framework/views/27ab4a7b5ea3854dc076406e3c218364a7743be0.php): failed to open stream: Permission denied in /var/www/html/checkers/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:122\\nStack trace:\\n#0 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(2, 'file_put_conten...', '/var/www/html/c...', 122, Array)\\n#1 /var/www/html/checkers/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(122): file_put_contents('/var/www/html/c...', 's...', 0)\\n#2 /var/www/html/checkers/vendor/laravel/framework/src/Illuminate/View/Compilers/BladeCompiler.php(122): Illuminate\\Filesystem\\Filesyste )\\ n#4 /var/www/html/checkers/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php中的/ var / www / html / checkers / vendor / laravel / framework / src / Illuminate / Vi在第122行[2018年7月6日星期五03:41:01.295172] [php7:错误] [pid 9120] [客户端192.168.10.1:46658] PHP致命错误:未捕获的ErrorException:file_put_contents(/ var / www / html / checkers / storage /framework/views/27ab4a7b5ea3854dc076406e3c218364a7743be0.php):无法打开流:/var/www/html/checkers/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:122\\n堆栈跟踪:\\ n #0 [内部功能]:Illuminate \\ Foundation \\ Bootstrap \\ HandleExceptions-> handleError(2,'file_put_conten ...','/ var / www / html / c ...',122,Array)\\ n#1 / var / www / html / checkers / vendor / laravel / framework / src / Illuminate / Filesystem / Filesystem.php(122):file_put_contents('/ var / www / html / c ...','s ...', 0)\\ n#2 /var/www/html/checkers/vendor/laravel/framework/src/Illuminate/View/Compilers/BladeCompiler.php(122):Illuminate \\ Filesystem \\ Filesyste m->put('/var/www/html/c...', 's...')\\n#3 /var/www/html/checkers/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(51): Illuminate\\View\\Compilers\\BladeCompiler->compile('/var/www/html/c...')\\n#4 /var/www/html/checkers/vendor/laravel/framework/src/Illuminate/Vi in /var/www/html/checkers/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php on line 122 m-> put('/ var / www / html / c ...','s ...')\\ n#3 / var / www / html / checkers / vendor / laravel / framework / src / Illuminate / View /Engines/CompilerEngine.php(51):Illuminate\\View\\Compilers\\BladeCompiler->compile('/var/www/html/c...')\\n#4 / var / www / html / checkers / vendor /第122行的/var/www/html/checkers/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php中的laravel / framework / src / Illuminate / Vi

Edit: I've sudo chmod -R 777 /var/ (temporarily) and I still get these permission errors. 编辑:我已经sudo chmod -R 777 / var /(临时),我仍然收到这些权限错误。

Assign the owner to all directories to your username and group to www-data . 将所有目录的所有者分配给您的用户名,并将组分配给www-data Assuming your apache group www-data and my-user is your username 假设您的apache组www-datamy-user是您的用户名

sudo chown -R my-user:www-data /path/to/your/laravel/root/directory

Then change the file and directory permission like this 然后像这样更改文件和目录权限

sudo find /path/to/your/laravel/root/directory -type f -exec chmod 664 {} \;    
sudo find /path/to/your/laravel/root/directory -type d -exec chmod 775 {} \;

Details you can check here File permissions for Laravel 5 (and others) 您可以在此处查看详细信息Laravel 5(及其他)的文件权限

Thank you for the help. 感谢您的帮助。 It turns out I was setting the permissions successfully but they were being overridden by Centos. 事实证明,我已经成功设置了权限,但是它们被Centos覆盖。

sudo setenforce 0

The above worked for me. 以上为我工作。

Have you changed permissions recursively? 您是否递归更改了权限?

try: 尝试:

chmod -R 777 /var/www/html/checkers/storage
chmod -R 777 /var/www/html/checkers/bootstrap

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM