Skip to content
Advertisement

devspace: from unique deployment PHP:apache to PHP-FPM + Nginx

How can I do a PHPFPM+Nginx deployment for devspace?

Actually, I’m working with PHP-Apache and have this devspace.yaml

[...]
deployments:
- name: panel
  helm:
    componentChart: true
    values:
      containers:
      - image: registry.digitalocean.com/mycompany/myapp
      service:
        ports:
        - port: 80
      ingress:
        rules:
        - host: "mydomain.com.ar"

My Dockerfile is like

FROM php:7.4.4-apache
[...]
EXPOSE 80
CMD ["apache2-foreground"]

All is working fine and Host is registered on Ingress. But, I like to upgrade from PHPApache to PHP-FPM + Nginx.

I change my Dockerfile from FROM php:7.4.4-apache to FROM php:7.4.4-fpm and EXPOSE and COMMAND are removed. But now? Particular configurations for PHP and NGinx are no neccesary now.

Then, how can I add nginx service to devspace.yaml and connect to php-fpm?

Advertisement

Answer

devspace.yaml:

version: v1beta9
images:
  app-nginx:
    image: registry.digitalocean.com/reyesoft/app-nginx
    dockerfile: build/nginx/Dockerfile
    # preferSyncOverRebuild: true
    preferSyncOverRebuild: true
    appendDockerfileInstructions:
      - USER root
  app-php:
    image: registry.digitalocean.com/reyesoft/app-php
    dockerfile: build/php/Dockerfile
    preferSyncOverRebuild: true
    injectRestartHelper: true
    appendDockerfileInstructions:
    - USER root
deployments:
- name: app
  helm:
    componentChart: true
    values:
      containers:
      - name: app-nginx
        image: registry.digitalocean.com/reyesoft/app-nginx
      - name: panel
        image: registry.digitalocean.com/reyesoft/app-php
        env: &panelEnv
          - name: APP_ENV
            value: "develop"
      service:
        ports:
          - port: 80
      ingress:
        # tls: true
        rules:
          - host: "reyesoft.com"
[...]

nginx.conf:

server {

    # [...]

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ .php$ {
        root           /usr/share/nginx/html/public/;

        include php_location.include/*.conf;

        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        # fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;
        fastcgi_param   SCRIPT_FILENAME         $fastcgi_script_name;
        include        fastcgi_params;
    }
}
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement