I am trying to install nginx+php-fpm with Laravel via docker, on AWS Elastic Beanstalk. I've been able to successfully get it up and running, however Laravel gives me an error: Mcrypt PHP extension required.
I've been able to install mcrypt via the command docker-php-ext-install
within the container, but after installing it, and verifying that it's been installed and enabled (via php-fpm -m |grep mcrypt
), I still get the Mcrypt PHP extension required.
error. Whenever I try to restart the php-fpm process or restart the container, elastic beanstalk spins up a brand new container and I have to re-install mcrypt all over again (basically wipes the slate clean).
I'm trying to make an automated script for all this, is there an easy way to do this?
This is my Dockerrun.aws.json file:
{
"AWSEBDockerrunVersion": 2,
"volumes": [
{
"name": "php-app",
"host": {
"sourcePath": "/var/app/current/src"
}
},
{
"name": "nginx-conf",
"host": {
"sourcePath": "/var/app/current/nginx/conf.d"
}
}
],
"containerDefinitions": [
{
"name": "php-app",
"image": "php:5-fpm",
"essential": true,
"memory": 128,
"mountPoints": [
{
"sourceVolume": "php-app",
"containerPath": "/var/www/html"
}
]
},
{
"name": "nginx-proxy",
"image": "nginx",
"essential": true,
"memory": 128,
"portMappings": [
{
"hostPort": 80,
"containerPort": 80
}
],
"links": [
"php-app"
],
"mountPoints": [
{
"sourceVolume": "php-app",
"containerPath": "/var/www/html"
},
{
"sourceVolume": "awseb-logs-nginx-proxy",
"containerPath": "/var/log/nginx"
},
{
"sourceVolume": "nginx-conf",
"containerPath": "/etc/nginx/conf.d",
"readOnly": true
}
]
}
]
}
and my post-script that's run after the container is spun (placed in .ebextensions):
commands:
create_post_dir:
command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
ignoreErrors: true
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/99_delayed_job.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
DOCKER_ID=`docker ps -q --filter "ancestor=php:5-fpm"`
docker exec -i $DOCKER_ID bash -c "apt-get update"
docker exec -i $DOCKER_ID bash -c "apt-get install -y libmcrypt-dev"
docker exec -i $DOCKER_ID bash -c "docker-php-ext-install mcrypt pdo pdo_mysql"
You must create your own image and host it publicly on hub.docker.com. Docker containers exit when the main command stops so there is no way to reboot the php-fpm process after the container has started.
For instance:
FROM php:5-fpm
RUN apt-get update
RUN apt-get install -y php5-mcrypt
Then push this image to docker hub.
You could also set up an automated build, that way docker hub builds this image for you.
Then update your build definition image like this:
"name": "php-app",
"image": "jamesnine/php:5-fpm",
"essential": true,