gpt4 book ai didi

Unable to create lockable file - Laravel 8 & PHP 8(无法创建可锁定文件-Laravel 8和PHP 8)

转载 作者:bug小助手 更新时间:2023-10-28 21:26:48 25 4
gpt4 key购买 nike



I'm stuck in a Laravel project, I've been using laravel a lot of years and never happened this.

我被困在了一个Laravel项目中,我已经使用Laravel很多年了,从来没有发生过这种情况。


I'm using Vagrant (as always) and only happens this with PHP 8, with other projects with php 7.X doesn't happen.

我使用的是Vagant(一如既往),只有在PHP8上才会发生这种情况,而在PHP7.x上的其他项目就不会发生这种情况。


enter image description here


The USER and GROUP permisions are OK as always. I Ran chmod -R 777 storage and bootstrap/cache a lot of times.
I ran all cache:clear.

用户和组权限一如既往地正常。我多次运行chmod-R777存储和引导/缓存。我运行了所有缓存:清除。


I don't know why it's happening this.

我不知道为什么会发生这样的事。


Anyone had problems with Laravel and PHP 8?

有人对Laravel和PHP8有问题吗?


Thanks!

谢谢!


更多回答

What have you tried to resolve the problem? If you try to create that file manually, does it work? Also, what exactly has changed between the last working state and the broken one?

你试过什么来解决这个问题?如果您尝试手动创建该文件,它是否有效?还有,上一次工作状态和坏掉的状态到底发生了什么变化?

