Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use PHP-FPM from a bash script?

Tags:

bash

php

fpm

I know php-fpm isn't intended to be used from bash as much as, say, php-cli, but I'm making a common interface for my website from both my broswer and the command line, and I need the executing version to be exactly the same.

echo '<?php echo 1' | socat - UNIX-CLIENT:/var/run/php/php7.2-fpm.sock

doesn't work, but I guess it is maybe because I don't extract the output, but either way I wouldn't know how to do that.

Any idea ?

like image 759
Pierre-Antoine Guillaume Avatar asked Apr 09 '26 10:04

Pierre-Antoine Guillaume


1 Answers

You should not. As @Barmar pointed out in the comments, just ensure php-cli has the same php.ini file loaded as php-fpm. Then just call php from bash. For me, the solution in an docker environment was to add the last line in this example docker-compose.yml

    php-fpm:
        build: phpdocker/php-fpm
        working_dir: /app
        environment:
            PHP_IDE_CONFIG: "serverName=Docker"
        volumes:
            - '../xy:/xy'
            - './phpdocker/php-fpm/php-ini-overrides.ini:/etc/php/8.1/fpm/conf.d/99-overrides.ini'
            - './phpdocker/php-fpm/php-ini-overrides.ini:/etc/php/8.1/cli/conf.d/99-overrides.ini'

Where /phpdocker/php-fpm/php-ini-overrides.ini is my custom ini file.

like image 59
Primoz990 Avatar answered Apr 12 '26 02:04

Primoz990



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!