SFO 也存在这个问题,但我被建议在这里询问,因为这更多的是一个服务器配置问题。
我有一个大问题。
我的 apache2 不处理 php7 代码,而是直接在浏览器(chrome)或空白页(firefox)中显示代码
很多人都遇到过类似的问题但显然都设法解决了。
(白屏 - Ubuntu 16.04 上的 PHP 7 无法呈现脚本)
我已关注过许多有关如何使其工作的线索,但无济于事。
此外,如果这可能是一个问题,我已强制我的网站仅在 https 上运行。
信息:
Ubuntu 版本:Ubuntu 16.04.3 LTS
阿帕奇:
Apache2-v
服务器版本:Apache/2.4.18(Ubuntu)
服务器搭建: 2017-07-27T14:34:01
PHP:
$ php -v
PHP 7.0.22-0ubuntu0.16.04.1 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.22-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies
$ ps -A|grep php
7799 ? 00:00:52 php-fpm7.0
Apache 模式:
$ ls -lart /etc/apache2/mods-enabled/
php7.0.load -> ../mods-available/php7.0.load
php7.0.conf -> ../mods-available/php7.0.conf
$ dpkg --list|grep libapache2
ii libapache2-mod-php 1:7.0+35ubuntu6 all server-side, HTML-embedded scripting language (Apache 2 module) (default)
ii libapache2-mod-php7.0 7.0.22-0ubuntu0.16.04.1 amd64 server-side, HTML-embedded scripting language (Apache 2 module)
ii libapache2-mod-python 3.3.1-11ubuntu2 amd64 Python-embedding module for Apache 2
php模块:
$ sudo a2enmod php7.0
Considering conflict php5 for php7.0:
Module php7.0 already enabled
从我的 Apache conf(/etc/apache2/sites-available)中提取:
<VirtualHost *:443>
ServerName ############
ServerAlias ############
DocumentRoot /var/www/html/public
ErrorLog /var/www/html/logs/eu_error_log
CustomLog /var/www/html/logs/eu_access_log combined
ScriptAlias /cgi-bin/ /var/www/html/cgi-bin/
DirectoryIndex index.html index.htm index.php7
<Directory /var/www/html/public>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted
AddType application/x-httpd-php .php7
AddType application/x-httpd-php-source .phps
AddType application/json .json
</Directory>
<Directory /var/www/html/cgi-bin>
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted
</Directory>
<Directory /usr/lib/cgi-bin>
Require all granted
</Directory>
<IfModule mod_fastcgi.c>
AddHandler php7-fcgi .php7
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>
# RemoveHandler .php
# RemoveHandler .php7
php_admin_value engine On
# IPCCommTimeout 301
# FcgidMaxRequestLen 1073741824
php_value memory_limit 128M
php_value suhosin.session.encrypt Off
SSLEngine on
SSLCertificateFile ############
SSLCertificateKeyFile ############
# SSLCACertificateFile ############
SSLCipherSuite ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA
SSLProtocol All -SSLv2 -SSLv3
SSLCompression off
SSLHonorCipherOrder On
</VirtualHost>
还有我的 www 文件夹:
$ ls -lart /var/www/html/public/*
-rw-r--r-- 1 root root 27 sep 10 15:35 .htaccess
-rw-r--r-- 1 root root 29 sep 10 15:46 index.php7
内容:
$ sudo cat /var/www/html/public/.htaccess
DirectoryIndex index.php7
$ sudo cat /var/www/html/public/index.php7:
<?php
echo "Hello World";
?>
正常的 index.html 会产生正确的输出。
还有什么要检查的吗?