title: How do I configure AWS CodePipeline, CodeBuild, and Elastic Beanstalk to deploy a Laravel 8 application correctly?
body: <p>I can't seem to figure out the right settings across the 3 services to make this work. I have a Laravel 8 application that triggers AWS CodePipeline from a Github push which uses CodePipeline to build the application and deploy it to Elastic Beanstalk.</p>
  <p>Everything builds and deploys successfully, but when I visit the application endpoint in my browser (with debugging on), I get:</p>
  <blockquote>
  <p>UnexpectedValueException
  There is no existing directory at &quot;/codebuild/output/src078727356/src/storage/logs&quot; and it could not be created: Permission denied</p>
  </blockquote>
  <p>My <code>buildspec</code> for CodeBuild is:</p>
  <pre><code>version: 0.2
  phases:
     install:
       runtime-versions:
           php: 7.4
           nodejs: 12.x
       commands:
           - apt-get update -y
           - apt-get install -y libpq-dev libzip-dev
           - apt-get install -y php-pgsql
           - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
           - chown -R www-data:www-data $CODEBUILD_SRC_DIR/storage
           - chmod -R 755 $CODEBUILD_SRC_DIR/storage
     pre_build:
       commands:
           - cp .env.staging .env
           - composer install
           - npm install
     build:
       commands:
           - pwd
           - ls -l
           - ls -l ./storage
           - ls -l ./storage/logs
           - npm run production
           - php artisan migrate --force
           - php artisan db:seed
           - php artisan route:clear
           - php artisan config:clear
           - php artisan cache:clear
     post_build:
       commands:
           - printenv
  artifacts:
     files:
           - '**/*'
     name: $(date +%Y-%m-%dT%H:%M:%S).zip
  proxy:
     upload-artifacts: yes
     logs: yes
  </code></pre>
  <p>You can see that there are a few debugging commands in the <code>build</code> section which confirms that there is indeed a directory where the error says their isn't:</p>
  <pre><code>[Container] 2021/09/27 22:54:11 Running command ls -l
  727 total 688
  728 -rw-rw-r--   1 root     root        174 Sep 27 22:34 README.md
  729 drwxr-xr-x   7 root     root       4096 Sep 27 22:53 app
  730 -rwxrwxr-x   1 root     root       1686 Sep 27 22:34 artisan
  731 drwxr-xr-x   3 root     root       4096 Sep 27 22:53 bootstrap
  732 -rw-rw-r--   1 root     root       1735 Sep 27 22:34 composer.json
  733 -rw-r--r--   1 root     root     285508 Sep 27 22:53 composer.lock
  734 drwxr-xr-x   2 root     root       4096 Sep 27 22:53 config
  735 drwxr-xr-x   5 root     root       4096 Sep 27 22:53 database
  736 drwxr-xr-x 529 root     root      20480 Sep 27 22:54 node_modules
  737 -rw-r--r--   1 root     root     323761 Sep 27 22:54 package-lock.json
  738 -rw-rw-r--   1 root     root        473 Sep 27 22:34 package.json
  739 -rw-rw-r--   1 root     root       1202 Sep 27 22:34 phpunit.xml
  740 drwxr-xr-x   2 root     root       4096 Sep 27 22:53 public
  741 drwxr-xr-x   6 root     root       4096 Sep 27 22:53 resources
  742 drwxr-xr-x   2 root     root       4096 Sep 27 22:53 routes
  743 -rw-rw-r--   1 root     root        563 Sep 27 22:34 server.php
  744 drwxr-xr-x   5 www-data www-data   4096 Sep 27 22:53 storage
  745 drwxr-xr-x   4 root     root       4096 Sep 27 22:53 tests
  746 drwxr-xr-x  44 root     root       4096 Sep 27 22:53 vendor
  747 -rw-rw-r--   1 root     root        559 Sep 27 22:34 webpack.mix.js
  748 
  749 [Container] 2021/09/27 22:54:11 Running command ls -l ./storage
  750 total 12
  751 drwxr-xr-x 3 www-data www-data 4096 Sep 27 22:53 app
  752 drwxr-xr-x 6 www-data www-data 4096 Sep 27 22:53 framework
  753 drwxrwxrwx 2 www-data www-data 4096 Sep 27 22:53 logs
  754 
  755 [Container] 2021/09/27 22:54:11 Running command ls -l ./storage/logs
  756 total 0
  </code></pre>
  <p>You can even see that the <code>logs/</code> directory is <code>777</code> writeable in that log snippet (changed it back to <code>755</code> per the <code>buildspec</code>).</p>
  <h1>Update</h1>
  <p>Per the first comment, I've taken a look at the EB instance to investigate further and it looks like its using the CodeBuild path for logging and storage (and basically everything else), even though the application runs out of <code>/var/app/current</code> in the EB instance. I either need to tell Laravel where it lives, or build it in CodeBuild in the same <code>/var/app/current</code> directory, or maybe something else?</p>