我试图在一个项目上执行一些PHP代码(使用Dreamweaver),但代码没有运行。

当我检查源代码时,PHP代码显示为HTML标记(我可以在源代码中看到它)。Apache运行正常(我正在使用XAMPP), PHP页面正在正常打开,但PHP代码没有被执行。

有人有什么建议吗?

注意:该文件已经命名为filename.php

编辑: 代码. .:

<?
include_once("/code/configs.php");
?>


当前回答

我在Ubuntu上运行Apache,我的问题是/etc/apache2/mods-available/php5.conf文件缺少这个:

<FilesMatch ".+\.ph(p[345]?|t|tml)$">
    SetHandler application/x-httpd-php
</FilesMatch>

我把它添加回来,php正确地解析php文件。

其他回答

我有一个案例,我不小心开始解压我的文件目录在根。它从我的文件文件夹中添加了。htaccess文件,这将阻止所有php

# If we know how to do it safely, disable the PHP engine entirely.
<IfModule mod_php5.c>
  php_flag engine off
</IfModule>

底线检查根目录下的.htaccess文件。

听起来你的配置好像有问题,下面是一些你可以检查的东西:

Make sure that PHP is installed and running correctly. This may sound silly, but you never know. An easy way to check is to run php -v from a command line and see if returns version information or any errors. Make sure that the PHP module is listed and uncommented inside of your Apache's httpd.conf This should be something like LoadModule php5_module "c:/php/php5apache2_2.dll" in the file. Search for LoadModule php, and make sure that there is no comment (;) in front of it. Make sure that Apache's httpd.conf file has the PHP MIME type in it. This should be something like AddType application/x-httpd-php .php. This tells Apache to run .php files as PHP. Search for AddType, and then make sure there is an entry for PHP, and that it is uncommented. Make sure your file has the .php extension on it, or whichever extension specified in the MIME definition in point #3, otherwise it will not be executed as PHP. Make sure you are not using short tags in the PHP file (<?), these are not enabled on all servers by default and their use is discouraged. Use <?php instead (or enable short tags in your php.ini with short_open_tag=On if you have code that relies on them). Make sure you are accessing your file over your webserver using an URL like http://localhost/file.php not via local file access file://localhost/www/file.php

最后,查看PHP手册以获得更多的设置技巧。

在我的情况下(Apache/2.4.34),

在取消特定模块的注释之后

其它选项:

from

“/etc/apache2/httpd.conf”

我的问题消失了。

如果你有这样的配置:

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot "/var/www/example.com"

    <FilesMatch "\.php$">
        SetHandler "proxy:fcgi://127.0.0.1:9000"
    </FilesMatch>
</VirtualHost>

取消httpd.conf中的下几行注释

LoadModule proxy_module lib/httpd/modules/mod_proxy.so
LoadModule proxy_fcgi_module lib/httpd/modules/mod_proxy_fcgi.so

这对我很有用

在我的情况下,php模块没有加载。试试这个:

检查加载了哪些模块:apache2ctl -M。查找类似php7_module (shared)的模块 如果没有列出php模块,则尝试加载与您的php版本对应的模块。在我的例子中,php包是libapache2-mod-php7.3。所以我这样做了:a2enmod php7.3,问题就解决了。