PHP-FPM not working as PHP handler in Apache

Discussion in 'Server Operation' started by iDen, Aug 26, 2013.

  1. iDen

    iDen New Member

    [SOLVED] PHP-FPM not working as PHP handler in Apache

    Maybe someone here can help :(
    I'm trying to switch global PHP handler on my server from mod_php to PHP-FPM. But something with my setup is worng. When I'm trying to open, it's being opened as standard text showing contents of file, not parsed via php:
    Httpd and php-fpm logs showing nothing.
    httpd -M - shows mod_fastcgi loaded.
    System:CentOS 6.4 x64, Apache 2.2.15.
    PHP-5.5.3 compiled from source with such configuration:
    ./configure \
    --prefix=/opt/php553-fpm \
    --with-config-file-path=/opt/php553-fpm/etc \
    --with-config-file-scan-dir=/opt/php553-fpm/etc/php.d \
    --with-pdo-pgsql \
    --with-zlib-dir \
    --with-freetype-dir \
    --enable-bcmath \
    --enable-mbstring \
    --with-libxml-dir=/usr \
    --enable-soap \
    --enable-calendar \
    --with-curl \
    --with-mcrypt \
    --with-zlib \
    --with-gd \
    --with-pgsql \
    --disable-rpath \
    --enable-inline-optimization \
    --with-bz2 \
    --with-zlib \
    --enable-sockets \
    --enable-sysvsem \
    --enable-sysvshm \
    --enable-pcntl \
    --enable-mbregex \
    --with-mhash \
    --enable-zip \
    --with-pcre-regex \
    --with-mysql \
    --with-pdo-mysql \
    --with-mysqli \
    --with-jpeg-dir=/usr \
    --with-png-dir=/usr \
    --enable-gd-native-ttf \
    --with-openssl \
    --with-libdir=lib64 \
    --enable-ftp \
    --with-imap \
    --with-imap-ssl \
    --with-kerberos \
    --with-gettext \
    --enable-fpm \
    --with-fpm-user=apache \
    php-fpm process starting normally via init.d/php-fpm, and ready to listen connections on netstat approves this info.
    mod_fastcgi - installed via yum
    my httpd/fpm.conf:
        <FilesMatch \.php$>
            SetHandler php-script
    #   AddHandler php-script .php
        Action php-script /php.external
        Alias   /php.external   /var/run/mod_fastcgi/php.fpm
        FastCGIExternalServer /var/run/mod_fastcgi/php.fpm -host
        AddType application/x-httpd-fastphp5 .php
        DirectoryIndex index.php
        <Directory "/var/run/mod_fastcgi/">
            Order deny,allow
            Deny from all
            <Files "php.fpm">
                Order allow,deny
                Allow from all
    User apache
    Group apache
    LoadModule fastcgi_module modules/
    # dir for IPC socket files
    FastCgiIpcDir /var/run/mod_fastcgi
    # wrap all fastcgi script calls in suexec
    FastCgiWrapper On
    # global FastCgiConfig can be overridden by FastCgiServer options in vhost config
    FastCgiConfig -idle-timeout 20 -maxClassProcesses 1
    php-fpm.conf and default pool 'www' confs are exactly same as everywhere on internet described in many-many tutorials which not helping me this time (. Only user and group in www.conf are "apache" - inserted during PHP compilation from source.

    Second question: PHP-FPM setup works only with files in document root?

    Right now document root for me is /var/www/html.
    But several sites like zabbix, phpmyadmin reside in "/home/vhosts" and they are subdirectories and not virtualhosts.
    I see error when I try aceess
    Directory index forbidden by Options directive: /home/vhosts/pma/
    Before I had mod_php compiled from same sources and everything worked.
    Right now it's still registered in system path, but loading of mod_php in httpd is disabled.

    So maybe someone can help me configure PHP-FPM as global php handler for system without virtual hosts.

    I had <IfModule> And it should be <IfModule mod_fastcgi.c>
    Also httpd configuration needs: SuexecUserGroup apache apache
    My fpm.conf for httpd, Tested on Apache 2.2:
    <IfModule mod_fastcgi.c>
        <FilesMatch \.php$>
            SetHandler php-script
        SuexecUserGroup apache apache
        Action php-script /php.external
        Alias   /php.external   /var/run/mod_fastcgi/php.fpm
        FastCGIExternalServer /var/run/mod_fastcgi/php.fpm -host -idle-timeout 900 -pass-header Authorization
        AddType application/x-httpd-fastphp5 .php
        DirectoryIndex index.php index.shtml index.cgi index.html index.htm
        Options +Indexes +FollowSymLinks +ExecCGI +Includes +MultiViews
        <Directory "/var/run/mod_fastcgi/">
            Order deny,allow
            Deny from all
            <Files "php.fpm">
                Order allow,deny
                Allow from all
    This configuration sets PHP-FPM as global php handler for whole server.
    You can use above code for separate virtualhosts changing FPM pools and/or SuExec arguments.
    Last edited: Aug 28, 2013

Share This Page