在 LinuxMint 上设置 PHP-FPM

在 LinuxMint 上设置 PHP-FPM

我目前正在尝试在 Linux Mint 18 (Sarah) 上安装 PHP-FPM。我花了好几个小时甚至几天的时间尝试让它工作,但无济于事。

PHP-FPM 似乎没有被调用,因为我在查询页面时总是得到 PHP 代码,而不是预期的网页,即:

询问:

GET /phpinfo.php

回复:

<?php
phpinfo();

预期的:

phpinfo()
PHP Version => 7.0.8-0ubuntu0.16.04.3

System => Linux[...]

另一个没有调用 PHP-FPM 的“线索”是,即使我停止它,网页响应也是一样的。

谢谢您所提供的任何帮助!

以下是规格:

  • Linux Mint 18
  • Apache 2.4.18
  • PHP 7(使用 apt-get 安装)
  • PHP-FPM(使用 apt-get)
  • libapache2-mod-fastcgi

已启用模组:

access_compat.load
actions.conf
actions.load
alias.conf
alias.load
auth_basic.load
authn_core.load
authn_file.load
authz_core.load
authz_host.load
authz_user.load
autoindex.conf
autoindex.load
deflate.conf
deflate.load
dir.conf
dir.load
env.load
fastcgi.conf
fastcgi.load
filter.load
mime.conf
mime.load
mpm_event.conf
mpm_event.load
negotiation.conf
negotiation.load
rewrite.load
setenvif.conf
setenvif.load
status.conf
status.load

VirtualHost 的内容 (仅启用一个):

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerName some.server.name
    ServerAdmin webmaster@localhost
    DocumentRoot /opt/git/NetDev/NetworkWebsite/web
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory /opt/git/NetDev/NetworkWebsite/web>
        Options FollowSymlinks
        DirectoryIndex app_dev.php
        AllowOverride All
        Require all granted
    </Directory>

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

fastcgi.conf文件内容:

<IfModule mod_fastcgi.c>
  AddHandler fastcgi-script .fcgi
  #FastCgiWrapper /usr/lib/apache2/suexec
  FastCgiIpcDir /var/lib/apache2/fastcgi
</IfModule>

php7.0-fpm.conf文件内容(已加载):

# Redirect to local php-fpm if mod_php is not available
<IfModule !mod_php7.c>
    # Enable http authorization headers
    SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1

    <FilesMatch ".+\.ph(p[3457]?|t|tml)$">
        SetHandler "proxy:unix:/run/php/php7.0-fpm.sock|fcgi://localhost"
    </FilesMatch>
    <FilesMatch ".+\.phps$">
        # Deny access to raw php sources by default
        # To re-enable it's recommended to enable access to the files
        # only in specific virtual host or directory
        Require all denied
    </FilesMatch>
    # Deny access to files without filename (e.g. '.php')
    <FilesMatch "^\.ph(p[3457]?|t|tml|ps)$">
        Require all denied
    </FilesMatch>
</IfModule>

<IfModule mod_fastcgi.c>
    AddHandler php7-fcgi .php
    Action php7-fcgi /php7-fcgi
    Alias /php7-fcgi /usr/lib/cgi-bin/php7-fcgi
    FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi -socket /var/run/php/php7.0-fpm.sock -pass-header Authorization
</IfModule>

相关内容