Apache2返回php源代码

时间:2014-06-29 19:03:55

标签: php apache ubuntu apache2

Ubuntu 12.04

已安装Apache2

# apache2 -v
Server version: Apache/2.2.22 (Ubuntu)
Server built:   Mar 19 2014 21:11:49

安装了PHP

# php --version
PHP 5.4.6-1ubuntu1.8 (cli) (built: Apr  4 2014 01:28:36)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies

安装并启用了PHP模块

# a2enmod php5
Module php5 already enabled

php5.conf包含SetHandler指令

<IfModule mod_php5.c>
    <FilesMatch ".+\.ph(p[345]?|t|tml)$">
        SetHandler application/x-httpd-php
    </FilesMatch>
    <FilesMatch ".+\.phps$">
        SetHandler application/x-httpd-php-source
        # 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
        Order Deny,Allow
        Deny from all
    </FilesMatch>
    # Deny access to files without filename (e.g. '.php')
    <FilesMatch "^\.ph(p[345]?|t|tml|ps)$">
        Order Deny,Allow
        Deny from all
    </FilesMatch>

    # Running PHP scripts in user directories is disabled by default
    #
    # To re-enable PHP in user directories comment the following lines
    # (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
    # prevents .htaccess files from disabling it.
    <IfModule mod_userdir.c>
        <Directory /home/*/public_html>
            php_admin_value engine Off
        </Directory>
    </IfModule>
</IfModule>

但我的档案是/var/www/wwwuser/data/domain.com/info.php

<?php phpinfo(); ?>

未执行 - 返回了它的源代码。为什么呢?

2 个答案:

答案 0 :(得分:2)

尝试sudo apt-get install libapache2-mod-php7.2 && sudo服务apache2重新启动 好吧,您可能拥有另一个版本的php,因此请参考您的php版本。为我工作的zend运行完美

答案 1 :(得分:0)

这个问题已经有一年了,对于OP来说可能为时已晚,但没有接受的答案,我在这里偶然发现了谷歌。我正在处理一个非常类似的问题,也许我的解决方案将来会对某人有用:

php.ini中有一条PHP指令:

short_open_tag = Off

如果这是Off,那么PHP将忽略<? ?>代码,因为它需要<?php ?>

所以在我的情况下,问题是我的测试脚本:

<? phpinfo(); ?>

解决方案是将代码更改为<?php或只更新INI文件以阅读short_open_tag = On