我已经为此苦苦挣扎了 5 个多小时,但似乎找不到解决问题的方法。基本上,我在 Fedora Core 服务器(在自定义端口 55555)上设置了虚拟主机。每当我尝试通过在浏览器中输入例如 111.111.111.111:55555/somefile.php 来访问 php 文件时,浏览器都会强制下载此文件。我希望 php 文件能够被解析。
以下是我的httpd.conf附加部分:
Listen 55555
<VirtualHost *:55555>
DocumentRoot "/var/www/vhosts/example.com/httpdocs/app/"
ServerName 111.111.111.111:55555
CustomLog "/var/log/app/access.log" combined
ErrorLog "/var/log/app/error.log"
<Directory "/var/www/vhosts/example.com/httpdocs/app/">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
有人知道为什么强制下载 php 文件以及如何解析它们吗?
嗯,重点是当我在 plesk 下设置域时,php 文件解析没有任何问题。
在httpd.conf中只有3行涉及php配置:
DirectoryIndex at_domains_index.html index.html index.html.var index.shtml index.cfm index.php index.htm index
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
在 conf.d 文件夹中的 php.conf 文件中有以下内容:
#
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#
LoadModule php5_module modules/libphp5.so
#
# Cause the PHP interpreter to handle files with a .php extension.
#
AddHandler php5-script .php
AddType text/html .php
#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php
#
# Uncomment the following line to allow PHP to pretty-print .phps
# files as PHP source code:
#
#AddType application/x-httpd-php-source .phps
答案1
通过启用 php 模块来修复此问题。我的虚拟主机配置如下:
Listen 55555
<VirtualHost *:55555>
DocumentRoot "/var/www/vhosts/example.com/httpdocs/app/"
ServerName 111.111.111.111:55555
CustomLog "/var/log/app/access.log" combined
ErrorLog "/var/log/app/error.log"
<Directory "/var/www/vhosts/example.com/httpdocs/app/">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Directory /var/www/vhosts/example.com/httpdocs/app>
<IfModule sapi_apache2.c>
php_admin_flag engine on
php_admin_flag safe_mode on
php_admin_value open_basedir "/var/www/vhosts/example.com/httpdocs/app:/tmp"
</IfModule>
<IfModule mod_php5.c>
php_admin_flag engine on
php_admin_flag safe_mode on
php_admin_value open_basedir "/var/www/vhosts/example.com/httpdocs/app:/tmp"
</IfModule>
</Directory>
</VirtualHost>