1
votes

I have been trying to deploy my Laravel project on a Elasticbeanstalk server, I keep getting this error:

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
directory index forbidden by Options directive

I have place .htaccess and index.php in the root not in the public folder.

.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

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

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

3
Why have you placed .htaccess and index.php in the root and not in the public folder? - Saurabh
@Saurabh If I place .htaccess and index.php into /public folder I get this error :Whoops, looks like something went wrong. and to access to the website I have to add the public folder to the url (www.example.com/public/). PHP Warning: require(/var/app/current/public/vendor/autoload.php): failed to open stream: No such file or directory in /var/app/current/public/index.php on line 24 - Sirius
Did you ever solve this, getting the same issue now and this is a setup I've used several times in the past. - iKlsR

3 Answers

2
votes

Did you do this?

  1. Open the Elastic Beanstalk console.

  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.

  6. Apply Configuration

enter image description here

Reference: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/php-laravel-tutorial.html

0
votes

you have to set permission to public folder with chmod to 755

0
votes

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.

You need to do the following.(Respect to apache server)

  1. You can edit the default config file ( /etc/apache2/site-available/default.conf ) and change the path to your laravel public folder
  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).
  3. Change the /public and /storage folder permission to sudo chmod -R 0777 /storage and sudo chmod -R 0777 /public