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 http://packages.dotdeb.org stable all” >> /etc/apt/sources.list
echo “deb-src http://packages.dotdeb.org stable all” >> /etc/apt/sources.list
wget http://www.dotdeb.org/dotdeb.gpg
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 127.0.0.1:9000 -pass-header Authorization
</IfModule>

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.

Enjoy

Valic

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

*

Text formatting is available via select HTML. <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>