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

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

有人有什么建议吗?

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

编辑: 代码. .:

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


当前回答

我在High Sierra (OS X 10.13.5)附带的php 7.1上遇到了这个问题,编辑/etc/apache2/httpd.conf进行以下更改有帮助:

取消注释这行 LoadModule php7_module libexec/apache2/libphp7.so 将下面的粘贴到末尾 < IfModule php7_module > AddType application/x-httpd-php .php AddType application/x-httpd-php-source .php < IfModule dir_module > DirectoryIndex index.html index.php < / IfModule > < / IfModule >

其他回答

这是我的。htaccess

DirectoryIndex index.html index.htm

index.html包含PHP代码。默认情况下,PHP不会将扩展名为htm*的文件作为PHP代码处理。

你可以通过在.htaccess中添加以下内容来覆盖它:

<FilesMatch ".+\.html$">
    SetHandler application/x-httpd-php
</FilesMatch>

我发布这个答案是因为我的Virtualmin/Webmin管理界面决定禁用我的PHP引擎是一个好主意。我花了一段时间才找到解决方案,所以我想和你们分享一下:

同时,确保你的网站配置文件中没有任何与这个特定主机或虚拟主机相关的php_admin_value在它们中关闭PHP,就像这样:

php_admin_value engine Off

有疑问的时候,评论一下…

# php_admin_value engine Off

并重新启动您的web服务器。

It is possible to install phpmyadmin on raspberry 64 bit and it even was not difficult in my case. I am running several hp-laptops with openSuse Tumbleweed and some Raspberries. On the latest Raspberry 3 B + I 64bit raspbian buster light, kde plasma Desktop. Linux raspi10 5.10.60-v8+ #1449 SMP PREEMPT Wed Aug 25 15:01:33 BST 2021 aarch64 GNU/Linux I am using nginx 1.14.2 with fastcgi (not using 'sock') and php 8.0.10 (php-fpm). I downloaded 'composer' first. (Use apt or aptitude for that). After that go to https://docs.phpmyadmin.net/en/latest/setup.html Look for the shell command

composer create-project phpmyadmin/phpmyadmin

它将在当前目录中安装一个完整的目录'phpmyadmin'。 移动到/var/lib/并根据nginx.conf中的设置设置user:group权限 在我的例子中: chown -R www-data:www-data /var/lib/phpmyadmin

创建一个符号链接到/srv/www/public或/var/www/html或任何你的服务器正在寻找的东西。 您可以向phpMyAdmin添加第二个名为phpMyAdmin的符号链接 确保nginx.conf中的根指令相应设置。

我的nginx配置在我的所有机器上(几乎)是相同的。 它现在非常紧凑。 这是最简单的方法。所有进一步的服务器和功能可以稍后添加。 /etc/nginx/sites-enabled没有条目 /etc/nginx/vhosts.d中没有任何内容 从php.ini中的一个池开始。为了配置它,谷歌一点和测试 通过检查php-fpm的状态。

你只是把php文件打开到浏览器。你必须使用localhost url打开它。如果您直接从目录中打开一个文件,在任何情况下它都不会执行PHP代码。

使用:http://locahost/index.php或http:127.0.0.1/index.php

启用php短代码。在本例中,您使用<?这是<? PHP的PHP短代码。默认情况下,php短代码是禁用的。

如果你是ubuntu用户,也可以使用:sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt。

使用Debian 10安装Apache + php7测试的最简单方法:

apt-get update -y
apt-get install apache2 php7.0 libapache2-mod-php  -y
sudo service apache2 restart