Quick Tip – Writable Laravel logs with Elastic Beanstalk

A while ago I wrote an article outlining deploying Laravel to Elastic Beanstalk. While this worked great, I started running into problems surrounding an error that Laravel couldn’t write to it’s log files. I had tried adding code to the pre-deploy scripts to update folder settings, but this didn’t work. After a little more digging, I found you can use a post-deploy script. It looks a bit different (and doesn’t have much documentation) but it does the trick.

Laravel-5.png

In your .ebextensions folder, create a file and name it what you like, as long as it is sequentially at the end. Mine is named ’04postdeploy.config’ Then in that file add the following code:

files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/99_make_storage_writable.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      chmod -R 777 /var/app/current/storage

…and that is it! The first line is the name of the script file to create, and that can be arbitrary, though you can change the numbering if you have multiple post deploy files. Elastic Beanstalk deploys the code into the /var/app/current folder (you may notice “ondeck” being used in pre-deploy scripts, so we can make sure we target the write location to update our permissions.

Enjoy!

What are your 10 bits on the matter? I want to know!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s