Home  >  Q&A  >  body text

Creating a container causes PHP-FPM to fail to start

I made a Dockerfile, but when I run it and get into the container, the php8.0-fpm service is not running.

How to make it run at build time? Note that I ran the command service php8.0-fpm start in the Dockerfile, but even then it didn't run.

How to make the php8.0-fpm service start with the container?

The following is the Dockerfile I made:

FROM ubuntu:jammy

ENV DEBIAN_FRONTEND=noninteractive

# Instalação Apache e PHP

RUN apt-get update && 
    apt-get install software-properties-common -y && 
    add-apt-repository ppa:ondrej/php -y && 
    apt-get update && 
    apt-get install -y 
    apache2 
    libapache2-mod-php8.0 
    libapache2-mod-php 
    php8.0-fpm 
    libapache2-mod-fcgid 

# Alteração sequência index

COPY /src/dir.conf /etc/apache2/mods-enabled

# Commitando a nova configuração

RUN service apache2 restart
RUN service php8.0-fpm restart

# Inserindo página info.php

COPY /src/info.php /var/www/html

# Alterando módulos de multiprocessamento

RUN service apache2 stop && 
    a2dismod php8.0 && 
    a2dismod php8.1 && 
    a2dismod mpm_prefork && 
    a2enmod mpm_event && 
    a2enconf php8.0-fpm && 
    a2enmod proxy && 
    a2enmod proxy_fcgi && 
    service apache2 restart && 
    service php8.0-fpm start

# Entrypoint para o conteiner iniciar o Apache

ENTRYPOINT ["apache2ctl", "-D", "FOREGROUND"]```


P粉151720173P粉151720173371 days ago705

reply all(2)I'll reply

  • P粉463418483

    P粉4634184832023-11-07 20:32:06

    You need to run php fpm on startup. You can do this if bash is installed in your virtual machine operating system.

    Stop signal SIGTERM

    CMD ["/bin/bash", "-c", "php-fpm8 && include your apache here"]

    Complete Guide: How to set up PHP 8, NGINX and PHP-FPM using docker

    reply
    0
  • P粉476475551

    P粉4764755512023-11-07 13:07:41

    I managed to keep it in a container, PHP has an extension called Supervisor and after installation we were able to start two or more services inside the container.

    Dockerfile looks like this:

    FROM httpd:2.4-alpine
    
    RUN apk update && \
        apk add \
        php \
        php-fpm \
        php-zip \
        composer \
        supervisor
    
    COPY . /usr/local/apache2/htdocs
    COPY httpd.conf /usr/local/apache2/conf/httpd.conf
    COPY supervisor /etc/supervisor
    
    WORKDIR /usr/local/apache2/htdocs
    
    CMD ["supervisord","-n", "-c", "/etc/supervisor/supervisord.conf"]

    I created two configuration files for Supervisor.

    apache.conf

    [program:apache]
    command=httpd -DFOREGROUND
    autostart=true
    autorestart=true
    priority=10
    startretries=1
    startsecs=1
    stdout_logfile=/dev/stdout
    stdout_logfile_maxbytes=0
    stderr_logfile=/dev/stderr
    stderr_logfile_maxbytes=0

    fpm.conf

    [program:php-fpm]
    command = php-fpm8 --nodaemonize 
    autostart=true
    autorestart=true
    priority=5
    stdout_logfile=/dev/stdout
    stdout_logfile_maxbytes=0
    stderr_logfile=/dev/stderr
    stderr_logfile_maxbytes=0

    At this point, the two services are started and running perfectly!

    reply
    0
  • Cancelreply