dockernginxdocker-composedockerfilefpm

How to change php-fpm default port?


I'm using php-fpm which runs for default on the port 9000. The problem's that I have other docker container based on php-fpm, so I need to change the default port to another one, in order to not confuse nginx.

This is my Dockerfile:

FROM php:8.0.2-fpm-alpine
RUN sed -i 's/9000/9001/' /usr/local/etc/php-fpm.d/zz-docker.conf

WORKDIR /var/www/html

CMD ["php-fpm"]

EXPOSE 9001

I tried to use the sed command to replace the port 9000 with 9001.

Inside my docker-compose file I have this configuration:

version: '3.9'

services:

  php-fpm:
    container_name: app
    restart: always
    build:
      context: .
      dockerfile: ./docker/php-fpm/Dockerfile
    ports:
      - "9001:9000"
    volumes:
      - ./src:/var/www/html
      - ./docker/php-fpm/config/www.conf:/usr/local/etc/php-fpm.d/www.conf
      - ./src/public:/app/public
      - ./src/writable:/app/writable

  nginx:
    image: nginx:stable-alpine
    container_name: nginx
    restart: always
    volumes:
      - ./src:/var/www/html
      - ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf
      - ./docker/nginx/sites/:/etc/nginx/sites-available
      - ./docker/nginx/conf.d/:/etc/nginx/conf.d
    depends_on:
      - php-fpm
    environment:
      VIRTUAL_HOST: ${HOST}
      LETSENCRYPT_HOST: ${HOST}
      LETSENCRYPT_EMAIL: ${EMAIL}

as you can see I have exposed the port 9001 also in the docker-compose file.

The file default.conf available within conf.d folder contains this:

upstream php-upstream {
    server php-fpm:9001;
}

the problem's that for some reason, when I load my site I get the error 500. So this means that the stream doesn't send any signal. If I change to port 9000 everything works, but the stream is wrong 'cause it's the content of another application.

How can I correctly change the default port?


Solution

  • I think the problem is not the sed command itself, it's related to the wrong file you mentioned for it.

    /usr/local/etc/php-fpm.d/zz-docker.conf
    

    this is the file you are trying to change the port in it but inside your docker-compose file you are mapping something else

    ./docker/php-fpm/config/www.conf:/usr/local/etc/php-fpm.d/www.conf