简体   繁体   English

无法提供目录/ var / www / html / public / [Laravel-AWS Elasticbeanstalk]

[英]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 directive Options指令禁止的目录索引

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? 你做了这个了吗?

  1. Open the Elastic Beanstalk console. 打开Elastic Beanstalk控制台。

  2. Navigate to the management page for your environment. 导航到您的环境的管理页面。

  3. Choose Configuration . 选择配置

  4. On the Software configuration card, choose Modify . 软件配置卡上,选择修改

  5. For Document Root, type /public . 对于Document Root,输入/ public

  6. 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服务器)

  1. You can edit the default config file ( /etc/apache2/site-available/default.conf ) and change the path to your laravel public folder 您可以编辑默认配置文件( /etc/apache2/site-available/default.conf )并将路径更改为laravel公用文件夹
  2. Or You can Disable the default config file ( 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 )。
  3. Change the /public and /storage folder permission to sudo chmod -R 0777 /storage and sudo chmod -R 0777 /public 将/ public和/ storage文件夹权限更改为sudo chmod -R 0777 /storagesudo chmod -R 0777 /public

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AH01276:无法提供目录/ var / www / html /:找不到匹配的DirectoryIndex(index.php,index.html) - AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.php,index.html) found var / www / html目录的权限 - permission for var/www/html directory 在 var/www/html 中部署 Laravel - Deploy Laravel in var/www/html Laravel在公共的&#39;www&#39;目录中如何保护 - Laravel in public 'www' directory how to protect Laravel 错误:“/var/www/html/DocApp/storage/logs”中没有现有目录,并且它不可构建:权限被拒绝 - Laravel Error: There is no existing directory at "/var/www/html/DocApp/storage/logs" and its not buildable: Permission denied 在/ var / www / html目录中的php中执行python代码 - Execute python code inside php in /var/www/html directory 从/ var / www / pdf /目录将PDF文件嵌入html - Embed PDF file in the html from /var/www/pdf/ directory 如何在/ var / www / html / blog /上为laravel 5.6设置htaccess - how to set htaccess on /var/www/html/blog/ for laravel 5.6 在/ var / www / html中编辑 - editing in /var/www/html 如何将 Laravel Mix 的 public 目录更改为 public_html 目录 - How to change public directory to public_html directory for Laravel Mix
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM