Update PHP Version not working

Hello,

since almost 1 or 2 weeks ago my Shopify PHP app deployed on Fly.io gives me the error:
"Your Composer dependencies require a PHP version '>= 8.2.0'. You are running 8.1.27."

I so tried to change the build.args values in the fly.toml file as suggested in docs: PHP and Node Versions · Fly Docs

As follow:

[build]
  [build.args]
    PHP_VERSION = "8.3"
    NODE_VERSION = "18"

But I still get the same error and if I connect to the machine console with ssh and run php -v I get:

222222222:/app# php -v
PHP 8.1.27 (cli) (built: Dec 28 2023 00:53:44) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.27, Copyright (c) Zend Technologies
222222222:/app#

I also tried to override the setting adding --build-arg "PHP_VERSION=8.3" --build-arg "NODE_VERSION=18" but without any result…

How can I do?

Thank you

What’s your Dockerfile and composer.json look like?

1 Like

Hmmm I thought we built PHP 8.3 base images, that should work in theory! But yeah, show the Docker image and fly.toml as it might be using a buildpack or something else.

1 Like

Here is the fly.toml

app = "aaaaaaaaaaaaaaa"
primary_region = "cdg"

[build]
  [build.args]
    PHP_VERSION = "8.3"
    NODE_VERSION = "18"

[env]
  APP_ENV = "production"
  APP_KEY = "base64:aaaaaaaaaaaaaaaaaaaaaaaaaaa"
  APP_NAME = "AAAAAAAAAAAAAAA"
  DB_CONNECTION = "sqlite"
  DB_DATABASE = "/data/db.sqlite"
  HOST = "https://aaaaaaa.fly.dev"
  PORT = "8080"
  SCOPES = "read_orders, read_all_orders "
  SHOPIFY_API_KEY = "AAAAAAAAAAAAAAAAAAAAA"

[mounts]
  source = "litefs"
  destination = "/data"

[http_service]
  internal_port = 8080
  force_https = true
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 0

[[services]]
  protocol = ""
  internal_port = 8080

And here is the dockerfile:

FROM php:8.1-fpm-alpine

ARG SHOPIFY_API_KEY

ENV SHOPIFY_API_KEY=$SHOPIFY_API_KEY

RUN apk update && apk add --update nodejs npm \

composer php-pdo_sqlite php-pdo_mysql php-pdo_pgsql php-simplexml php-fileinfo php-dom php-tokenizer php-xml php-gd php-xmlwriter php-xmlreader php-session \

openrc bash nginx ca-certificates fuse3

RUN docker-php-ext-install pdo

COPY --chown=www-data:www-data web /app

COPY --from=flyio/litefs:0.5 /usr/local/bin/litefs /usr/local/bin/litefs

WORKDIR /app

# Overwrite default nginx config

COPY web/nginx.conf /etc/nginx/nginx.conf

# Use the default production configuration

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

RUN composer update

RUN composer install

# RUN touch /data/db.sqlite

# RUN chown www-data:www-data /data/db.sqlite

RUN cd frontend && npm install && npm run build

RUN composer build

ENTRYPOINT [ "/app/entrypoint.sh" ]

Looking at the docker file I guess it may be the image… sorry I have not that much of experience with Docker unfortunately

Thanks!

The issue

So Fly works by building a Docker image and deploying that as a “real” VM (not a container, the docker image is just a convenient way to ship an application and its runtime- php in this case).

Your Dockerfile is using a setup that wasn’t generated by fly launch - in other words, our PHP (laravel, really) docs aren’t geared towards your (custom?) Dockerfile being used.

Solution

In this case, it’s likely that the following change to the Dockerfile will make it Just Work™ for you, using PHP 8.3:

- FROM php:8.1-fpm-alpine
+ FROM php:8.3-fpm-alpine

ARG SHOPIFY_API_KEY

# Remaining Dockerfile omitted for brevity

Last note

You may want to consider moving the APP_KEY and SHOPIFY_API_KEY environment variables to fly secrets (they’ll still look like environment variables to the PHP app, but they won’t be plaintext in the fly.toml file with secrets).

Let me know if that works for you!

1 Like

Very clear, thank you very much for the explanation and the tips! :pray:

(I would suggest adding a very brief sentence on the doc page to alert that the PHP version could depend on the Docker image in some cases to avoid dumb questions such as mine)

Great!

Definitely a great idea :+1::bulb:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.