Public | Automated Build

Last pushed: a year ago
Short Description
Alpine PHP-FPM Docker container.
Full Description

exira/php-fpm

Get this image

The recommended way to get the Exira PHP-FPM Docker Image is to pull the prebuilt image from the Docker Hub Registry.

docker pull exira/php-fpm:latest

To use a specific version, you can pull a versioned tag. You can view the list of available versions in the Docker Hub Registry.

docker pull exira/php-fpm:[TAG]

If you wish, you can also build the image yourself.

git clone https://github.com/exira/docker-php-fpm.git
cd docker-php-fpm
docker build -t exira/php-fpm .

Linking

This image is designed to be used with a web server to serve your PHP app, you can use the linking system provided by Docker to do this.

Serving your PHP app through an nginx frontend

We will use PHP-FPM with nginx to serve our PHP app. Doing so will allow us to setup more complex configuration, serve static assets using nginx, load balance to different PHP-FPM instances, etc.

Step 1: Create a virtual host

Let's create an nginx virtual host to reverse proxy to our PHP-FPM container. The exira nginx Docker Image ships with some example virtual hosts for connecting to exira runtime images. We will make use of the PHP-FPM example:

server {
    listen 0.0.0.0:80;
    server_name yourapp.com;

    access_log /exira/nginx/logs/yourapp_access.log;
    error_log /exira/nginx/logs/yourapp_error.log;

    root /app;

    location / {
        index index.php;
    }

    location ~ \.php$ {
        # fastcgi_pass [PHP_FPM_LINK_NAME]:9000;
        fastcgi_pass yourapp:9000;
        fastcgi_index index.php;
        include fastcgi.conf;
    }
}

Notice we've substituted the link alias name yourapp, we will use the same name when creating the link.

Copy the virtual host above, saving the file somewhere on your host. We will mount it as a volume in our nginx container.

Step 2: Run the PHP-FPM image with a specific name

Docker's linking system uses container ids or names to reference containers. We can explicitly specify a name for our PHP-FPM server to make it easier to connect to other containers.

docker run -it --name phpfpm -v /path/to/php/app:/app exira/php-fpm

or using Docker Compose:

phpfpm:
  image: exira/php-fpm
  volumes:
    - /path/to/php/app:/app

Step 3: Run the nginx image and link it to the PHP-FPM server

Now that we have our PHP-FPM server running, we can create another container that links to it by giving Docker the --link option. This option takes the id or name of the container we want to link it to as well as a hostname to use inside the container, separated by a colon. For example, to have our PHP-FPM server accessible in another container with yourapp as it's hostname we would pass --link phpfpm:yourapp to the Docker run command.

docker run -it -v /path/to/vhost.conf:/exira/nginx/conf/vhosts/yourapp.conf \
  --link phpfpm:yourapp \
  exira/nginx

or using Docker Compose:

nginx:
  image: exira/nginx
  links:
    - phpfpm:yourapp
  volumes:
    - /path/to/vhost.conf:/exira/nginx/conf/yourapp.conf

We started the nginx server, mounting the virtual host we created in Step 1, and created a link to the PHP-FPM server with the alias yourapp.

Docker Pull Command
Owner
exira
Source Repository

Comments (0)