如何让 apache2 在 Ubuntu 16.04 上使用 php7 提供基于 php 的项目?

如何让 apache2 在 Ubuntu 16.04 上使用 php7 提供基于 php 的项目?

Ubuntu 16.04 添加了一些libapache2-mod-php7.0内容,这会弄乱apache2基于 php 的项目的服务配置(我这样模糊地表述这一点是因为我想避免处理应该开箱即用/无需了解内部情况的项目的源代码,例如dokuwiki)。

官方 PHP 7 迁移指南以及之前没有发生过的错误Parse error: syntax error, unexpected 'new' (T_NEW),我也没有进一步调查(参见上文),至少我想要服务的项目与 PHP 7 不兼容,这让我对 PHP 7 设置不感兴趣,因此坚持使用 PHP 5。

sudo a2dismod php7.0 && sudo a2enmod php5我获得下载机会之后。

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
AddType application/x-httpd-php .php .htm .html

一直存在于站点配置中,例如

Listen 0.0.0.0:446 https

Alias /dokuwiki/ "/var/www/html/dokuwiki/"

DirectoryIndex index.php index.html index.htm doku.php

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
AddType application/x-httpd-php .php .htm .html

<Directory "/var/www/html/dokuwiki">
    Options None
    AllowOverride Limit

    Require all granted
</Directory>

<VirtualHost richtercloud.de:446 >
    ErrorLog /var/log/dokuwiki/dokuwiki.log
    SSLEngine On
    DocumentRoot "/var/www/html/dokuwiki"
    ServerName richtercloud.de
    SSLCertificateFile /etc/apache2/server.crt
    SSLCertificateKeyFile /etc/apache2/server.key
</VirtualHost>

添加如下处理程序

AddHandler php5-script .php
AddHandler application/x-httpd-php .php5 .php4 .php .php3 .php2 .phtml

或者

AddType text/html       php

(灵感来自https://serverfault.com/questions/215455/what-c​​auses-php-pages-to-consistently-download-instead-of-running-normally) 没有帮助。

https改为会很好http,但是我服务的所有项目都配置为在内部建立 SSL 连接,所以这意味着大量的配置更改,我想在最后一刻避免这些更改。

/var/log/apache2/error.log包含

[Fri Mar 18 14:21:45.448248 2016] [core:notice] [pid 12155] AH00094: Command line: '/usr/sbin/apache2'
[Fri Mar 18 14:22:45.449327 2016] [mpm_prefork:notice] [pid 12155] AH00169: caught SIGTERM, shutting down
[Fri Mar 18 14:22:57.677426 2016] [ssl:warn] [pid 12732] AH01909: richtercloud.fritz.box:443:0 server certificate does NOT include an ID which matches the server name
[Fri Mar 18 14:22:57.677519 2016] [:notice] [pid 12732] mod_qos(009): loaded MPM is 'prefork' but mod_qos should be used with MPM 'Worker' only.
[Fri Mar 18 14:22:57.677565 2016] [:warn] [pid 12732] mod_qos(009): mod_unique_id not available (mod_qos generates simple request id if required)
[Fri Mar 18 14:22:57.793923 2016] [:notice] [pid 12737] FastCGI: process manager initialized (pid 12737)
PHP Warning:  Module 'horde_lz4' already loaded in Unknown on line 0
PHP Warning:  Module 'igbinary' already loaded in Unknown on line 0
PHP Warning:  Module 'imagick' already loaded in Unknown on line 0
PHP Warning:  Module 'intl' already loaded in Unknown on line 0
PHP Warning:  Module 'memcache' already loaded in Unknown on line 0
[Fri Mar 18 14:22:58.010146 2016] [ssl:warn] [pid 12734] AH01909: richtercloud.fritz.box:443:0 server certificate does NOT include an ID which matches the server name
[Fri Mar 18 14:22:58.010260 2016] [:notice] [pid 12734] mod_qos(009): loaded MPM is 'prefork' but mod_qos should be used with MPM 'Worker' only.
[Fri Mar 18 14:22:58.010309 2016] [:warn] [pid 12734] mod_qos(009): mod_unique_id not available (mod_qos generates simple request id if required)
[Fri Mar 18 14:22:58.025190 2016] [mpm_prefork:notice] [pid 12734] AH00163: Apache/2.4.18 (Ubuntu) Embperl/2.5.0 mod_auth_pgsql/2.0.3 mod_auth_gssapi/1.3.3 mod_auth_tkt/2.1.0 mod_fastcgi/mod_fastcgi-SNAP-0910052141 mod_fcgid/2.3.9 OpenSSL/1.0.2g mod_qos/11.21 mod_scgi/1.13 mod_apreq2-20090110/2.8.0 mod_defensible/1.2 mod_perl/2.0.9 Perl/v5.22.1 configured -- resuming normal operations
[Fri Mar 18 14:22:58.025228 2016] [core:notice] [pid 12734] AH00094: Command line: '/usr/sbin/apache2'

对于每次似乎没有问题的(重新)启动。

上面的例子ErrorLog包含VirtualHostdokuwiki

[Fri Mar 18 03:07:49.551221 2016] [proxy:warn] [pid 4306] [client 192.168.179.52:34298] AH01144: No protocol handler was valid for the URL /doku.php. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.

我不知道如何摆脱它,但无论如何,它并没有改变任何事情。

$ sudo apache2ctl -M 
Loaded Modules:
 core_module (static)
 so_module (static)
 watchdog_module (static)
 http_module (static)
 log_config_module (static)
 logio_module (static)
 version_module (static)
 unixd_module (static)
 auth_pgsql_module (shared)
 access_compat_module (shared)
 alias_module (shared)
 apreq_module (shared)
 auth_basic_module (shared)
 auth_gssapi_module (shared)
 auth_plain_module (shared)
 auth_tkt_module (shared)
 authn_core_module (shared)
 authn_file_module (shared)
 authz_core_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 cgi_module (shared)
 defensible_module (shared)
 deflate_module (shared)
 dir_module (shared)
 encoding_module (shared)
 env_module (shared)
 fastcgi_module (shared)
 fcgid_module (shared)
 filter_module (shared)
 geoip_module (shared)
 headers_module (shared)
 mime_module (shared)
 mpm_prefork_module (shared)
 negotiation_module (shared)
 perl_module (shared)
 php5_module (shared)
 qos_module (shared)
 rewrite_module (shared)
 scgi_module (shared)
 setenvif_module (shared)
 slotmem_shm_module (shared)
 socache_shmcb_module (shared)
 ssl_module (shared)
 status_module (shared)
 xsendfile_module (shared)
 embperl_module (shared)

我知道这是一个基于开发版本的问题,但现在就应该回答这个问题,而不是等到发布后的几个小时,那时很多人都会遇到这个问题。

答案1

我对 mods 和 confs 以及 sites 和.htaccessand 感到困惑... 显然可以启用php5-cgi和的confs php7.0-fpm,这可以通过以下方法修复

sudo a2disconf php7.0-fpm 
sudo systemctl restart apache2.service

相关内容