大网数据广告活动
服务器运维问答

Apache with PHP-FPM - PHP doesn't execute

· 52CE 我爱测

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)…

问题原文

原帖链接 · Sisir · CC BY-SA 3.0

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)

已采纳解答

原帖链接 · Sisir · CC BY-SA 4.0

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

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-06-23)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。