Using PHP5-FPM With Apache 2.4 (+ mod_proxy_fcgi Module) On Fedora 18 - Page 2

5 Configuring Apache

To make Apache 2.4 work with PHP-FPM, we can use the ProxyPassMatch directive in each vhost that should use PHP-FPM (see

Possible configurations are, for example:

ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://$1

This matches (from the document root onward) all paths that contain .php, optionally followed by a / and any continued path.

ProxyPassMatch ^/(.*\.php)$ fcgi://$1

This matches (from the document root onward) all paths that end in .php.

In this example I want to configure the default vhost which has the document root /var/www/html. It is defined in /etc/httpd/conf/httpd.conf:

vi /etc/httpd/conf/httpd.conf

Add this somewhere near the end (before the IncludeOptional conf.d/*.conf line):

<IfModule proxy_module>
  ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://$1

Make sure you use the correct document root (/var/www/html in this case) in the ProxyPassMatch directive.

If mod_php is installed and enabled, we need to disable it. Open /etc/httpd/conf.d/php.conf...

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

... and comment out the AddHandler and AddType lines:

# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
<IfModule prefork.c>
  LoadModule php5_module modules/
<IfModule !prefork.c>
  LoadModule php5_module modules/

# Cause the PHP interpreter to handle files with a .php extension.
#AddHandler php5-script .php
#AddType text/html .php

# Add index.php to the list of files that will be served as directory
# indexes.
DirectoryIndex index.php

# Uncomment the following line to allow PHP to pretty-print .phps
# files as PHP source code:
#AddType application/x-httpd-php-source .phps

Restart Apache afterwards:

systemctl restart httpd.service

Now create the following PHP file in the document root /var/www/html of the default Apache vhost:

vi /var/www/html/info.php

Now we call that file in a browser (e.g.

As you see, PHP5 is working, and it's working through FPM/FastCGI, as shown in the Server API line. If you scroll further down, you will see all modules that are already enabled in PHP5. MySQL is not listed there which means we don't have MySQL support in PHP5 yet.


6 Getting MySQL Support In PHP5

To get MySQL support in PHP, we can install the php-mysql package. It's a good idea to install some other PHP5 modules as well as you might need them for your applications. You can search for available PHP5 modules like this:

yum search php

Pick the ones you need and install them like this:

 yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-magickwand php-mbstring php-mcrypt php-mssql php-shout php-snmp php-soap php-tidy

APC is a free and open PHP opcode cacher for caching and optimizing PHP intermediate code. It's similar to other PHP opcode cachers, such as eAccelerator and Xcache. It is strongly recommended to have one of these installed to speed up your PHP page.

APC can be installed as follows:

yum install php-pecl-apc 

Now reload PHP-FPM:

systemctl reload php-fpm.service

Now reload in your browser and scroll down to the modules section again. You should now find lots of new modules there, including the MySQL module:


Share this page:

Suggested articles

0 Comment(s)

Add comment