Home > Software design >  Issues Starting PHP-FPM using Ubuntu Docker
Issues Starting PHP-FPM using Ubuntu Docker

Time:01-05

It seems the PHP FPM silently fails to start. There is nothing where the FPM logs would be.

Docker File

FROM ubuntu:16.04

RUN apt-get update -y && apt-get install -y software-properties-common language-pack-en-base && apt-get install sudo -y

RUN LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php

RUN apt-get -y update && apt-get install -y \
    php7.0-fpm \
    php7.0-common \
    php7.0-opcache \
    php7.0-bcmath \
    php7.0-pspell \
    php7.0-recode \
    php7.0-cli \
    php7.0-tidy \
    php7.0-dev \
    php7.0-curl \
    php7.0-gd \
    php7.0-imap \
    php7.0-intl \
    php7.0-json \
    php7.0-ldap \
    php7.0-mbstring \
    php7.0-mcrypt \
    php7.0-mysql \
    php7.0-pgsql \
    php7.0 \
    php7.0-xml \
    php-memcached \
    php-redis

# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

## Make PHP FPM Log Dir
RUN mkdir -p /var/log/php7.0-fpm

## Copy and set PHP config files
COPY /containers/config/php-fpm.conf /etc/php/7.0/fpm/conf
COPY /containers/config/php.ini /etc/php/7.0/fpm/
COPY /containers/config/www.conf /etc/php/7.0/fpm/pool.d/

# Make App dir
RUN mkdir -p /app

# Switch to new App dir
WORKDIR /App

# Add contents of my-application project
ADD . /my-application

# Install dependencies with composer
RUN composer dump-autoload

# Expose port for php-fpm
EXPOSE 9000

CMD ["sudo service php7.0-fpm start"]

When checking if the configs are there, they are.

root@b8f3677b721b:/etc/php/7.0/fpm# ls -la
total 112
drwxr-xr-x 1 root root  4096 Jan  4 15:34 .
drwxr-xr-x 1 root root  4096 Jan  3 22:45 ..
-rw-r--r-- 1 root root  4424 Jan  4 15:34 conf
drwxr-xr-x 2 root root  4096 Jan  3 22:46 conf.d
-rw-r--r-- 1 root root  4421 Oct  8  2020 php-fpm.conf
-rw-r--r-- 1 root root 71010 Dec 22 16:37 php.ini
drwxr-xr-x 1 root root  4096 Jan  4 15:34 pool.d

PHP version is proper

root@b8f3677b721b:/etc/php/7.0/fpm# php -v
PHP 7.0.33-0ubuntu0.16.04.16 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.33-0ubuntu0.16.04.16, Copyright (c) 1999-2017, by Zend Technologies

Trying to call the init script directly in a invalid way seems to indicate that it is there.

root@b8f3677b721b:/etc/init.d# sh php7.0-fpm
Usage: /etc/init.d/php-fpm7.0 {start|stop|status|restart|reload|force-reload}

Trying to run php-fpm manually in the container, this is the result

root@b8f3677b721b:/etc# sudo service php7.0-fpm start
root@b8f3677b721b:/etc# ps -aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0   4380   656 ?        Ss   15:35   0:00 sleep infinity
root         8  0.0  0.0  18348  3408 pts/0    Ss   15:35   0:00 /bin/bash
root

   256  0.0  0.0  34428  2924 pts/0    R    16:11   0:00 ps -aux

At a loss for what else to try and do here. I have read many other questions, but none of the answers/accepted solutions seem to work. Not sure if it matters, I am running Nginx in a different container while referencing the host name in the nginx config.

CodePudding user response:

You don't need to use the PHP-FPM service, you can just use the php-fpm command at the end like so:

CMD php-fpm

Moreover, if you don't need the extra stuff provided by the ubuntu image, you should switch to the php-fpm images so that it only uses what's required. Your final container will be lighter and will be less susceptible to security troubles if I remember correctly. You also will be able to finely select the PHP version you want to use.

  •  Tags:  
  • Related