How to install and use PHP5-FPM with Apache2 on Debian

Valic —  March 29, 2012 — 4 Comments

Step1. Install Apache2 using the command:

apt-get install apache2-mpm-worker

Now you cand navigate from  your browser to http://your-ip to check if Apache2 is working (you should see the Apache2 default page with message:  It works).

Step2.  Install PHP5-FPM.

We will make PHP5 work in Apache2 through PHP-FPM and Apache2  mod_fastcgi module.
We need to install apache mod-fastcgi first:

apt-get install libapache2-mod-fastcgi php5

Now install php-fpm:

echo “deb stable all” >> /etc/apt/sources.list
echo “deb-src stable all” >> /etc/apt/sources.list
cat dotdeb.gpg |apt-key add –
apt-get update
apt-get install php5-fpm

Step3. Enable the  Apache2 modules:

a2enmod actions fastcgi alias

and restart Apache2 server:

/etc/init.d/apache2 restart

Step4. Make Apache work with PHP-FPM:

Put the following section between <VirtualHost> and </VirtualHost> in your virtualhost file:

vim /etc/apache2/sites-enabled/000-default
<IfModule mod_fastcgi.c>
AddHandler php5-fcgi .php
Action php5-fcgi /php5-fcgi
Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host -pass-header Authorization

Restart apache again.

/etc/init.d/apache2 restart

Step5. Verify if  PHP-FPM is working:

Create one phpinfo file in the document root /var/www

echo “<?php phpinfo();  ?>” > /var/www/phpinfo.php

and navigate to http://your-ip/phpinfo.php and check for PHP-FP.



Posts Twitter Facebook

Editor in Chief at Debian-Tutorials, Linux enthusiast.

4 responses to How to install and use PHP5-FPM with Apache2 on Debian

  1. I have do it exactly this tutorial on my private Root-Server with Debian but it shows me in the phpinfo(); data table no PHP5-FPM. What i have made wrong?

  2. did you not get any errors?

  3. Hi, I’m curious why you’ve gone w/ TCP in Step 4. Isn’t sockets preferable for performance reasons?

  4. You can use either sockets either external source. In this guide I used external source.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.