LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-26-2013, 07:31 AM   #1
DarkSlayer
Member
 
Registered: Apr 2008
Location: Tbilisi , Georgia
Distribution: Fedora, CentOS
Posts: 65

Rep: Reputation: 19
Lightbulb PHP-FPM not working as PHP handler in Apache


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 server.com/info.php, it's being opened as standart text showing contents of file, not parsed:
Code:
<?php 
phpinfo(); 
?>
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:
Code:
./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 \
--with-fpm-group=apache
php-fpm process starting normally via init.d/php-fpm, and ready to listen connections on 127.0.0.1:9000. netstat approves this info.
mod_fastcgi - installed via yum
my httpd/fpm.conf
Code:
<IfModule mod_fastcgi.so>
    <FilesMatch \.php$>
        SetHandler php-script
    </FilesMatch>
#   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 127.0.0.1:9000
    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
        </Files>
    </Directory>
</IfModule>
fastcgi.conf
Code:
User apache
Group apache

LoadModule fastcgi_module modules/mod_fastcgi.so

# 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 server.com/pma:
Code:
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.

SOLUTION

I had <IfModule mod_fastcgi.so> 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:
Code:
<IfModule mod_fastcgi.c>
    <FilesMatch \.php$>
        SetHandler php-script
    </FilesMatch>
    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 127.0.0.1:9000 -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
        </Files>
    </Directory>
</IfModule>
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 by DarkSlayer; 08-28-2013 at 02:22 AM.
 
Old 08-27-2013, 02:19 AM   #2
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
Quote:
# AddHandler php-script .php
Are you sure this should be commented out? I don't know php-fpm but if you run php as a module this must be set (or info.php will show the way you said).
 
Old 08-28-2013, 02:25 AM   #3
DarkSlayer
Member
 
Registered: Apr 2008
Location: Tbilisi , Georgia
Distribution: Fedora, CentOS
Posts: 65

Original Poster
Rep: Reputation: 19
Quote:
Originally Posted by j-ray View Post
Are you sure this should be commented out? I don't know php-fpm but if you run php as a module this must be set (or info.php will show the way you said).
Yes it should be commented out. Because I'm using SetHandler option. If I want to use AddHandler I have to comment out SetHandler option.
Anyways, I've solved this problem.
 
  


Reply

Tags
apache2, centos, fastcgi, php



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial: Apache 2.4.3 + Mpm_Event_Module + Php-Fpm + Mod_Proxy_Fcgi pdean712 Slackware 2 11-30-2012 09:11 PM
Amazon Linux + Apache + PHP-FPM = Confusion! mh77 Linux - Newbie 1 09-25-2012 05:02 AM
apache with php/suexec/fpm/fastcgi? hoodez Linux - Server 0 07-23-2010 01:26 AM
LXer: Installing Nginx With PHP 5.3 And PHP-FPM On Ubuntu Lucid Lynx (10.04) LXer Syndicated Linux News 0 06-14-2010 11:42 PM
LXer: Installing PHP 5.3, Nginx And PHP-fpm On Ubuntu/Debian LXer Syndicated Linux News 0 02-10-2010 05:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 04:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration