[英]How to fix “Apache2 Debian Default Page” instead of my site
我尝试用我的覆盆子pi adresse读取我的DS18B20传感器温度,我在/var/www/html/index.php中编写了这段代码
<?php
// Fichier à lire
$file = "/sys/bus/w1/devices/28-80000026ddb1/w1_slave";
// Lecture ligne par ligne
$lines = file($file);
// Recupere la 2nd ligne
$temp = explode(’=’, $lines[1]);
// Formatage de la temperature
$temp = number_format($temp[1]/1000,2, ’.’, ’’);
// On affiche la temperature
echo $temp;echo" degrés Celius";
?>
它出什么问题了? 它向我展示了以下内容:
您正在查看网络服务器的根页面。 您的PHP代码不在根页面中,您需要浏览到index.php页面。
在浏览器栏中点击显示Apache2 Debian默认页面的URL,然后是:
/index.php
代替
/index.html
例如:
[ip_address]/index.php
如果apache配置文件是默认配置文件,则不应要求其他设置来浏览您的页面。 进一步的配置可以将根页面更改为您的。 请参阅: 如何更改Apache中的默认索引页面?
是的,应该安装PHP以运行PHP代码。
您需要安装PHP,将其链接到您的apache安装,然后告诉apache根页面是“index.php”而不是“index.html”,这样当您请求“/”时它可以执行index.php脚本。
1-安装PHP引擎,例如作为apache SAPI模块:
apt install libapache2-mod-php7.0
2-将此文件放入虚拟主机或/etc/apache2/apache2.conf文件中:
DirectoryIndex index.php index.html
3-重启apache
您现在应该能够使用apache httpd执行PHP代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.