title: Cannot serve directory /var/www/html/public/ [Laravel - Aws Elasticbeanstalk]
body: <p>I have been trying to deploy my Laravel project on a Elasticbeanstalk server, I keep getting this error:</p>
  
  <p>Frontend error:</p>
  
  <blockquote>
    <p>You don't have permission to access / on this server.</p>
  </blockquote>
  
  <p>Error in the log file:</p>
  
  <blockquote>
    <p>Cannot serve directory /var/www/html/public/: No matching
    DirectoryIndex (index.html,index.php) found, and server-generated<br>
    directory index forbidden by Options directive</p>
  </blockquote>
  
  <p>I have place .htaccess and index.php in the root not in the public folder.</p>
  
  <p><strong>.htaccess</strong></p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
      &lt;IfModule mod_negotiation.c&gt;
          Options -MultiViews -Indexes
      &lt;/IfModule&gt;
  
      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]
  &lt;/IfModule&gt;
  </code></pre>
  
  <p><strong>.ebextensions/01-main.config</strong></p>
  
  <pre><code>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]
  </code></pre>
  
  <p><strong>.ebextensions/02-project.config</strong></p>
  
  <pre><code>commands:
    01_update_composer:
      command: export HOME=/root &amp;&amp; export COMPOSER_HOME=/root &amp;&amp; /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
  </code></pre>
  
  <p>Any help will be appreciated.</p>
  
  <p>Thanks</p>