AWS上的Laravel:日志文件权限问题
我在Amazon Web Services Elastic Beanstalk上部署Laravel webapp时遇到了一个非常令人沮丧的问题。有时这很好,但大约50%的时候我会发生以下崩溃: 无法打开流或文件“/var/app/current/storage/logs/laravel-2019-10-18.log”:无法打开流:权限被拒绝 (其中日期为当前日期。) 果然,当我使用SSH连接到服务器时,我可以看到该特定日志文件的权限设置为AWS上的Laravel:日志文件权限问题,laravel,amazon-web-services,amazon-elastic-beanstalk,Laravel,Amazon Web Services,Amazon Elastic Beanstalk,我在Amazon Web Services Elastic Beanstalk上部署Laravel webapp时遇到了一个非常令人沮丧的问题。有时这很好,但大约50%的时候我会发生以下崩溃: 无法打开流或文件“/var/app/current/storage/logs/laravel-2019-10-18.log”:无法打开流:权限被拒绝 (其中日期为当前日期。) 果然,当我使用SSH连接到服务器时,我可以看到该特定日志文件的权限设置为root:root -rw-r--r-- 1 root
root:root
-rw-r--r-- 1 root root 3400 Oct 18 13:39 laravel-2019-10-18.log
-rw-rw-r-- 1 webapp webapp 0 Oct 18 13:39 laravel.log
如果我将所有者更改为webapp:webapp
,则应用程序会再次正常工作。同样,如果我删除日志文件的网站再次正常工作。。。直到下一次部署
我的问题是如何防止这种情况发生。禁用所有日志?是否在部署期间更改权限?这仅仅是因为debug设置为“true”吗
这是我的deploy.config
。有什么不对劲还是遗漏了
container_commands:
01-migrations:
command: "php artisan migrate --force"
02-import:
command: "php artisan import:initial-data"
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/99_make_storage_writable.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
echo "Making /storage writeable..."
chmod -R 755 /var/app/current/storage
if [ ! -f /var/app/current/storage/logs/laravel.log ]; then
echo "Creating /storage/logs/laravel.log..."
touch /var/app/current/storage/logs/laravel.log
sudo chown -R webapp:webapp /var/app/current/storage/logs
sudo chmod -R ug+w /var/app/current/storage/logs
fi
#https://serverfault.com/a/669547/24863
"/opt/elasticbeanstalk/hooks/appdeploy/post/99_restart_workers.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
echo "Spawn worker..."
nohup php /var/app/current/artisan queue:work >/dev/null 2>&1 &
"/opt/elasticbeanstalk/tasks/publishlogs.d/laravel-logs.conf":
mode: "000755"
owner: root
group: root
content: |
/var/app/current/storage/logs/*.log
#https://stackoverflow.com/a/38751749/199700
"/etc/httpd/conf.d/https_redirect.conf":
mode: "000644"
owner: root
group: root
content: |
RewriteEngine on
<If "-n '%{HTTP:X-Forwarded-Proto}' && %{HTTP:X-Forwarded-Proto} != 'https'">
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</If>
#https://stackoverflow.com/a/38600025/199700
"/etc/php.d/project.ini" :
mode: "000644"
owner: root
group: root
content: |
upload_max_filesize=10M
post_max_size=32M
container\u命令:
01迁移:
命令:“php artisan迁移--强制”
02进口:
命令:“php artisan导入:初始数据”
文件夹:
“/opt/elasticbeanstalk/hooks/appdeploy/post/99_make_storage_writable.sh”:
模式:“000755”
所有者:root
组:根
内容:|
#!/usr/bin/env bash
echo“使/存储可写…”
chmod-R 755/var/app/current/storage
如果[!-f/var/app/current/storage/logs/laravel.log];然后
echo“创建/存储/日志/laravel.log…”
touch/var/app/current/storage/logs/laravel.log
sudo chown-R webapp:webapp/var/app/current/storage/logs
sudo chmod-R ug+w/var/app/current/storage/logs
fi
#https://serverfault.com/a/669547/24863
“/opt/elasticbeanstalk/hooks/appdeploy/post/99_restart_workers.sh”:
模式:“000755”
所有者:root
组:根
内容:|
#!/usr/bin/env bash
回声“产卵工人…”
nohup php/var/app/current/artisan队列:工作>/dev/null 2>&1&
“/opt/elasticbeanstalk/tasks/publishlogs.d/laravel logs.conf”:
模式:“000755”
所有者:root
组:根
内容:|
/var/app/current/storage/logs/*.log
#https://stackoverflow.com/a/38751749/199700
“/etc/httpd/conf.d/https_redirect.conf”:
模式:“000644”
所有者:root
组:根
内容:|
重新启动发动机
重写规则(.*)https://%{HTTP_HOST}%{REQUEST_URI}[R,L]
#https://stackoverflow.com/a/38600025/199700
“/etc/php.d/project.ini”:
模式:“000644”
所有者:root
组:根
内容:|
上载\u最大\u文件大小=10M
立柱最大尺寸=32米
这通常是因为您正在运行一个php artisan
命令,该命令以root用户身份写入日志。查看laravel-2019-10-18.日志的初始内容,应能提供涉及哪个命令的线索