我试图在一个项目上执行一些PHP代码(使用Dreamweaver),但代码没有运行。
当我检查源代码时,PHP代码显示为HTML标记(我可以在源代码中看到它)。Apache运行正常(我正在使用XAMPP), PHP页面正在正常打开,但PHP代码没有被执行。
有人有什么建议吗?
注意:该文件已经命名为filename.php
编辑: 代码. .:
<?
include_once("/code/configs.php");
?>
我试图在一个项目上执行一些PHP代码(使用Dreamweaver),但代码没有运行。
当我检查源代码时,PHP代码显示为HTML标记(我可以在源代码中看到它)。Apache运行正常(我正在使用XAMPP), PHP页面正在正常打开,但PHP代码没有被执行。
有人有什么建议吗?
注意:该文件已经命名为filename.php
编辑: 代码. .:
<?
include_once("/code/configs.php");
?>
当前回答
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 7用户,添加到你的httpd.conf文件:
# PHP 7 specific configuration
<IfModule php7_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
</IfModule>
如果我们在同一页做下面
Sudo apt-get install PHP Sudo apt-get install php-{bcmath,bz2,intl,gd,mbstring,mysql,zip,fpm} -y
要在Apache2中启用PHP 7.2 FPM,请执行以下操作:
A2enmod proxy_fcgi SetenVIF
a2enconf php7.2-fpm
更新2:Apache下载。php文件而不是渲染
在那之后,我遇到了上面的问题。还有类似的问题。
我不知道为什么,但它只发生在我的。php文件在/var/www/html/根文件夹。对于子目录来说一切正常。(例如wordpress和phpmyadmin工作得很好)
这就是我的解。我决定启用php模块。所以我运行了这个命令:
a2enmod php7.2
但我得到了这个错误:
考虑php7.2依赖mpm_prefork: 考虑mpm_prefork的冲突mpm_event: 错误:mpm_event模块已启用-由于冲突无法继续。它首先需要被禁用! 考虑mpm_prefork的冲突mpm_worker: 无法为php7.2启用依赖mpm_prefork,终止
所以我决定通过运行以下命令禁用mpm:
sudo a2dismod mpm_prefork
sudo a2dismod mpm_worker
sudo a2dismod mpm_event
然后重启apache:
Systemctl restart apache2
然后启用php7.2(我安装的版本):
Sudo a2enmod php7.2
现在一切都很好。
听起来你的配置好像有问题,下面是一些你可以检查的东西:
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手册以获得更多的设置技巧。
这是我的。htaccess
DirectoryIndex index.html index.htm
index.html包含PHP代码。默认情况下,PHP不会将扩展名为htm*的文件作为PHP代码处理。
你可以通过在.htaccess中添加以下内容来覆盖它:
<FilesMatch ".+\.html$">
SetHandler application/x-httpd-php
</FilesMatch>
在尝试了所有方法之后,我想出了这个解决方案
当默认情况下PHP 7.0 FPM未启用时,将出现此错误。
要在Apache2中启用PHP 7.0 FPM,运行:
sudo 2enmod proxy_fcgi setenvif
sudo a2enconf php7.0-fpm
systemctl restart apache2
如果您使用的是php7.4,在上面的命令中输入7.4而不是7.0。