How to fix this PHP code in Raspbian (Raspberry Pi 2)?

Asked

Viewed 233 times

2

I am creating 2 monitoring projects here in the company with 2 monitoring pages that will use PHP and HTML and will run on Raspberry Pi 2 board (Raspbian). The code is very simple, I can open it normally in Windows, but in Raspbian is occurring as picture below (sorry the quality, I took from mobile):

Erro PHP Raspbian

It displays a part of the PHP code and the end, then adds the image (in html) only without the rest of the code. Below is the beginning of the code to get an idea:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
        <link rel="stylesheet" type="text/css" href="css/styles.css">
<!--        <meta name="viewport" content="width=device-width, initial-scale=1.0"> -->
        <script type="text/javascript">
            setTimeout(function(){ location.reload(); }, 30000);
        </script>

        <title>Topologia Band</title>
    </head>

    <?php
    function teste_ping ($host, $ip="173.0.0.1")
    {
        $data = date('_d_m');

        $f = fopen("ping$data.csv", 'r');
        if ($f) 
        { 
            while (($linha=fgetcsv($f))!==FALSE) 
            {
                if ((string)$ip==(string)$linha[0]) 
                {
                    if($linha[1] == "1")
                    {
                        echo "<div class='$host'><i class='verde fa fa-2x fa-wifi'></i></div>";
                        break;
                    }
                    else
                    {   
                        echo "<div class='$host'><i class='vermelho fa fa-2x fa-wifi'></i></div>";
                        break;
                    }
                }
                elseif ((string)$ip!=(string)$linha[0])
                {
                    echo "<div class='$host'><i class='azul fa fa-2x fa-wifi'></i></div>";
                }
            }
        fclose($f);
        }
    }
?>
    <body>
        <header><h1>Mapa da rede EM TESTE</h1></header>
            <div class="topologia_rede">
                <img class="img_topologia_rede" src="img/img_topologia.png">
            </div>

            <?php teste_ping('div_torre_band', 'www.google.com'); ?>
            <?php teste_ping('div_fibra_1gb', 'www.googasle.com.br');   ?>
            <?php teste_ping('div_telefonia_publica', 'www.google.com');   ?>
            <?php teste_ping('div_e1_embratel', 'www.google.com');   ?>
            <?php teste_ping('div_GRU', 'www.google.com');   ?>
            <?php teste_ping('div_embratel_20mb', 'www.google.com');   ?>
            <?php teste_ping('div_linktel_20mb', 'www.google.com');   ?>
            <?php teste_ping('div_linktel_10mb', 'www.google.com');   ?>
            <?php teste_ping('div_tvminuto_vl-mariana', 'www.google.com');   ?>
            <?php teste_ping('div_link_2mb', 'www.google.com');   ?>
            <?php teste_ping('div_radio_30mb', 'www.google.com');   ?>
            <?php teste_ping('div_embratel_100mb', 'www.google.com');   ?>
            <?php teste_ping('div_virtua_30mb', 'www.google.com');   ?>
            <?php teste_ping('div_rede_publica', 'www.google.com');   ?>
            <?php teste_ping('div_uol_diveo', 'www.google.com');   ?>
            <?php teste_ping('div_oi_wifi', 'www.google.com');   ?>
            <?php teste_ping('div_VCP', 'www.google.com');   ?>
    </body>
</html>

Could you help me figure out how to solve?

Obs1: I have tried in the browsers: Midori, Epiphany and Chromium and persists the problem;

Note: I have updated apache, PHP5 and the service is OK;

Note: Status of apache: Status Apache

  • The PHP script is not being interpreted, so it displays as text. Make sure that PHP is configured in Apache.

  • Apparently it is configured. It would have some command hint that I can use to try?

  • Create an info.php file and enter this code <?php phpinfo(); save and run by browser http://localhost/pingphp/site/info.php. A purple color page should appear with php information

  • I made the command and appeared the command line in the Browser. I’ll edit the question by inserting the image of apache2 status so you can see how it is "apparently OK" but I don’t know how to do it anymore. I already edit the question with the image.

  • It is now clear that PHP is not being loaded by Apache. Just add PHP as the Apache module. Right there in the raspi console, type service apache2 -M which will return the list of modules loaded by Apache. Probably will not show the PHP module in the list. Then vc should add the module in the httpd.conf and restart the Apache.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.