【问题标题】:How to fix "Apache2 Debian Default Page" instead of my site如何修复“Apache2 Debian 默认页面”而不是我的网站
【发布时间】:2019-05-15 14:35:58
【问题描述】:

我试图用我的树莓派地址读取我的 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 apache raspberry-pi sensors


【解决方案1】:

您需要安装 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 代码

【讨论】:

    【解决方案2】:

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

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

    /index.php
    

    而不是

    /index.html
    

    例如:

    [ip_address]/index.php
    

    如果 apache 配置文件是默认配置文件,应该不需要其他设置来浏览您的页面。进一步的配置可以将根页面更改为您的。看看这个:How do I change the default index page in Apache?

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

    【讨论】:

      猜你喜欢
      • 2018-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多