php-fpm with apache on AMI 2018 linux

Primary tabs

Start with setting apache rule to prevent httproxy vulnerability.

Set this after main configuration (before serveradmin)

vi /etc/httpd/conf/httpd.conf

RequestHeader unset Proxy early

Install fpm

yum install php72-fpm

Enable mpm_event and comment out everything else

vi /etc/httpd/conf.modules.d/00-mpm.conf

LoadModule mpm_event_module modules/

Add fpm proxy

vi /etc/httpd/conf.d/php.conf

###Near end add:

<Proxy "unix:/var/run/php-fpm/default.sock|fcgi://php-fpm">
        # we must declare a parameter in here (doesn't matter which) or it'll not register the proxy ahead of time
        ProxySet disablereuse=off
        ProxySet timeout=300

<FilesMatch \.php$>
        SetHandler proxy:fcgi://php-fpm

Setup fpm socket

vi /etc/php-fpm.d/www.conf

listen = /var/run/php-fpm/default.sock

listen.allowed_clients =
listen.owner = ec2-user = www
user = ec2-user
group = www

Also comment out

listen.acl_users so it will be ;listen.acl_users

Set proper permissions:

chown -R ec2-user:www /var/lib/php/7.2/*

Enable service

chkconfig php-fpm-7.2 on

Start php-fpm

service php-fpm-7.2 start

Restart apache

service httpd restart

QR Code for