Hi, this is Takafumi.
When the development of the system I'm currently involved in was over, I thought, "I'm about to prepare the staging environment," and tried to execute the command php aritisan migrate
to create a table.
Operation not permitted
"I can't migrate!"
Today's article solves the problem of not being able to migrate in a staging environment prepared using AWS EC2!
Become the owning user & give write permission to the owning group
UnexpectedValueException : The stream or file "/var/www/mcfhfs/storage/logs/laravel-2019-11-20.log" could not be opened: failed to open stream: Permission denied
at /var/www/mcfhfs/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:111
107| restore_error_handler();
108| if (!is_resource($this->stream)) {
109| $this->stream = null;
110|
> 111| throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened: '.$this->errorMessage, $this->url));
112| }
113| }
114|
115| if ($this->useLocking) {
Exception trace:
1 Monolog\Handler\StreamHandler::write()
/var/www/mcfhfs/vendor/monolog/monolog/src/Monolog/Handler/RotatingFileHandler.php:120
2 Monolog\Handler\RotatingFileHandler::write()
/var/www/mcfhfs/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php:42
Please use the argument -v to see more details.
Looking at the error message, it says "You do not have permission to write to the log file." Apparently you don't have write permission to the log file.
When I checked the permissions with ls -la
, it was rw ---- r ---- r --
.
In this case, it is "owning user (reading / writing) --owning group (reading) --other user (reading)". I'm not the owning user, I belong to the owning group, so I only have read permissions.
"Then, why not add write permission (w) to the permissions of the owning group?"
So run chmod 664 laravel-2019-11-20.log
.
As a result, ʻOperation not permitted` was displayed.
Upon examination, it seems that file permissions can only be changed by the file owner. (Reference: https://marunouchi-tech.i-studio.co.jp/3341)
"Then, why don't I become the owner of the file?"
Delete the relevant log file and create it again. After confirming that the file owner is yourself, execute migrate again.
php artisan migrate:fresh
Dropped all tables successfully.
Migration table created successfully.
"success!"
I thought this was the solution, and when I tried to view the page by connecting to the staging environment from the browser, the message "You do not have write permission for the log file" was displayed again. Apparently it is necessary to give write permission from the web server.
chmod 664 laravel-2019-11-20.log
ls -la
-rw-rw-r--
Now that the owning user and owning group have write permission, access the site again. It was displayed safely!
-Permissions can only be changed by the file owner. ・ Don't forget to grant write permission from the web server! -Check the authority when "Operation not permitted" or "Permission denied"!
I've never had an error with permissions, so I'm glad I got to know this. It is safe to get Permission denied with this. Well then!
Recommended Posts