Apache с PHP-FPM - PHP не выполняется

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)

2
задан 23 June 2016 в 13:17
1 ответ

Проблема решена. Я выполнил следующие шаги.

Убедитесь, что PHP-FPM работает

Прежде всего, если вы не выбрали альтернативный порт для php-fpm, он будет настроен на работу на порту 9000.

/etc/init.d/php-fpm start

Если он не сообщает, что порт уже занят, вам нужно будет узнать номер процесса, который запущен этим портом, и kill его.

netstat -tulpn | grep :8999

Это должно дать вам идентификатор процесса, который в настоящее время запущен . Например, если идентификатор процесса 21190 , тогда вы запускаете

kill 21190

. Теперь, когда порт очищен, вы можете попробовать снова запустить php-fpm

/etc/init.d/php-fpm start

Обновить файл конфигурации vHost

Например, вы размещаете example.com . Теперь откройте конфигурацию vhost для домена. Вот простейший пример.

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

Теперь добавьте обновите его следующим образом:

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

И теперь все ваши php-файлы для example.com должны выполняться.

Ссылка: https://wiki.apache.org/httpd/PHP-FPM

1
ответ дан 3 December 2019 в 12:40

Теги

Похожие вопросы