Apache 正在将 php 文件发送到我的浏览器,而不是解析

Apache 正在将 php 文件发送到我的浏览器,而不是解析

我必须在现有的 Web 主机上设置 PHP。我已经创建了虚拟主机条目,但出于某种原因,Apache 将 PHP 发送到浏览器而不是解析。从谷歌搜索来看,这似乎是 Mime 类型的问题,但我绝不是 Apache 专家,所以如果有人能帮忙,我将不胜感激...

我的 httpd.conf 中有以下内容:

AddHandler php5-script php

DirectoryIndex index.html index.phtml index.php index.phps

AddType application/x-httpd-php .phtml
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

PHP 模块加载到 Apache 中:

/usr/sbin/apachectl -M

已加载模块:

core_module (static)

mpm_prefork_module (static)

http_module (static)

so_module (static)

auth_basic_module (shared)

auth_digest_module (shared)

authn_file_module (shared)

authn_alias_module (shared)

authn_anon_module (shared)

authn_dbm_module (shared)

authn_default_module (shared)

authz_host_module (shared)

authz_user_module (shared)

authz_owner_module (shared)

authz_groupfile_module (shared)

authz_dbm_module (shared)

authz_default_module (shared)

ldap_module (shared)

authnz_ldap_module (shared)

include_module (shared)

log_config_module (shared)

logio_module (shared)

env_module (shared)

ext_filter_module (shared)

mime_magic_module (shared)

expires_module (shared)

deflate_module (shared)

headers_module (shared)

usertrack_module (shared)

setenvif_module (shared)

mime_module (shared)

dav_module (shared)

status_module (shared)

autoindex_module (shared)

info_module (shared)

dav_fs_module (shared)

vhost_alias_module (shared)

negotiation_module (shared)

dir_module (shared)

actions_module (shared)

speling_module (shared)

userdir_module (shared)

alias_module (shared)

rewrite_module (shared)

proxy_module (shared)

proxy_balancer_module (shared)

proxy_ftp_module (shared)

proxy_http_module (shared)

proxy_connect_module (shared)

cache_module (shared)

suexec_module (shared)

disk_cache_module (shared)

file_cache_module (shared)

mem_cache_module (shared)

cgi_module (shared)

version_module (shared)

fcgid_module (shared)

perl_module (shared)

php5_module (shared)

proxy_ajp_module (shared)

ssl_module (shared)

这是我的虚拟主机条目:

<VirtualHost 10.16.140.113:80>

ServerName   viridor-cms.co.uk

ServerAlias  www.viridor-cms.co.uk

UseCanonicalName Off

DocumentRoot /var/www/vhosts/viridor-cms.co.uk/httpdocs

CustomLog /var/www/vhosts/viridor-cms.co.uk/cms-access_log common

ErrorLog /var/www/vhosts/viridor-cms.co.uk/cms-error_log

DirectoryIndex index.php index.html

<IfModule sapi_apache2.c>

php_admin_flag engine on

php_admin_flag safe_mode on

</IfModule>

<IfModule mod_php5.c>

php_admin_flag engine on

php_admin_flag safe_mode on

</IfModule>

AddType application/x-httpd-php .php

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

</VirtualHost>

请帮帮我,我的头因为撞到桌子和墙壁而很痛!


谢谢您的回复.. :)

我已经添加了你的建议

[警告] 模块 php5_module 已加载,跳过

停止 httpd:[确定] 启动 httpd:[2010 年 5 月 24 日星期一 15:02:27] [警告] 模块 php5_module 已加载,跳过[确定]

但服务器仍在向浏览器发送 application/a-httpd-php 文件。

该网址是http://viridor-cms.co.uk并且本地 hosts 文件条目需要:

89.206.183.89 viridor-cms.co.uk

谢谢 :)

答案1

将以下行添加到你的 httpd.conf 或 apache2.conf

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

& 删除 addhandler 行AddHandler php5-script php

然后重新启动 apache。

apache 将通过此行 application/"x-httpd-php" 理解 php 引擎将用于 .php 扩展

答案2

您是否在未重新启动 Apache 的情况下对 Apache 配置文件进行了任何更改?

# /etc/init.d/httpd restart

另外,尝试添加此行(尽管 PHP 模块似乎已加载):

LoadModule php5_module modules/libphp5.so

您可能必须用 PHP 模块的绝对路径替换 modules/libphp5.so。

相关内容