我试图在一个项目上执行一些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");
?>
当前回答
尝试重新启动apache服务器。这就是我犯的错误——在安装php后忘记重新启动服务器!
service httpd restart
其他回答
重新安装mcrypt模块对我有用。
$sudo apt-get install php5-mcrypt
$sudo php5enmod mcrypt
听起来你的配置好像有问题,下面是一些你可以检查的东西:
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手册以获得更多的设置技巧。
我也遇到过类似的问题,但我的解决方法不同。 存放PHP代码的文件名为somename。html 把它改为" someename .php"工作得很好
这种情况又发生在我身上,服务器下载html文件,而不是处理。我已经有一段时间没有在电脑上使用web服务器apache了,同时Ubuntu从最初安装的LTS更新了两个版本。现在是这样
$ cat /etc/issue
Ubuntu 16.04 LTS
php是这样工作的:
$ sudo apt-get install lamp-server^
$ sudo a2enmod php7.0
$ sudo service apache2 restart
web服务器现在正在解析php。也许现在要更新一些网页,因为php7.0现在运行在php5之前的地方。哦。
我通过卸载XAMPP并安装WAMP解决了这个问题。 谢谢你的帮助。