php - Apache 不执行 php 文件,但启用了 mod_php5

标签 php module apache2 installation execution

<分区>

我不明白为什么。他没有执行 php 文件,而是为我提供下载服务。

在下载的文件中有php源。

我的测试文件很简单,叫做info.php

<?php

phpinfo();

我的虚拟主机:

<VirtualHost some_ip:80>
DocumentRoot /var/www/vhosts/my_vhost/htdocs
ServerName www.my_vhost.com

<Directory /var/www/vhosts/my_vhost/htdocs/>
    Options All -MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>

ErrorLog  /var/www/vhosts/my_vhost/logs/error.log
LogLevel warn   
CustomLog /var/www/vhosts/my_vhost/logs/access.log combined

</VirtualHost>

在 apache2 conf 中我有一行:

AddType application/x-httpd-php .php

Apache 启用的模块:

apache2ctl -M
Loaded Modules:
 core_module (static)
 log_config_module (static)
 logio_module (static)
 mpm_prefork_module (static)
 http_module (static)
 so_module (static)
 actions_module (shared)
 alias_module (shared)
 auth_basic_module (shared)
 auth_digest_module (shared)
 authn_file_module (shared)
 authz_default_module (shared)
 authz_groupfile_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 bw_module (shared)
 cgi_module (shared)
 dav_module (shared)
 dav_fs_module (shared)
 dav_lock_module (shared)
 dav_svn_module (shared)
 authz_svn_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 fcgid_module (shared)
 include_module (shared)
 mime_module (shared)
 negotiation_module (shared)
 perl_module (shared)
 php5_module (shared)
 python_module (shared)
 reqtimeout_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 ssl_module (shared)
 status_module (shared)
 suexec_module (shared)
 userdir_module (shared)
 wsgi_module (shared)
Syntax OK

我必须尝试调试和解决这个问题吗?

我也安装了 phpmyadmin,它工作正常。

最佳答案

检查你是否有这个文件“php5.conf”和“php5.load”到“mods-available”(默认路径:/etc/apache2/mods-available)

如果没有,就这样创建它们:

php5.conf :

<IfModule mod_php5.c>
    <FilesMatch ".ph(p3?|tml)$">
        SetHandler application/x-httpd-php
    </FilesMatch>
    <FilesMatch ".phps$">
        SetHandler application/x-httpd-php-source
    </FilesMatch>
    # 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/*/site>
            php_admin_value engine Off
        </Directory>
    </IfModule>
</IfModule>

php5.load :

# default PATH : /usr/lib/apache2/module/libphp5.so
LoadModule php5_module PATH/libphp5.so

phpmyadmin 将配置文件名“phpmyadmin.conf”的链接添加到“/etc/apache2/conf.d”中,并包含启用 php 的必要指令:

<Directory /usr/share/phpmyadmin>
    Options FollowSymLinks
    DirectoryIndex index.php

    <IfModule mod_php5.c>
        AddType application/x-httpd-php .php

        php_flag magic_quotes_gpc Off
        php_flag track_vars On
        php_flag register_globals Off
        php_value include_path .
    </IFModule>
</Directory>

关于php - Apache 不执行 php 文件,但启用了 mod_php5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13185280/

相关文章:

php - 当域由 Media Temple 托管且电子邮件由 domains.live.com 托管时,使用 PHP 发送电子邮件

python - 无法在同一文件夹中导入模块

php - 如何在字段mysql中选择最后一个日期之前的最后n个月?

session - 如何在 joomla 中将 session 值从一个模块获取到另一个模块

python - 在没有 Pip 或 setup.py 的 Ubuntu 16.04 上安装 Python 模块 easygui

authentication - 是否可以将 Apache 基本身份验证设置为锁定目录(一个文件除外)?

php - 找不到 Laravel 5 路由 404

Apache2 代理传递包括 URL 上的所有参数

php - mysql插入通知: Array to string conversion

javascript - 调用 $.getJSON 并发送 URL 参数