0

I am trying to deploy a Laravel app to Elastic Beanstalk. I have changed the .ebextensions folder for the .platform folder and am using hooks.

The app is a Laravel 12 app using AWS's PHP 8.4 running on 64bit Amazon Linux 2023/4.6.1 platform.

Every time I try and deploy this app it seems like I am getting depreciation errors on the side of composer. To help with this, I added a "prebuild" folder inside .platform with instructions to download and install a new version of composer instead of defaulting to the one already cooked into the server. The file in "prebuild" is called "00_install_composer.sh" and looks like this:

#!/bin/bash

echo "-----> [prebuild] Starting Composer install process"

cd /var/app/staging

# Rename composer.json to avoid Elastic Beanstalk's default Composer step
if [ -f "composer.json" ]; then
  echo "-----> [prebuild] Renaming composer.json to skip default EB Composer"
  mv composer.json composer.json.bak
fi

# Download latest Composer
EXPECTED_SIGNATURE=$(curl -s https://composer.github.io/installer.sig)
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_SIGNATURE=$(php -r "echo hash_file('sha384', 'composer-setup.php');")

if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]; then
  echo "ERROR: Invalid Composer installer signature"
  rm composer-setup.php
  exit 1
fi

php composer-setup.php --install-dir=/var/app/staging --filename=composer
rm composer-setup.php

# Restore composer.json
if [ -f "composer.json.bak" ]; then
  echo "-----> [prebuild] Restoring composer.json"
  mv composer.json.bak composer.json
fi

echo "-----> [prebuild] Composer install complete"

The issue is that after putting this file in place, I see in the logs that there are line items saying that the file should be run but then it seems that the server just continues on with its own pre-baked version of composer. Here are the log lines:

2025/05/13 16:05:57.845528 [INFO] Running script: .platform/hooks/prebuild/00_install_composer.sh
2025/05/13 16:05:58.571375 [INFO] Finished running scripts in /var/app/staging/.platform/hooks/prebuild
2025/05/13 16:05:58.571384 [INFO] Executing instruction: Install composer dependencies
2025/05/13 16:05:58.571400 [INFO] installing composer dependencies...
2025/05/13 16:05:58.571408 [INFO] Changing ownership of staging dir...
2025/05/13 16:05:58.582769 [INFO] Running command: /bin/su webapp -c composer.phar install --no-ansi --no-interaction 
2025/05/13 16:06:14.187215 [INFO] 
Deprecated: Composer\Console\Application::run(): Implicitly marking parameter $input as nullable is deprecated, the explicit nullable type must be used instead in phar:///usr/local/composer.phar/src/Composer/Console/Application.php on line 107

Deprecated: Composer\Console\Application::run(): Implicitly marking parameter $output as nullable is deprecated, the explicit nullable type must be used instead in phar:///usr/local/composer.phar/src/Composer/Console/Application.php on line 107

Deprecated: Symfony\Component\Console\Application::run(): Implicitly marking parameter $input as nullable is deprecated, the explicit nullable type must be used instead in phar:///usr/local/composer.phar/vendor/symfony/console/Application.php on line 103

Any idea how to handle this? I have no idea how to get a compatible version of composer up and running.

Thanks!

5
  • Your rename of composer.json to composer.json.bak and back again doesn't make much sense - the default composer execution isn't going to run in between those two lines anyway. And if it did work, you haven't shown any code running your custom composer instead of the default one. Commented May 13 at 18:09
  • thanks for comments, any suggestions on how to fix the problem? Commented May 13 at 18:13
  • /bin/su webapp -c /var/app/staging/composer.phar ... (or maybe just /bin/su webapp -c ./composer.phar ... since I guess you are already in the correct directory). Commented May 13 at 18:21
  • @Olivier I think that command is built into Beanstalk, not something the OP has written themselves (not that the question makes that very clear). Commented May 13 at 18:24
  • As the messages are solely deprecation messages, why not ignore them? What makes you think that Laravel is even involved? Finally, if you know that /usr/local/composer.phar is run, why not move your own instance of composer.phar to that exact location? Which version of Composer does your image use initially? Commented May 14 at 6:30

1 Answer 1

2

There is a page in the AWS documentation about exactly this topic.

The introduction says:

This topic describes how to configure Elastic Beanstalk to keep Composer up to date. You may have to update Composer if you see an error when you try to install packages with a Composer file, or if you're unable to use the latest platform version. Between platform updates, you can update Composer in your environment instances through the use of configuration files in your .ebextensions folder.

So the first thing to do is check the list of PHP platform versions to see if you can just update that. You can compare against the list of releases on Composer's GitHub repo.

At the time of writing, that page lists platform version 4.6.1 which ships with Composer 2.8.8. Composer version 2.8.9 was released earlier today, but none of the changes look relevant, so if you're on the up to date Beanstalk platform, upgrading Composer is unlikely to make any difference.


If you do need a newer version, rather than installing an extra copy, the AWS guide recommends you use Composer's built-in self-update command.

AWS recommend hard-coding the target version for stability (2.7.0 in the example below, which is a few months old now). This is optional, but without it, a deployment might run on an un-tested Composer version and cause problems.

The full example they give is to create a file called .ebextensions/composer.config with this content:

commands:
  01updateComposer:
    command: /usr/bin/composer.phar self-update 2.7.0
    
option_settings:
  - namespace: aws:elasticbeanstalk:application:environment
    option_name: COMPOSER_HOME
    value: /home/webapp/composer-home

Depending on your workflow, another alternative is to run composer install locally and upload the vendor directory to Beanstalk as part of your application. According to the AWS documentation on Composer integration:

When Elastic Beanstalk finds a vendor folder on the instance, it ignores the composer.json file (even if it exists). Your application then uses dependencies from the vendor folder.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.