LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Containers (https://www.linuxquestions.org/questions/linux-containers-122/)
-   -   Why Apache container can't see PHP container? (https://www.linuxquestions.org/questions/linux-containers-122/why-apache-container-cant-see-php-container-4175735252/)

Jason.nix 03-24-2024 01:08 PM

Why Apache container can't see PHP container?
 
Hello,
I have two YAML files as follows:
Code:

version: '3.9'
networks:
  phpnet:
    driver: bridge
    name: My_Network
services:
  web:
    image: nginx:latest
    ports:
      - '8080:80'
    volumes:
      - ./default.conf:/etc/nginx/conf.d/default.conf
      - /var/www/html:/usr/share/nginx/html
    networks:
      - phpnet
    depends_on:
      - php-fpm
  php-fpm:
    image: php:8-fpm
    volumes:
      - /var/www/html:/usr/share/nginx/html/
      - /var/www/html:/usr/local/apache2/htdocs/
    networks:
      - phpnet

And:
Code:

version: '3.9'
networks:
  apache:
    external: true
    name: My_Network
services:
    httpd:
        ports:
            - '80:80'
        volumes:
            - /var/www/html:/usr/local/apache2/htdocs/
            - ./httpd.conf:/usr/local/apache2/conf/httpd.conf
        image: 'httpd:latest'
        networks:
            - apache

The network is also built by Docker:
Code:

# docker network list
NETWORK ID    NAME              DRIVER    SCOPE
b36954410da3  My_Network        bridge    local
385e912fff96  bridge            bridge    local
7b3a9c0ec7dd  host              host      local
fb5635eda3c3  nginx-php_phpnet  bridge    local
d851ead577b7  none              null      local
b13678883aac  redis_default      bridge    local

But:
Code:

# curl http://172.20.2.58:8080/index.php
Testing PHP-FPM on Docker.
#
# curl http://172.20.2.58:80/index.php
<?php
echo "Testing PHP-FPM on Docker."
?>

As you can see, Apache cannot compile PHP file. What is wrong?

Thank you.

Jason.nix 03-27-2024 08:42 AM

Hello,
This problem was solved by adding the following lines to the httpd.conf file:
Code:

LoadModule proxy_module modules/mod_proxy.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>


DocumentRoot "/usr/local/apache2/htdocs"
<Directory "/usr/local/apache2/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride None
Require all granted
</Directory>

<IfModule proxy_module>
    <FilesMatch "\.php$">
        SetHandler  "proxy:fcgi://php-fpm:9000"
    </FilesMatch>
</IfModule>



All times are GMT -5. The time now is 01:21 AM.