php - Apache2返回php源码

标签 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(); ?>

不执行 - 它是返回的源代码。为什么?

最佳答案

这个问题已经有一年了,对于 OP 来说可能为时已晚,但没有公认的答案,我从谷歌偶然发现。我正在处理一个非常相似的问题,也许我的解决方案将来会对某人有用:
php.ini 中有一个 PHP 指令:

short_open_tag = Off

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

所以就我而言,问题出在我的测试脚本上:
<? phpinfo(); ?>

解决方法是将标签改为<?php或者只是更新 INI 文件以读取 short_open_tag = On .

关于php - Apache2返回php源码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24479265/

相关文章:

PHP-MYSQL脚本无法连接服务器上的数据库

java - JSP 中的 while 循环执行 javascript 不起作用?

ruby-on-rails - Ruby On Rails Mysql 访问被拒绝

php - 从 ID 列表批量更新值列表

php - mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows等…期望参数1为资源或结果

PHP PDO - 使用准备好的语句导致服务器错误

Rstudio 服务器找不到 R 安装的正确位置 (ubuntu)

php - 锁定在 MyISAM 表 (MySQL) 和 PHP

PHP:mysqli 扩展未加载

php - 2021 年使用 PHP 5.3 的 Apache