安装PHP后出现错误500

时间:2018-08-07 08:45:41

标签: php

我的网站会显示一张图片,每秒发送一次(刷新网页)。但是,我意识到我没有在apache(在树莓派pi上运行)上安装PHP,所以我做到了并更改了目录从/var/www/html/index.php/var/www/index.php并调整了路径等。

现在,如果我想显示该站点,则会出现500错误。 在日志文件中显示以下内容:

  

PHP解析错误:语法错误,意外的“ else”(T_ELSE),预计第26行的/var/www/html/index.php中的文件结尾

我的index.php(项目中唯一的文件)是这样的:

<html>
<head>
    <title>Swissskills</title>
    <link rel="stylesheet" href="css/stylesheet.css"/>
    <link rel="icon" href="pictures/post.jpg">
    <meta http-equiv="refresh" content="2.1">
</head>
<body>
    <div id="links">
        <h1 id="title">Webcam</h1>
        <?php
            /*
            $timestamp --> findet letzte Änderung der Datei heraus (nicht in lesbarer Uhrzeit formatiert --> alles in sec)
            $time --> liest aktuelle Zeit
            $diff --> differenz in sec
            */
            $dateinamen = 'pictures/Live.jpg';
            $timestamp = filemtime($dateinamen);
            $time  = time();
            $diff = $time -$timestamp;

            // Wenn Bild jünger als 2sec
            if ($diff < 2)
                echo "<img src='pictures/Live.jpg'";
            sleep(2);
            else
                echo "<img src='pictures/oops.jpg'";
        ?> 
    </div>
    <div id="rechts">
        <h2>Ping</h2>
        <?php
            /*exec (wie in Kommandozeile)
            ping (normal) -n (Anzahl Pakete) -w (Wartezeit für gesendete Pakete)
            $host (Hostname/IP-Adresse)
            $output (Detailinfos wie in Kommandozeile)
            $result (0 = vorhanden; 1 = nicht vorhanden)
            */

            $host1="192.168.1.1";
            exec("ping -n 1 -w 1 " . $host1, $output1, $result1);
            if ($result1 == 0)
                echo "<h3 id='sw1'style='background-color: green';>Router</h3></br>";
            else
                echo "<h3 id='sw1'style='background-color: red';>Router</h3></br>";


            $host2="192.168.1.10";
            exec("ping -n 1 -w 1 " . $host2, $output2, $result2);
            if ($result2 == 0)
                echo "<h3 id='sw2'style='background-color: green';>Switch 1</h3></br>";
            else
                echo "<h3 id='sw2'style='background-color: red';>Switch 1</h3></br>";


            $host3="192.168.1.11";
            exec("ping -n 1 -w 1 " . $host3, $output3, $result3);
            if ($result3 == 0)
                echo "<h3 id='sw3'style='background-color: green';>Switch 2</h3></br>";
            else
                echo "<h3 id='sw3'style='background-color: red';>Switch 2</h3></br>";
        ?>
    </div>
</body>

感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

您周围的文件中存在语法错误

if ($diff < 2)
    echo "<img src='pictures/Live.jpg'";
sleep(2);
else
    echo "<img src='pictures/oops.jpg'";

尝试在if语句中的代码周围使用大括号

if ($diff < 2) {
    echo "<img src='pictures/Live.jpg'";
    sleep(2);
} else {
    echo "<img src='pictures/oops.jpg'";
}

答案 1 :(得分:0)

您的if语句缺少左/右花括号

使用大括号或分号(http://php.net/manual/en/control-structures.alternative-syntax.php

<html>
<head>
    <title>Swissskills</title>
    <link rel="stylesheet" href="css/stylesheet.css"/>
    <link rel="icon" href="pictures/post.jpg">
    <meta http-equiv="refresh" content="2.1">
</head>
<body>
<div id="links">
    <h1 id="title">Webcam</h1>
    <?php
            /*
            $timestamp --> findet letzte Änderung der Datei heraus (nicht in lesbarer Uhrzeit formatiert --> alles in sec)
            $time --> liest aktuelle Zeit
            $diff --> differenz in sec
            */
            $dateinamen = 'pictures/Live.jpg';
            $timestamp = filemtime($dateinamen);
            $time  = time();
            $diff = $time -$timestamp;

            // Wenn Bild jünger als 2sec
            if ($diff < 2) {
                echo "<img src='pictures/Live.jpg'";
                sleep(2);
            }
            else {
                echo "<img src='pictures/oops.jpg'";
            }
        ?>
</div>
<div id="rechts">
    <h2>Ping</h2>
    <?php
    /*exec (wie in Kommandozeile)
    ping (normal) -n (Anzahl Pakete) -w (Wartezeit für gesendete Pakete)
    $host (Hostname/IP-Adresse)
    $output (Detailinfos wie in Kommandozeile)
    $result (0 = vorhanden; 1 = nicht vorhanden)
    */

    $host1="192.168.1.1";
    exec("ping -n 1 -w 1 " . $host1, $output1, $result1);
    if ($result1 == 0)
        echo "<h3 id='sw1'style='background-color: green';>Router</h3></br>";
    else
        echo "<h3 id='sw1'style='background-color: red';>Router</h3></br>";


    $host2="192.168.1.10";
    exec("ping -n 1 -w 1 " . $host2, $output2, $result2);
    if ($result2 == 0)
        echo "<h3 id='sw2'style='background-color: green';>Switch 1</h3></br>";
    else
        echo "<h3 id='sw2'style='background-color: red';>Switch 1</h3></br>";


    $host3="192.168.1.11";
    exec("ping -n 1 -w 1 " . $host3, $output3, $result3);
    if ($result3 == 0)
        echo "<h3 id='sw3'style='background-color: green';>Switch 2</h3></br>";
    else
        echo "<h3 id='sw3'style='background-color: red';>Switch 2</h3></br>";
    ?>
</div>
</body>
相关问题