首页 > 解决方案 > 如何修复“Apache2 Debian 默认页面”而不是我的网站

问题描述

我试图用我的树莓派地址读取我的 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";
?>

它出什么问题了?它向我展示了以下内容:

在此处输入图像描述

标签: phpapacheraspberry-pisensors

解决方案


您正在查看您的网络服务器的根页面。您的 PHP 代码不在根页面中,您需要浏览到页面 index.php 。

在浏览器栏中点击显示 Apache2 Debian 默认页面的 url,然后是:

/index.php

代替

/index.html

例如:

[ip_address]/index.php

如果 apache 配置文件是默认配置文件,应该不需要其他设置来浏览您的页面。进一步的配置可以将根页面更改为您的。请参阅:如何更改 Apache 中的默认索引页面?

是的,应该安装 PHP 以运行 PHP 代码。


推荐阅读