2

I have compiled PHP 7 with FPM support using this tutorial on CentOS 7.x environment.

I was able to test the php through CLI by running.

cd /opt/php7/bin
./php --version

Which outputs

PHP 7.0.6 (cli) (built: May 22 2016 07:20:48) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

I have also installed apache and it is running successfully.

Now I have created vhosts and guided domain to a directory. I have pasted a php file info.php with the function phpinfo() but server outputs the PHP function without executing it.

I feel I am really close now and just need to configure apache to run with php-fpm so I put this config on httpd.conf file but it doesn't help.

<IfModule mod_fastcgi.c>

    DirectoryIndex index.html index.shtml index.cgi index.php

    AddType application/x-httpd-fastphp7 .php
    Action application/x-httpd-fastphp7 /php7-fcgi

    Alias /php7-fcgi /opt/php7/bin/php-cgi

    FastCgiExternalServer /var/www/html/ -socket /opt/php7/var/run/php-fpm.pid -pass-header Authorization

    <Directory /var/www/html/>
        Require all granted
    </Directory>
</IfModule>

fcgi module is installed beacuse when I run apachectl -t -D DUMP_MODULES I get fcgid_module (shared)

1 Answer 1

1

Solved the problem. I have followed the steps below.

Make Sure PHP-FPM is running

First of all if you haven't choose any alternative port for php-fpm then it will be set to run at port 9000.

/etc/init.d/php-fpm start

or

/etc/init.d/php7.x-fpm start

If it fails saying that the port is already occupied then you will need to find out the process number that is running by the port and kill it.

netstat -tulpn | grep :8999

This should give you the process id that is currently running. For example if the process id is 21190 then you run

kill 21190

Now that the port is cleared you can now try to start the php-fpm again

/etc/init.d/php-fpm start

Update vHost config file

For example you are hosting example.com. Now open up the vhost config for the domain. Here is a simplest example.

<VirtualHost *:80>
    DocumentRoot "/var/www/html/example.com/"
    ServerName example.com
</VirtualHost>

Now add update it with following:

<VirtualHost *:80>
    DocumentRoot "/var/www/html/example.com/"
    ServerName example.com

    # Setup php-fpm to process php files
    ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/example.com/$1
    DirectoryIndex /index.php index.php
</VirtualHost>

And now all your php file for the example.com should execute.

Reference: https://wiki.apache.org/httpd/PHP-FPM

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .