Score:0

php8.1 does not work with the php handler php8.1-fpm : the browser displays the php source code

de flag

I have installed the following Ubuntu repository packages on Ubuntu 22.04.1 LTS :

$ dpkg -l apache2 php php-fpm libapache2-mod-php libapache2-mod-fcgid
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                 Version           Architecture Description
+++-====================-=================-============-=========================================================================
ii  apache2              2.4.52-1ubuntu4.1 amd64        Apache HTTP Server
ii  libapache2-mod-fcgid 1:2.3.9-4         amd64        FastCGI interface module for Apache 2
ii  libapache2-mod-php   2:8.1+92ubuntu1   all          server-side, HTML-embedded scripting language (Apache 2 module) (default)
ii  php                  2:8.1+92ubuntu1   all          server-side, HTML-embedded scripting language (default)
ii  php-fpm              2:8.1+92ubuntu1   all          server-side, HTML-embedded scripting language (FPM-CGI binary) (default)
$ apache2 -v
Server version: Apache/2.4.52 (Ubuntu)
Server built:   2022-06-14T12:30:21
$ php -v
PHP 8.1.2-1ubuntu2.6 (cli) (built: Sep 15 2022 11:30:49) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.2-1ubuntu2.6, Copyright (c), by Zend Technologies
$

but php8.1 does not work with the php handler php8.1-fpm : the browser displays the php source code.

I have this configuration in my VirtualHost :

$ grep -1 php/ /etc/apache2/sites-enabled/helpdesk.media-participations.com-ssl.conf
        <FilesMatch \.php$>
                SetHandler "proxy:unix:/run/php/php8.1-fpm.sock|fcgi://localhost/"
        </FilesMatch>

and here is the status :

$ \ls -l /run/php/php8.1-fpm.*
-rw-r--r-- 1 root     root     5 Nov  4 15:10 /run/php/php8.1-fpm.pid
srw-rw---- 1 www-data www-data 0 Nov  4 15:10 /run/php/php8.1-fpm.sock
$ a2query -m | grep php
php8.1 (enabled by site administrator)
$ sudo a2dissite 000-default
Site 000-default disabled.
To activate the new configuration, you need to run:
  systemctl reload apache2
$ sudo systemctl reload apache2
$ systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-11-04 16:22:18 CET; 2s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 76811 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 76816 (apache2)
      Tasks: 7 (limit: 9365)
     Memory: 17.7M
        CPU: 102ms
     CGroup: /system.slice/apache2.service
             ├─76816 /usr/sbin/apache2 -k start
             ├─76817 /usr/sbin/apache2 -k start
             ├─76818 /usr/sbin/apache2 -k start
             ├─76819 /usr/sbin/apache2 -k start
             ├─76820 /usr/sbin/apache2 -k start
             ├─76821 /usr/sbin/apache2 -k start
             └─76822 /usr/sbin/apache2 -k start

Nov 04 16:22:18 my-server systemd[1]: Starting The Apache HTTP Server...
Nov 04 16:22:18 my-server apachectl[76814]: AH00558: apache2: Could not reliably determine the server_s fully qualified domain name, using 127.0.1.1. Set the 'ServerName'>
Nov 04 16:22:18 my-server systemd[1]: Started The Apache HTTP Server.
$ apachectl configtest
AH00558: apache2: Could not reliably determine the server_s fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
Syntax OK
$ systemctl status php8.1-fpm.service
● php8.1-fpm.service - The PHP 8.1 FastCGI Process Manager
     Loaded: loaded (/lib/systemd/system/php8.1-fpm.service; enabled; vendor preset:>
     Active: active (running) since Fri 2022-11-04 15:10:01 CET; 1h 22min ago
       Docs: man:php-fpm8.1(8)
    Process: 76090 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php>
   Main PID: 76087 (php-fpm8.1)
     Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
      Tasks: 3 (limit: 9365)
     Memory: 11.1M
        CPU: 471ms
     CGroup: /system.slice/php8.1-fpm.service
             ├─76087 "php-fpm: master process (/etc/php/8.1/fpm/php-fpm.conf)" "" "">
             ├─76088 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ">
             └─76089 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ">

Nov 04 15:10:01 my-server systemd[1]: Starting The PHP 8.1 FastCGI Process Manager>
Nov 04 15:10:01 my-server systemd[1]: Started The PHP 8.1 FastCGI Process Manager.
$ ps -fC php-fpm8.1
UID          PID    PPID  C STIME TTY          TIME CMD
root       76087       1  0 15:10 ?        00:00:00 php-fpm: master process (/etc/php/8.1/fpm/php-fpm.conf)
www-data   76088   76087  0 15:10 ?        00:00:00 php-fpm: pool www
www-data   76089   76087  0 15:10 ?        00:00:00 php-fpm: pool www
$ sudo cat /var/log/php8.1-fpm.log
[04-Nov-2022 14:15:53] NOTICE: fpm is running, pid 68585
[04-Nov-2022 14:15:53] NOTICE: ready to handle connections
[04-Nov-2022 14:15:53] NOTICE: systemd monitor interval set to 10000ms
[04-Nov-2022 14:15:54] NOTICE: Terminating ...
[04-Nov-2022 14:15:54] NOTICE: exiting, bye-bye!
[04-Nov-2022 14:15:54] NOTICE: fpm is running, pid 68708
[04-Nov-2022 14:15:54] NOTICE: ready to handle connections
[04-Nov-2022 14:15:54] NOTICE: systemd monitor interval set to 10000ms
[04-Nov-2022 14:50:38] NOTICE: Terminating ...
[04-Nov-2022 14:50:38] NOTICE: exiting, bye-bye!
[04-Nov-2022 15:10:01] NOTICE: fpm is running, pid 76067
[04-Nov-2022 15:10:01] NOTICE: ready to handle connections
[04-Nov-2022 15:10:01] NOTICE: systemd monitor interval set to 10000ms
[04-Nov-2022 15:10:01] NOTICE: Terminating ...
[04-Nov-2022 15:10:01] NOTICE: exiting, bye-bye!
[04-Nov-2022 15:10:01] NOTICE: fpm is running, pid 76087
[04-Nov-2022 15:10:01] NOTICE: ready to handle connections
[04-Nov-2022 15:10:01] NOTICE: systemd monitor interval set to 10000ms
$

And here is what I get :

$ curl -k https://localhost/info.php
<?php
phpinfo();
phpinfo(INFO_MODULES);
?>

I seems the php code in not interpreted by the server.

How can I fix this ?

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.