php icon indicating copy to clipboard operation
php copied to clipboard

PHP: syntax error, unexpected '=' in /usr/local/etc/php/conf.d/zz-generated-settings.ini

Open Thijmen opened this issue 2 years ago • 10 comments

Hi there,

After not having to build an image with shinsenter/php:8.2-fpm-apache, I built one today and resulted in the following error when running PHP;

php -v
PHP:  syntax error, unexpected '=' in /usr/local/etc/php/conf.d/zz-generated-settings.ini on line 23
PHP 8.2.24 (cli) (built: Sep 27 2024 06:51:37) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.24, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.24, Copyright (c), by Zend Technologies

The file looks like this:

[PHP]
allow_url_include = 0
date.timezone = Europe/Amsterdam
display_errors = 0
error_log = /proc/1/fd/2
expose_php = 0
mail.log = /proc/1/fd/2
max_execution_time = 240
memory_limit = 1024M
opcache.enable = 1
opcache.error_log = /proc/1/fd/2
opcache.jit_debug = 0
opcache.max_accelerated_files = 130987
opcache.preload_user = www-data
post_max_size = 600M
report_zend_debug = 0
request_order = GP
session.cookie_httponly = 1
session.cookie_lifetime = 0
session.cookie_samesite = Lax
session.cookie_secure = 0
session.save_handler = redis
session.save_path = tcp://some-secret-value:6379?auth=someauth
session.use_cookies = 1
syslog.facility = syslog
upload_max_filesize = 100M
variables_order = EGPCS

; Generated at 2024-10-09 15:55:35

Seems to be related to this file: https://github.com/shinsenter/php/blob/main/src/php/common/shell-php/php-envvars#L44C18-L44C25

It looks like it seems not to be that happy with the double = on like with session.save_path. What is a better way to handle this?

Thijmen avatar Oct 09 '24 16:10 Thijmen

By the way, running php-envvars does show it correctly:

PHP_SESSION_SAVE_PATH='tcp://some-secret-value:6379?auth=someauth'

Thijmen avatar Oct 09 '24 17:10 Thijmen

@Thijmen

Thank you for the feedback regarding this issue.

I'm not sure if I can test and fix it soon, but I'd like you to try setting the environment variable ALLOW_RUNTIME_PHP_ENVVARS=1 for your container to see if it might temporarily resolve the issue for you.

Best regards

shinsenter avatar Oct 10 '24 04:10 shinsenter

Indeed, it looks like that works for now! Thanks

Thijmen avatar Oct 10 '24 07:10 Thijmen

I am glad hearing it’s working

shinsenter avatar Oct 10 '24 07:10 shinsenter

@Thijmen

The patched Docker images will also be updated shortly after the official Docker images for PHP 8.4 are released.

I hope the issue you're facing will soon be resolved when using the latest Docker images.

shinsenter avatar Nov 21 '24 08:11 shinsenter

I have the same problem.

Using the version with php 8.2.25, I needed to put redis connection url inside double quotes in env var and it works.

The generated file /usr/local/etc/php/conf.d/zz-generated-settings.ini becomes: session.save_path = "tcp://redis:6379?auth=test"

After using the version with php 8.2.26 this workaround doesn't work anymore. The generated file /usr/local/etc/php/conf.d/zz-generated-settings.ini starts to be session.save_path = "\"tcp://redis:6379?auth\=test\""

I tried to remove the quotes from env var, so the result is session.save_path = "tcp://redis:6379?auth\=test"

But still not working because the = was wrongly escaped.

Any suggestions?

wsitl avatar Dec 04 '24 03:12 wsitl

Hello @wsitl, thank you for leaving feedback.

I have tested the case where the value of an environment variable for PHP contains the = character, and it works fine with the recently built Docker image versions.

I would like to know how you are currently setting the PHP_SESSION_SAVE_PATH environment variable for the container. Could you share your docker-compose.yml file or the command you use to create the container?

Additionally, there’s a possibility you are using an older Docker image without the patch. Please let me know the Docker image version displayed in the welcome message when the container starts.

I’d also like to know how the PHP_SESSION_SAVE_PATH variable is displayed when you run the php-envvars command inside the container.

I appreciate your cooperation in providing these details so I can pinpoint the issue.

Best regards.

shinsenter avatar Dec 04 '24 09:12 shinsenter

Hi @shinsenter, I'm using k8s to deploy the image:

      env:
        - name: PHP_SESSION_SAVE_HANDLER
          value: redis
        - name: PHP_SESSION_SAVE_PATH
          valueFrom:
            secretKeyRef:
              name: my-secrets
              key: PHP_REDIS

I'm using the version shinsenter/phpfpm-nginx (built: 2024-12-04T02:01:15+0000)

The php-envvars script says: PHP_SESSION_SAVE_PATH='tcp://redis:6379?auth=test'

Using phpinfo I can see the wrong escape, the same as /usr/local/etc/php/conf.d/zz-generated-settings.ini tcp://redis:6379?auth\=test

wsitl avatar Dec 04 '24 22:12 wsitl

After I stop using double quotes AND start use ALLOW_RUNTIME_PHP_ENVVARS=1, it works!

wsitl avatar Dec 04 '24 22:12 wsitl

@wsitl

I'm glad to know that ALLOW_RUNTIME_PHP_ENVVARS=1 made it work.

Using phpinfo I can see the wrong escape, the same as /usr/local/etc/php/conf.d/zz-generated-settings.ini tcp://redis:6379?auth\=test

According to the INI file syntax standard, escaping special characters like = is necessary and is not considered an error. Therefore, the appearance of \= in the zz-generated-settings.ini file is completely valid. https://en.wikipedia.org/wiki/INI_file#Escape_characters

shinsenter avatar Dec 05 '24 00:12 shinsenter