PrestaShop / docker

🐳
https://hub.docker.com/r/prestashop/prestashop/
MIT License
257 stars 176 forks source link

PS 8.1.3-8.1-fpm conf #367

Closed elclay7 closed 5 months ago

elclay7 commented 6 months ago

Hi,

I hope some good Samaritan can help me. I have been trying to build a Prestashop with fpm for several days, Prestashop:8.1.3-8.1-fpm, since according to the official documentation it works much faster than the simple version with Apache Prestashop:8.1.3-8.1-apache. The truth is that trying to configure the Apache webservice to communicate correctly with the Prestashop container has given me quite a few headaches, which led me to the following question:

Why does the image presashop:8.1.3-8.1-fpm not have Apache included as a webservice?

According to what I think I have understood, container Apache makes the web resources available and container Prestashop handles the PHP requests, and we absolutely need a webservice for it to work. Now after many attempts it didn't work for me, but I'm sharing my Docker-compose with you, I know there are more people like me out there.

Container: ps-test-fpm-ws | image: php:8.1.3-apache Container: ps-test-fpm-app | image: prestashop/prestashop:8.1.3-8.1-fpm Container: ps-test-fpm-db | image: mariadb:10.5.8

version: "3.6"
services:

  ps-test-fpm-ws:
    image: php:8.1.3-apache
    container_name: ps-test-fpm-ws
    restart: unless-stopped
    ports:
      - 9008:80
    volumes:
      - /storage01/ps-test-fpm/app/html:/var/www/html
      - /storage01/ps-test-fpm/ws/sites-available/000-default.conf:/etc/apache2/sites-available/000-default.conf

  ps-test-fpm-app:
    image: prestashop/prestashop:8.1.3-8.1-fpm
    container_name: ps-test-fpm-app
    restart: unless-stopped
    environment:
      - PS_INSTALL_AUTO=0
      - TZ=America/Santiago
    ports:
      - 9007:9000
    volumes:
      - /storage01/ps-test-fpm/app/html:/var/www/html

  ps-test-fpm-db:
    image: mariadb:10.5.8
    container_name: ps-test-fpm-db
    restart: unless-stopped
    environment:
      - MYSQL_ROOT_PASSWORD=devpassroot
      - MYSQL_DATABASE=devdb
      - MYSQL_USER=devuser
      - MYSQL_PASSWORD=devpass
      - MYSQL_ALLOW_EMPTY_PASSWORD=no
      - TZ=America/Santiago
    expose:
      - 3306
    volumes:
      - /storage01/ps-test-fpm/db/data:/var/lib/mysql

/etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        <FilesMatch \.php$>
            SetHandler "proxy:fcgi://ps-test-fpm-app:9000"
        </FilesMatch>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Captura de pantalla 2024-01-25 191000

What am I doing wrong?

Can any good samaritan share a conf that works?

elclay7 commented 5 months ago

Finally I was able to achieve it. I share the configuration for those who are suffering like me

docker-compose

version: "3.6"
services:

  psldmcl-ws:
    image: httpd:2.4.58-alpine
    container_name: psldmcl-ws
    restart: unless-stopped
    ports:
      - 7480:80
    volumes:
      - /storage/psldmcl/app/html:/var/www/html
      - /storage/psldmcl/ws/httpd.tuning:/usr/local/apache2/conf/httpd.conf:ro
    networks:
      - default

  psldmcl-app:
    image: prestashop/prestashop:8.1.3-8.1-fpm
    container_name: psldmcl-app
    restart: unless-stopped
    environment:
      - DB_SERVER=psldmcl-db
      - DB_USER=dbuser
      - DB_PASSWD=dbpassword
      - DB_PREFIX=ps_
      - DB_NAME=dbname
    expose:
      - 9000
    volumes:
      - /storage/psldmcl/app/html:/var/www/html
      - /storage/psldmcl/app/tuning.ini:/usr/local/etc/php/conf.d/tuning.ini:ro
    depends_on:
      - psldmcl-db
    networks:
      - default

  psldmcl-db:
    image: mariadb:10.5.8
    container_name: psldmcl-db
    restart: unless-stopped
    environment:
      - MYSQL_ROOT_PASSWORD=rootpassword
      - MYSQL_DATABASE=dbname
      - MYSQL_USER=dbuser
      - MYSQL_PASSWORD=dbpassword
      - MYSQL_ALLOW_EMPTY_PASSWORD=no
    expose:
      - 3306
    volumes:
      - /storage/psldmcl/db/data:/var/lib/mysql
      - /storage/psldmcl/db/tuning.cnf:/etc/mysql/conf.d/tuning.cnf:ro
    networks:
      - default

