I\'ve got an Elastic Beanstalk environment with a PHP application. I\'d like to just run npm install
after my application has been deployed.
node
For anyone else experiencing this issue on a PHP Elastic Beanstalk instance, here's what helped me get through this:
1) If you're running on an Amazon Linux instance, doing a yum install nodejs
will give you a super old version that will most likely be incompatible with a number of things. I had to add a script to my .ebextensions
dir and execute it from one of my configs to install an updated version of nodejs. Here is a copy of that script:
#!/bin/bash
hash_file="/tmp/nodejshash"
check_if_npm_packages_has_to_be_installed () {
if [ -f $hash_file ]; then
check_if_same_hash
else
return 0
fi
}
check_if_same_hash () {
hash_new="$(md5sum .ebextensions/bin/install-nodejs.sh 2> /dev/null | cut -d ' ' -f 1)"
hash_current="$(cat "$hash_file" 2> /dev/null | cut -d ' ' -f 1)"
if [ $hash_new == $hash_current ]; then
return 1
else
return 0
fi
}
install_node () {
if hash nodejs 2> /dev/null; then
echo 'nodejs install, add more processing if needed' > /dev/null
else
curl -sL https://rpm.nodesource.com/setup_6.x | bash -
yum install -y nodejs
fi
}
install_npm_packages () {
npm install -g bower
npm install -g gulp
}
update_current_hash () {
echo $hash_new > $hash_file
}
install_node
if check_if_npm_packages_has_to_be_installed; then
install_npm_packages
update_current_hash
fi
2) If you're on a micro instance by default, the node-sass
package was taking a very long time to build and eventually timed out. I increased my instance size to a t2.small
to get past this.
Hope this helps someone else out.