Skip to content

AWS CodeBuild + ubuntu/standard/7.0 + missing PHP module "sodium"

0

I am bound to the following AWS CodeBuild environment:

  • Image: aws/codebuild/standard:7.0
  • Environment type: Linux EC2

My project requires the PHP module ext-sodium which doesn't seem to be part of the standard setup. According to the aws-codebuild-docker-images, libsodium-dev is installed in the system. However, php -m doesn't confirm the availability of the PHP module.

I tried several ways to install the module in the install phase in my buildspec but to no avail.

phases:
  install:
    runtime-versions:
      php: 8.2
    commands:
      - ???
      - php -m | grep sodium
    finally:
      - echo 'Installation complete'
  build:
  ...

Simply enabling the module in the php.ini doesn't work:

- "sed -i -e 's/;\\(extension=sodium\\)/\\1/g' /root/.phpenv/versions/8.2/etc/php.ini"

neither does this approach work:

- "echo extension=sodium >> /root/.phpenv/versions/8.2/etc/conf.d/sodium.ini"

What do I have to do to configure or enable sodium support for PHP in CodeBuild using the aws/codebuild/standard:7.0 image?

asked 2 years ago719 views

1 Answer
-1

To enable the sodium module for PHP in AWS CodeBuild using the aws/codebuild/standard:7.0 image, you need to compile and install the module during the build process. Since libsodium-dev is already installed in the system, you can use pecl to install the sodium extension. Here's how you can modify your buildspec to achieve this:

  1. First, ensure you're using the correct PHP version in your runtime-versions.
  2. Use pecl to install the sodium extension.
  3. Enable the extension in your PHP configuration.
  4. Verify the installation.

Here's an example of how your buildspec's install phase could look:

phases:
install:
runtime-versions:
php: 8.2
commands:
- pecl install libsodium
- echo "extension=sodium.so" >> /root/.phpenv/versions/8.2/etc/php.ini
- php -m | grep sodium
finally:
- echo 'Installation complete'
build:
# Your build commands here

This approach should successfully install and enable the sodium module for PHP in your CodeBuild environment. The pecl install command will compile and install the sodium extension, and then we add it to the PHP configuration file.

If you encounter any issues, you may need to install additional dependencies or update existing ones. In such cases, you could add commands like apt-get update and apt-get install -y followed by any necessary packages before the pecl install command.

Remember that these changes will only persist for the duration of the build. If you find yourself needing this extension frequently, you might want to consider creating a custom Docker image that includes the sodium extension pre-installed, which you can then use as your CodeBuild environment.
Sources
Managed Build Server - AWS CodeBuild Features - AWS
Troubleshooting AWS CodeBuild - AWS CodeBuild
Build specification reference for CodeBuild - AWS CodeBuild

answered 2 years ago

  • "Since libsodium-dev is already installed in the system, you can use pecl to install the sodium extension."

    pecl is not available in the aws/codebuild/standard:7.0 image:

    [Container] Running command pecl install libsodium
    /codebuild/output/tmp/script.sh: 4: pecl: not found
    
    [Container] Command did not exit successfully pecl install libsodium exit status 127
    

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.