Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Command .platform/hooks/prebuild/update_composer.sh failed with error fork/exec .platform/hooks/prebuild/update_composer.sh: permission denied #8

Closed
yurik94 opened this issue May 17, 2020 · 7 comments

Comments

@yurik94
Copy link

yurik94 commented May 17, 2020

Hello Alex, thank you for this awesome repo ,
I was trying your scripts but I got this error on prebuild hook:

Amazon Linux 2

2020/05/17 19:39:58.177299 [INFO] Executing instruction: StageApplication
2020/05/17 19:39:58.222485 [INFO] extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /var/app/staging/
2020/05/17 19:39:58.222523 [INFO] Running command /bin/sh -c /usr/bin/unzip -q -o /opt/elasticbeanstalk/deployment/app_source_bundle -d /var/app/staging/
2020/05/17 19:39:58.486747 [INFO] finished extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /var/app/staging/ successfully
2020/05/17 19:39:58.500972 [INFO] Executing instruction: RunPreBuildHooks
2020/05/17 19:39:58.501029 [INFO] Executing platform hooks in .platform/hooks/prebuild/
2020/05/17 19:39:58.501039 [INFO] No plugin in cfn metadata.
2020/05/17 19:39:58.501071 [INFO] Following platform hooks will be executed in order: [update_composer.sh]
2020/05/17 19:39:58.501077 [INFO] Running platform hook: .platform/hooks/prebuild/update_composer.sh
2020/05/17 19:39:58.501307 [ERROR] An error occurred during execution of command [app-deploy] - [RunPreBuildHooks]. Stop running the command. Error: Command .platform/hooks/prebuild/update_composer.sh failed with error fork/exec .platform/hooks/prebuild/update_composer.sh: permission denied 

2020/05/17 19:39:58.501316 [INFO] Executing cleanup logic

This is the content (copy-pasted) of .platform/hooks/prebuild/update_composer.sh :

#!/bin/sh

# Update Composer binary.

export COMPOSER_HOME=/root

sudo /usr/bin/composer.phar self-update

I tried executing it manually via SSH (ec2-user) and it worked:

[ec2-user@ip-172-redacted ~]$ export COMPOSER_HOME=/root
[ec2-user@ip-172-redacted ~]$ sudo /usr/bin/composer.phar self-update
Updating to version 1.10.6 (stable channel).
   Downloading (100%)         
Use composer self-update --rollback to return to version 1.9.3

I know it's not crucial for the deploy, but do you have any idea?

P.S: I'm on Windows 10, I tried chmoddin' with git bash and both files are already executable...

@yurik94
Copy link
Author

yurik94 commented May 17, 2020

Another question...

2020/05/17 22:03:01.905016 [ERROR] An error occurred during execution of command [app-deploy] - [Install composer dependencies]. Stop running the command. Error: Installing composer dependencies failed with error: Command /bin/sh -c composer.phar install --no-ansi --no-interaction failed with error exit status 1. Stderr:Do not run Composer as root/super user! See https://getcomposer.org/root for details

Within 01_install_composer_dependencies you are installing dependencies as root which is not recommended, right?

@rennokki
Copy link
Owner

Hey!

According to this: #6, sudo should be used to avoid any errors regarding the install.

The errors related to .platform/hooks/prebuild/update_composer.sh: permission denied are because you didn't make the shell scripts executable before deploying them:

@rennokki
Copy link
Owner

rennokki commented May 19, 2020

Windows Bash acts different because it emulates the UNIX CLI, but the filesystem is still turned upside down. Use Ubuntu on Windows 10 from the Store to access the files and chmod them: https://www.microsoft.com/store/productId/9N6SVWS3RX71

@yurik94
Copy link
Author

yurik94 commented May 31, 2020

Resolved by using .ebextensions rather than .sh hooks

option_settings:
  - namespace: aws:elasticbeanstalk:application:environment
    option_name: COMPOSER_HOME
    value: /root

  - namespace: aws:elasticbeanstalk:container:php:phpini
    option_name: document_root
    value: /public

  - namespace: aws:elasticbeanstalk:container:php:phpini
    option_name: memory_limit
    value: 256M

commands:
  00_php_ini_bak:
    command: cp /etc/php.ini /etc/php.ini.bak

  01_install_pecl_redis:
    command: |
      pecl install redis
      echo "extension=redis.so" | tee /etc/php.d/50-redis.ini
    test: "php -r \"exit(extension_loaded('redis') ? 1 : 0);\""

  02_install_pecl_ev:
    command: |
      pecl install ev
      echo "extension=ev.so" | tee /etc/php.d/50-ev.ini
    test: "php -r \"exit(extension_loaded('ev') ? 1 : 0);\""

  03_php_ini_restore:
    command: cp /etc/php.ini.bak /etc/php.ini

container_commands:
  01_copy_env_file:
    command: |
      touch .env
      echo "APP_ENV=beanstalk" > .env
      chown webapp:webapp .env

  02_chmod_folders:
    command: |
      chmod -R 777 storage/
      chmod -R 777 bootstrap/cache/
      mkdir storage/framework/cache
      mkdir storage/framework/views
      chown webapp:webapp storage/logs
      chown webapp:webapp storage/framework/*

  03_install_composer_dependencies:
    command: |
      /usr/bin/composer.phar self-update
      php /usr/bin/composer.phar install --no-dev --no-interaction --prefer-dist --optimize-autoloader

  04_link_storage_folder:
    command: php artisan storage:link # not needed as we are using S3

  05_systemctl_restart_nginx:
    command: systemctl restart nginx

@rennokki
Copy link
Owner

Yes, this is a workaround. 👀

If you check the diff between master and amazon-ami branch, you can see that most of the commands were moved to .platform/ since i tought it is a good idea to make use of this AL2 feature. 😅

@MarkusJLechner
Copy link

MarkusJLechner commented Jul 3, 2020

i made a posting in aws forum.

there are too many reasons for this problem. one of the reasons is deploying from a windows machine

image

@rennokki
Copy link
Owner

rennokki commented Jul 3, 2020

Consider running the commands using WSL if you got Windows 10 or your CI/CD pipeline instead before deploying it.

Repository owner locked and limited conversation to collaborators Jul 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants