Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ozne's avatar
Level 9

Laravel Command returning different output when executed by Cron on AWS EC2

Hello guys, I'm having some trouble with the cron jobs in a EC2 instance on a Elastic Beanstalk environment.

When I connect to the EC2 instance and I type php artisan command:backup_logs from the terminal, the job runs smoothly and everything works as it should. While, when the job runs through the cron * * * * * /usr/bin/php /var/app/current/artisan command:backup_logs it returns the following error in the logs:

[2018-09-17 16:14:01] production.ERROR: Missing required client configuration options:

region: (string)

  A "region" configuration value is required for the "s3" service

  (e.g., "us-west-2"). A list of available public regions and endpoints can be
  found at http://docs.aws.amazon.com/general/latest/gr/rande.html. {"exception":"[object] (InvalidArgumentException(code: 0): Missing required client configuration options:

region: (string)

  A \"region\" configuration value is required for the \"s3\" service
  (e.g., \"us-west-2\"). A list of available public regions and endpoints can be
  found at http://docs.aws.amazon.com/general/latest/gr/rande.html. at /var/app/current/vendor/aws/aws-sdk-php/src/ClientResolver.php:371)
[stacktrace]
#0 /var/app/current/vendor/aws/aws-sdk-php/src/ClientResolver.php(267): Aws\ClientResolver->throwRequired(Array)
#1 /var/app/current/vendor/aws/aws-sdk-php/src/AwsClient.php(158): Aws\ClientResolver->resolve(Array, Object(Aws\HandlerList))
#2 /var/app/current/vendor/aws/aws-sdk-php/src/S3/S3Client.php(261): Aws\AwsClient->__construct(Array)
#3 /var/app/current/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php(208): Aws\S3\S3Client->__construct(Array)
#4 /var/app/current/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php(125): Illuminate\Filesystem\FilesystemManager->createS3Driver(Array)
........

It gives a PRODUCTION error on laravel.log, while this is DEVELOPMENT, and the value is looking for is already set. As I mentioned earlier the upload works fine when I run it from the terminal as a logged user.

I am having the same problem with all the commands and also when I want to run the jobs through the schedule, the same error happens.

Anyone who can shed some light please? Thank you very much!

0 likes
7 replies
ozne's avatar
Level 9

Any DevOps wiz in here?

ozne's avatar
Level 9

thanks for that but unfortunately doesn't help much. I really cannot understand why when the command is run through cron doesn't work properly.

tim.ogilvy@thecigroup.com.au's avatar

It looks like this occurs because the linux user running cron is not the same system user as the user which serves the web app.

The lazy way to solve it is to 777 your log files, however that's not recommended as it opens them to the world.

It's also worth noting that new log files created sequentially by the webapp user will revert to the default permissions, meaning that unless you keep updating them, things will stop working again soon.

I'm looking for a solution currently, and will update this if I find one.

tim.ogilvy@thecigroup.com.au's avatar

It looks like this is the most useful solution - adding the ec2-user to the webapp group during the instance config, via .ebextensions:

usermod -a -G webapp ec2-user or sudo usermod -a -G webapp ec2-user depending on where you call it.

Please or to participate in this conversation.