@NicoHaase The file exists, and if I run cache:clear it happens again with another file. This only happens with PHP8. (It's a new project, but I have another project with php8 and also had problems with storage permissions)

@NicoHaase该文件存在,如果我运行CACHE:CLEAR,另一个文件将再次发生这种情况。这只会发生在PHP8上。(这是一个新项目,但我有另一个php8项目,存储权限也有问题)

@RizkyArlin no mate... I resolved some session and cache problems using database and Redis instead of the filesystem, but with storage still, fail. I think maybe it's with my homestead machine because I didn't see more people with the same problem. I will try Laravel valet and see if it works

@RizkyArlin没有大副...我使用数据库和Redis而不是文件系统解决了一些会话和缓存问题,但存储仍然失败。我想可能是我的宅基地机器出了问题,因为我没有看到更多的人有同样的问题。我会试着用拉威尔代客,看看它是否管用

I have the same issue in production with laravel 8 and php 7.4. it is sporadic and indeed always temporarily fixed by the chmod per above but later recurs as somehow laravel creates a new cache dir owned by root. This is clearly a bug. Does anyone have a Permanent fix?

我在用laravel 8和php 7.4进行生产时也遇到了同样的问题。它是零星的,实际上总是由上面的chmod per临时修复,但后来随着laravel以某种方式创建了一个由根拥有的新缓存目录而反复出现。这显然是一个漏洞。有没有人有永久的解决办法?

@Daryl, have you tried creating a dir owned by root? Something is running as root there, a cronjob or someone with SSH access running service tasks there. PHP doesn't randomly create directories you can't create by normal means. This question lacks a minimal reproducible example. There are too many pieces of the puzzle missing.

@Daryl,你试过创建根用户拥有的目录吗?某个用户以超级用户身份在那里运行,cronjob或具有SSH访问权限的人在那里运行服务任务。PHP不会随机创建您不能通过正常方式创建的目录。这个问题缺少一个最小的可重复使用的例子。有太多的拼图遗失了。

优秀答案推荐

Can you please try with the given permission, as it should be on web server group www-data level as well?

您可以尝试使用给定的权限吗,因为它应该也在Web服务器组www-data级别上?


Also, adding a link for your reference.

此外,还添加了供您参考的链接。


https://linuxhint.com/how-to-set-up-file-permissions-for-laravel/

Https://linuxhint.com/how-to-set-up-file-permissions-for-laravel/


sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache


Please use the following commands:

请使用以下命令:



  1. Clear your project's cache


cd /home/vagrant/code/project_folder_name
sudo php artisan cache:clear


  1. Give your folders proper permission


sudo chmod 775 /home/vagrant/code/project_folder_name
sudo chown -R vagrant:vagrant /home/vagrant/code/project_folder_name

Hopefully, it will solve your issue.

希望它能解决你的问题。



I just ran
php artisan cache:clear
and it worked

我刚刚运行了php artisan缓存:Clear,它起作用了。



We had the same problem with the Laravel cache. I explain how we could address the problem using a few steps. The following steps we took:

我们在Laravel缓存上也遇到了同样的问题。我解释了我们如何通过几个步骤来解决这个问题。我们采取了以下步骤:


First:

We checked the permission of the files placed in the Laravel cache directory at the path /var/www/html/storage/framework/cache/data/. When you ll, the following output is visible at first look:

drwxr-xr-x 3 www-data www-data 4096 May 14 10:32 03

drwxr-xr-x 3 www-data www-data 4096 May 14 10:04 07

drwxr-xr-x 3 root root 4096 May 14 10:31 24

drwxr-xr-x 3 www-data www-data 4096 May 14 10:21 27

drwxr-xr-x 3 www-data www-data 4096 May 14 10:21 31

drwxrwxr-x 3 www-data www-data 4096 May 14 09:47 44

drwxr-xr-x 3 root root 4096 May 14 10:30 48

As you can see above, a few files are owned by root. This is the root of the problem. When you configure a Laravel project, it is supposed that the www-data user creates all files. We must find the cause of files created by the root user.

首先:我们检查了/var/www/html/store/framework/cache/data/路径下的Laravel缓存目录中的文件的权限。当你愿意的时候,乍一看,可以看到以下输出:drwxr-xr-x 3 www-data www-data 4096 May 14 10:32 03 drwxr-xr-x 3 www-data www-data 4096 May 14 10:04 07 drwxr-xr-x 3根目录4096 May 14 10:31 24 drwxr-xr-x 3 www-data www-data 4096 May 14 10:21 27 drwxr-xr-x 3 www-data www-data 4096 May 14 09:47 44 drwxr-xr-x 3根4096 5月14 10:30 48如上图所示,有几个文件由超级用户拥有。这就是问题的根源。当您配置Laravel项目时,假定www-data用户创建了所有文件。我们必须找出根用户创建文件的原因。


Second:

We could find out that operating systems were executing a few commands and jobs under the root user. So, we needed a solution to modify the schedule table of the cron job manager and execute the jobs with the www-data user. We first opened the cron table with the crontab -e command to do this. Then, we modified the cron table file as follows:

* * * * * root su -c "php /var/www/html/artisan schedule:run >> /var/log/cron.log" -s /bin/bash www-data

By doing the abovementioned, the cron jobs are executed by a bash belonging to the www-data user.

第二:我们可以发现操作系统正在根用户下执行一些命令和作业。因此,我们需要一种解决方案来修改cron作业管理器的调度表,并使用www-data用户执行作业。我们首先使用crontag-e命令打开cron表来执行此操作。然后,我们按如下方式修改cron表文件:***根su-c“php/var/www/html/artisan Schedule:run>>/var/log/cron.log”-S/bin/bash www-data通过执行上述操作,cron作业由属于www-data用户的bash执行。


Third:

We had a few files created by the root user in our project. To ensure that no file is owned by it, we highly recommend running the following command before purging the Laravel cache at the project's root folder (e.g., html).

chown -R www-data:www-data html

It recursively changes the ownership of all files and grants it to the www-data user.

第三:我们在项目中有几个由根用户创建的文件。为了确保它不拥有任何文件,我们强烈建议在清除项目根文件夹(例如,html)中的Laravel缓存之前运行以下命令。Chown-R www-data:www-data html它递归地更改所有文件的所有权,并将其授予www-data用户。


Fourth:

After doing all the first three steps, we needed to clear the Laravel cache. So, the cache files are purged and reconstructed. One may purge the Laravel cache with the php artisan cache:clear command. After doing these steps, the output would be something like the following with no file owned by root.

drwxrwxr-x 52 www-data www-data 4096 May 14 13:46 ./

drwxrwxr-x 3 www-data www-data 4096 Nov 15 2021 ../

drwxr-xr-x 3 www-data www-data 4096 May 14 13:03 01/

drwxr-xr-x 3 www-data www-data 4096 May 14 12:53 0e/

drwxr-xr-x 3 www-data www-data 4096 May 14 12:32 10/

drwxr-xr-x 3 www-data www-data 4096 May 14 12:52 25/

drwxr-xr-x 3 www-data www-data 4096 May 14 12:32 39/

drwxr-xr-x 3 www-data www-data 4096 May 14 12:52 3a/

drwxr-xr-x 3 www-data www-data 4096 May 14 12:12 3f/

drwxr-xr-x 3 www-data www-data 4096 May 14 13:46 42/

drwxr-xr-x 3 www-data www-data 4096 May 14 11:59 44/

drwxr-xr-x 4 www-data www-data 4096 May 14 12:52 4d/

第四:在完成前三个步骤之后,我们需要清除Laravel缓存。因此,缓存文件被清除并重建。用户可以使用php artisan缓存:Clear命令清除Laravel缓存。完成这些步骤后,输出将如下所示,其中没有由根用户拥有的文件。Drwxrwxr-x 52 www-data www-data 4096 5月14 13:46./drwxrwxr-x 3 www-data www-data 4096 11月15 2021年./drwxr-xr-x 3 www-data www-data 4096 5月14 13:03 01/drwxr-xr-x 3 www-data www-data 4096 May 14 12:53 0E/drwxr-xr-x 3 www-data www-data 4096 12:32 10/drwxr-xr-x 3 www-data www-4096 12:52 25/drwxr-xr-x3 www-data www-data 4096 14 12:32 39/drwxr-xr-x 3 www-data www-data 4096 May 14 12:52 3a/drwxr-xr-x 3 www-data www-data 4096 May 14 12:12 3f/drwxr-xr-x 3 www-data www-data 4096 May 14 13:46 42/drwxr-xr-x 3 www-data www-data 4096 5月14 11:59 44/drwxr-xr-x 4 www-data 4096 12:52 4d/



I resolved it by providing owner permission to apache user:

我通过向ApacheUser提供所有者权限解决了这个问题:


chown -R apache:apache storage/framework


use command
php artisan storage:link

使用命令php artisan store:link


更多回答

Worked for me laravel 8 with docker. For windows user need to run like this docker-compose exec php-apache chmod -R ug+rwx storage /var/www/html/bootstrap/cache Here php-apache is docker server name for apache and you have to give full path present in docker volume.

为我工作,8岁,和多克一起工作。对于Windows用户,需要像这样运行-编写exec php-apachechmod-rug+rwx store/var/www/html/bootstrap/cache这里php-apache是apache的docker服务器名称,您必须在docker卷中提供完整路径。

Please do not duplicate existing answers

请不要重复现有答案

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

您的答案可以通过其他支持信息来改进。请编辑以添加更多详细信息,如引用或文档,以便其他人可以确认您的答案是正确的。你可以在帮助中心找到更多关于如何写出好答案的信息。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com