networks:
  default:
    driver: bridge

httpd conf In my case /storage/psldmcl/ws/httpd.tuning:/usr/local/apache2/conf/httpd.conf:ro

ServerName localhost
ServerRoot "/usr/local/apache2"
ServerAdmin www-admin@foo.example.com
Listen 80

LoadModule mpm_event_module modules/mod_mpm_event.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule access_compat_module modules/mod_access_compat.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule reqtimeout_module modules/mod_reqtimeout.so
LoadModule filter_module modules/mod_filter.so
LoadModule mime_module modules/mod_mime.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule env_module modules/mod_env.so
LoadModule headers_module modules/mod_headers.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule version_module modules/mod_version.so
LoadModule unixd_module modules/mod_unixd.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule expires_module modules/mod_expires.so
LoadModule remoteip_module modules/mod_remoteip.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule dir_module modules/mod_dir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so

<IfModule unixd_module>
User daemon
Group daemon
</IfModule>

RemoteIPHeader X-Forwarded-For
RemoteIPTrustedProxy 172.28.0.0/16

ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://psldmcl-app:9000/var/www/html/$1
DirectoryIndex /index.php index.php

<Directory />
    AllowOverride none
    Require all denied
</Directory>

DocumentRoot "/var/www/html/"

<Directory "/var/www/html/">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

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

<Files ".ht*">
    Require all denied
</Files>

ErrorLog /proc/self/fd/2

LogLevel warn

<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    CustomLog /proc/self/fd/1 common

</IfModule>

<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/usr/local/apache2/cgi-bin/"
</IfModule>

<IfModule cgid_module>
</IfModule>

<Directory "/usr/local/apache2/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

<IfModule mod_headers.c>
 <FilesMatch "\.(ico|jpe?g|png|gif|css|woff2)$">
   Header set Cache-Control "max-age=2592000, public"
 </FilesMatch>
</IfModule>

<IfModule mime_module>
    TypesConfig conf/mime.types

    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
</IfModule>

<IfModule proxy_html_module>
Include conf/extra/proxy-html.conf
</IfModule>

<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>

<IfModule deflate_module>
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE application/json application/x-javascript  text/javascript application/javascript text/js
  AddOutputFilterByType DEFLATE text/xml application/xml application/xml+rss text/javascript application/javascript
  AddOutputFilterByType DEFLATE image/svg+xml
</IfModule>

<IfModule mod_expires.c>
  AddType application/x-font-woff .woff
  AddType image/svg+xml .svg

  ExpiresActive On

  ExpiresDefault "access plus 7200 seconds"
  ExpiresByType image/jpg "access plus 1 month"
  ExpiresByType image/jpeg "access plus 1 month"
  ExpiresByType image/gif "access plus 1 month"
  ExpiresByType image/png "access plus 1 month"
  ExpiresByType image/x-icon "access plus 1 month"
  ExpiresByType application/x-font-woff "access plus 1 month"
  <FilesMatch \.php$>
    # Do not allow PHP scripts to be cached unless they explicitly send cache headers themselves.
    ExpiresActive Off
  </FilesMatch>
</IfModule>

<IfModule mpm_event_module>
    ServerLimit             16
    MaxClients              400
    StartServers            3
    ThreadLimit             64
    ThreadsPerChild         25
    MaxRequestWorkers       400
    MaxConnectionsPerChild  0
</IfModule>

Modify with the name and port of your container ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://psldmcl-app:9000/var/www/html/$1