일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- AWS
- 블레이드 템플릿
- fastapi
- mariadb
- Redis
- node.js
- For
- SQL
- nodejs
- nginx
- Machine Learning
- python
- Babel
- php
- Redux
- Go
- CentOS
- javascript
- laravel
- React
- webpack
- Node
- 기초 수학
- Backbone.js
- deep learning
- docker
- rabbitmq
- Switch
- NCP
- linux
- Today
- Total
개발일기
Laravel - Laravel Forge: file_put_contents(): failed to open stream: Permission denied 본문
Laravel - Laravel Forge: file_put_contents(): failed to open stream: Permission denied
Flashback 2022. 9. 2. 21:571. 원인
라라벨 프로젝트를 처음 생성하고 웹 페이지에 접속 했을 때, 위와 같은 에러가 발생하는 경우를 종종 발견할 수 있다.
주로 storage와 bootstrap 폴더의 파일에 에러가 발생한다. 원인은 Permission denined로 권한 관련 설정이 제대로 이루어지이 않아 발생하는 문제이다.
2. 해결법
- 에러가 발생하는 폴더의 하위 파일까지 권한을 755로 변경한다.
chmod 755 -R [에러가 발생한 경로]
# app, routes 등을 포함하는 프로젝트 폴더의 명은 test_project라고 가정
# storage일 경우
chmod -R 755 test_project/storage
# bootstrap일 경우
chmod -R 755 test_project/bootstrap
- app key를 생성한다.
# 프로젝트 폴더에서 해당 artisan 명령어를 실행한다.
php artisan key:generate
app key를 생성할 경우, 생성 결과는 .env파일에서 확인할 수 있다. .env파일의 APP_KEY 부분이 변경된다.
- Ubuntu 유저일 경우, chown 권한을 변경한다.
# storage
chown -R www-data:www-data test_project/storage
# bootstrap
chown -R www-data:www-data test_project/bootstrap
www-data는 ubuntu에서 파일의 기본 소유권자와 그룹을 나타낸다.
3. 주의점
권한을 777로 설정하는 것도 하나의 방법이긴 하다. 하지만 777로 설정하면 해당 파일을 누구나 읽고, 수정할 수 있으며 실행도 할 수 있다. 그렇기에 보안적인 측면에서 좋은 방법이 아니기에 777로 설정하는 법은 추천하지 않는다.
이와 같이 설정할 경우, 누구나 사용할 수 있는 파일 및 폴더가 되기 때문에 에러가 발생하지는 않는다.
# 추천하지 않는 방법
# storage
chmod -R 777 test_project/storage
# bootstrap
chmod -R 777 test_project/bootstrap
참고 사이트 :
https://stackoverflow.com/questions/33370134/when-to-generate-a-new-application-key-in-laravel
When to generate a new Application Key in Laravel?
Since it automatically sets it for me in my .env file when I create the app, I'm not sure when I should run it. In addition to that, if a second developer comes in, and clones the app, does he/she...
stackoverflow.com
file_put_contents(meta/services.json): failed to open stream: Permission denied
I am new to Laravel. I was trying to open http://localhost/test/public/ and I got Error in exception handler. I googled around and changed the permission of storage directory using chmod -R 7...
stackoverflow.com
https://askubuntu.com/questions/873839/what-is-the-www-data-user
What is the www-data user?
I'm working through How To Serve Django Applications with uWSGI and Nginx on Ubuntu 16.04. At the end of the "Create a systemd Unit File for uWSGI" in the article they discuss the www-data user. W...
askubuntu.com
'프로그래밍 언어 > PHP - Laravel' 카테고리의 다른 글
PHP - connect() to unix:/run/php/php-fpm.sock failed (13: Permission denied) (0) | 2023.04.21 |
---|---|
Laravel - ../vendor/autoload.php): Failed to open stream: No such file or directory in (0) | 2023.04.21 |
Laravel - slug url 생성 (0) | 2022.08.20 |
Laravel - Schedule 예약 작업 실행 (0) | 2022.08.13 |
Laravel - 비동기 페이지네이션 (0) | 2022.07.25 |