[英]Cannot serve directory /var/www/html/public/ [Laravel - Aws Elasticbeanstalk]
I have been trying to deploy my Laravel project on a Elasticbeanstalk server, I keep getting this error: 我一直在尝试将我的Laravel项目部署在Elasticbeanstalk服务器上,但不断出现此错误:
Frontend error: 前端错误:
You don't have permission to access / on this server.
您无权访问此服务器上的/。
Error in the log file: 日志文件中的错误:
Cannot serve directory /var/www/html/public/: No matching DirectoryIndex (index.html,index.php) found, and server-generated
无法提供目录/ var / www / html / public /:找不到匹配的DirectoryIndex(index.html,index.php),并且由服务器生成
directory index forbidden by Options directiveOptions指令禁止的目录索引
I have place .htaccess and index.php in the root not in the public folder. 我将.htaccess和index.php放在根目录中而不是公用文件夹中。
.htaccess 的.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
.ebextensions/01-main.config .ebextensions / 01-main.config
container_commands:
01-optimize:
command: "/usr/bin/composer.phar dump-autoload --optimize"
02-migrations:
command: "php artisan migrate --env=production"
03-cache:
command: "php artisan cache:clear"
cwd: "/var/app/ondeck"
04-optimize:
command: "php artisan optimize --force"
cwd: "/var/app/ondeck"
05-permissions:
command: "chmod 777 -R /var/app/ondeck"
cwd: "/var/app/ondeck"
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 777 /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
chown webapp:webapp /var/app/current/storage/logs/laravel.log
fi
if [ ! -d /var/app/current/public/storage ]; then
echo "Creating /public/storage symlink..."
ln -s /var/app/current/storage/app/public /var/app/current/public/storage
fi
"/opt/elasticbeanstalk/tasks/publishlogs.d/laravel-logs.conf":
mode: "000755"
owner: root
group: root
content: |
/var/app/current/storage/logs/*.log
"/etc/httpd/conf.d/https_redirect.conf":
mode: "000644"
owner: root
group: root
content: |
RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-Proto} ^http$
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=307,L]
.ebextensions/02-project.config .ebextensions / 02-project.config
commands:
01_update_composer:
command: export HOME=/root && export COMPOSER_HOME=/root && /usr/bin/composer.phar self-update
option_settings:
- namespace: aws:elasticbeanstalk:application:environment
option_name: COMPOSER_HOME
value: /root
- namespace: aws:elasticbeanstalk:application:environment
option_name: HOME
value: /root
- namespace: aws:elasticbeanstalk:container:php:phpini
option_name: document_root
value: /public
- namespace: aws:elasticbeanstalk:container:php:phpini
option_name: memory_limit
value: 512M
- namespace: aws:elasticbeanstalk:sqsd
option_name: HttpPath
value: /worker/queue
- namespace: aws:elasticbeanstalk:container:php:phpini
option_name: zlib.output_compression
value: Off
- namespace: aws:elasticbeanstalk:container:php:phpini
option_name: allow_url_fopen
value: On
- namespace: aws:elasticbeanstalk:container:php:phpini
option_name: max_execution_time
value: 4000
Any help will be appreciated. 任何帮助将不胜感激。
Thanks 谢谢
Did you do this? 你做了这个了吗?
Open the Elastic Beanstalk console. 打开Elastic Beanstalk控制台。
Navigate to the management page for your environment. 导航到您的环境的管理页面。
Choose Configuration . 选择配置 。
On the Software configuration card, choose Modify . 在软件配置卡上,选择修改 。
For Document Root, type /public . 对于Document Root,输入/ public 。
Apply Configuration 应用配置
Reference: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/php-laravel-tutorial.html 参考: https : //docs.aws.amazon.com/elasticbeanstalk/latest/dg/php-laravel-tutorial.html
您必须将chmod的公用文件夹权限设置为755
This means your server config file is not created properly. 这意味着您的服务器配置文件未正确创建。
The default config file root is "/var/www/html/public/" but in your server there is no such directory. 默认的配置文件根目录是“ / var / www / html / public /”,但是在您的服务器中没有这样的目录。
You need to do the following.(Respect to apache server) 您需要执行以下操作。(对于Apache服务器)
/etc/apache2/site-available/default.conf
) and change the path to your laravel public folder /etc/apache2/site-available/default.conf
)并将路径更改为laravel公用文件夹 sudo a2dissite default.conf
inside /etc/apache2/site-available
directory) and create your own config file and enable it ( sudo a2ensite laravel.conf
). /etc/apache2/site-available
目录中的sudo a2dissite default.conf
)并创建自己的配置文件并启用它( sudo a2ensite laravel.conf
)。 sudo chmod -R 0777 /storage
and sudo chmod -R 0777 /public
sudo chmod -R 0777 /storage
和sudo chmod -R 0777 /public
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.