如何修复“ Apache2 Debian默认页面”而不是我的网站

时间:2019-05-15 14:35:58

标签: php apache raspberry-pi sensor

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

这是怎么了?它显示了以下内容:

enter image description here

2 个答案:

答案 0 :(得分:0)

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

在浏览器栏中单击显示Apache2 Debian Default Page的URL,后跟:

/index.php

代替

/index.html

例如:

[ip_address]/index.php

如果apache配置文件是默认文件,则不需要其他设置即可浏览页面。可以进行进一步的配置以将根页面更改为您的根页面。参见以下内容:How do I change the default index page in Apache?

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

答案 1 :(得分:0)

您需要安装PHP,将其链接到您的apache安装,然后告诉apache根页面是“ index.php”而不是“ index.html”,以便在您请求“ /”时它可以执行索引。 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代码