I installed php fpm on ubuntu, and enabled the proxy_fcgi module. I created a test file that just calls phpinfo, but since I switched to php fpm, when I hit the page, instead of executing the php code, apache just returns a page that contains the php source. I don’t find any error in the logs.
I’ll provide the relevant config files I modified and relevant commands below. Any idea what I did wrong?
$ cat /etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
<FilesMatch .php$>
SetHandler “proxy:unix:/run/php/php8.1-fpm.sock|fcgi://localhost/”
</FilesMatch>
</VirtualHost>
$ ls /etc/apache2/mods-enabled/
access_compat.load autoindex.conf filter.load proxy_fcgi.load
alias.conf autoindex.load mime.conf proxy_http.load
alias.load deflate.conf mime.load reqtimeout.conf
auth_basic.load deflate.load mpm_event.conf reqtimeout.load
authn_core.load dir.conf mpm_event.load setenvif.conf
authn_file.load dir.load negotiation.conf setenvif.load
authz_core.load env.load negotiation.load status.conf
authz_host.load fcgid.conf proxy.conf status.load
authz_user.load fcgid.load proxy.load
$ cat /etc/ec2_version
Ubuntu 22.04.3 LTS (Jammy Jellyfish)
# systemctl restart php8.1-fpm && systemctl restart apache2
# tail -n 3 /var/log/apache2/error.log
[Fri Apr 26 13:58:35.327295 2024] [mpm_event:notice] [pid 31924:tid 281446406930464] AH00492: caught SIGWINCH, shutting down gracefully
[Fri Apr 26 13:58:35.442722 2024] [mpm_event:notice] [pid 32194:tid 261126812663840] AH00489: Apache/2.4.52 (Ubuntu) mod_fcgid/2.3.9 configured -- resuming normal operations
[Fri Apr 26 13:58:35.442845 2024] [core:notice] [pid 32194:tid 261126812663840] AH00094: Command line: '/usr/sbin/apache2'
I hit the phpinfo.php page and expected to see the details of the php environment. Instead I got the source code of the page:
$ ls -l /var/www/html/phpinfo.php
-rwxr-xr-x 1 www-data www-data 20 Mar 30 12:02 /var/www/html/phpinfo.php
$ cat /var/www/html/phpinfo.php
<?php
phpinfo();
?>
$ curl http://localhost/phpinfo.php
<?php
phpinfo();
?>