500 Internal server error in PHP files

Asked

Viewed 1,993 times

2

Every time I run a PHP file on the server it returns (in the header) an error 500. This only happens with PHP files...

Commands like echo and phpinfo() only strings work (tested with echo 'teste';). But if I go to use more complex codes, like include arrays and etc, it no longer works and gives that error.

I thought it might be an error in my script, but it works on localhost...

The exit to ls -l in the briefcase public_html is the following:

drwxr-xr-x 3 root root 4096 Jan 28 06:50 app
drwxr-xr-x 2 root root 4096 Jan 28 06:50 css
drwxr-xr-x 2 root root 4096 Jan 28 06:50 fonts
drwxr-xr-x 5 root root 4096 Jan 28 06:52 img
-rwxr-xr-x 1 root root  859 Jan 28 06:50 index.php
drwxr-xr-x 2 root root 4096 Jan 28 06:52 js

From now on, thank you.

@Edit:

Follow my full script.

<?php

ini_set('display_errors', true);
error_reporting(E_ALL);

/*
 *  0 = confirmado
 *  1 = talvez
 *  2 = não vai
 */

$convidados = [
    'Cieli' => [0,15],
    'Carlinhos' => [0,30],
    'Daianna' => [1,0],
    'Renato' => [0,20],
    'Ana' => [3,0],
    'Larissa' => [0,20],
    'Debora' => [0,30],
    'Dani' => [0,0],
    'Suelen' => [1,0],
    'Vitor' => [1,0],
    'Felipe' => [1,0],
    'Luany' => [1,0],
    'Sandra' => [1,0],
    'Halysson' => [1,0],
    'Karina' => [3,0],
    'Mariana' => [3,0],
    'Wanessa' => [0,30],
    'Matheus' => [1,20],
    'Mauricio' => [3,0],
    'Mayara' => [1,20],
    'Lukas' => [1,0],
    'Leticia' => [1,0],
    'Geord' => [1,0],
    'Zé' => [3,0],
    'Luana' => [1,0],
    'Keity' => [0,20],
    'Werinton' => [0,20]
];

ksort($convidados);

$confirmed       = '<i class="fa fa-check"></i>';
$not_confirmed   = '<i class="fa fa-times"></i>';
$awaiting        = '<i class="fa fa-circle"></i>';
$total           = [];
$total_confirmed = 0;

foreach ($convidados as $key => $value) {
    $total[] = $convidados[$key][1];

    if( $convidados[$key][0] === 0 ) {
        $total_confirmed += 1;
    }
}

?>

<!DOCTYPE html>
<html class="no-js" lang="">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Site</title>

        <meta name="viewport" content="width=device-width, initial-scale=1">

        <link rel="stylesheet" href="css/normalize.css">
        <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
        <link href='http://fonts.googleapis.com/css?family=Slabo+27px' rel='stylesheet' type='text/css'>
        <link rel="stylesheet" href="css/main.css">

        <script src="js/vendor/modernizr-2.8.3.min.js"></script>
    </head>
    <body>

        <header>
            <h2>
                Site
            </h2>
        </header>

        <main role="main" class="main-width">
            <h3>Tabela de confirmados</h3>

            <table>
                <caption>
                    Legenda: (<?php echo $confirmed; ?>) Confirmado, (<?php echo $awaiting; ?>) Aguardando confirmação, (<?php echo $not_confirmed; ?>) Não confirmado
                </caption>
                <thead>
                    <tr>
                        <td>Convidado</td>
                        <td>Confirmado</td>
                        <td>Valor</td>
                    </tr>
                </thead>
                <tbody>
                <?php
                    foreach ($convidados as $key => $value) {
                        echo 
                            '
                            <tr>
                                <td>' . $key . '</td>
                                <td>' . ($convidados[$key][0] === 0 ? $confirmed : ($convidados[$key][0] === 1 ? $awaiting : $not_confirmed)) . '</td>
                                <td>R$' . number_format($convidados[$key][1], 2, ',', '.') . '</td>
                            </tr>
                            ';
                    }
                ?>
                </tbody>
                <tfoot>
                    <tr>
                        <td colspan="2">Total de confirmados: <?php echo $total_confirmed; ?></td>
                        <td colspan="1">Total arrecadado: R$<?php echo number_format(array_sum($total), 2, ',', '.'); ?></td>
                    </tr>
                </tfoot>
            </table>
        </main>

        <script src="js/main.js"></script>
    </body>
</html>
  • In your test files, add these two lines to display errors on the production host: ini_set('display_errors', true); error_reporting(E_ALL);. Blank screen or error 500 is sure error in code.

  • I was already wearing... See the above script; It would not be a mistake in the code I tried to create an array and echo it through the Indice, which works on localhost, but on the server does not work.

  • Error appeared? which version of php of the two servers?

  • 1

    No, no errors. On the site, the page is blank, on localhost, works perfectly. The localhost version is 5.5.9, and on the site is 5.3.3

  • Have you checked apache logs? Is there any error_log in the current script directory?

  • Can you tell me where the log directory is? The server uses Centos...

  • Logs in Centos is on /var/logs/httpd. I believe there may be an error in CGI if you are using CGI.

  • 1

    It has a lot of bug logs, mostly or related to files not found (probably script tests), others in relation to the Date() function, an older log with this "script not found or Unable to stat: /var/www/cgi-bin/test-cgi" and the latest related to CGI is this: "client sent HTTP/1.1 request without hostname (see RFC2616 Section 14.23): /tmUnblock.cgi"

Show 3 more comments

1 answer

2

To abbreviated array syntax is available from php5.4, as your production host uses a lower version (5.3.3) compared to localhost(5.5.9), the following error is generated:

syntax error, Unexpected '[' in

To fix this you need to convert to old syntax, this can be with a replace from your IDE/text editor copy the array snippet, then replace [ for array( and ] for ) don’t forget to $total who is also an array.

Syntax php5.4

$convidados = [
    'Cieli' => [0,15],
    'Carlinhos' => [0,30]
];

Syntax for previous versions:

$convidados = array(
    'Cieli' => array(0,15),
    'Carlinhos' => array(0,30)
);

In the example(sandbox) it is possible to run the code in different versions of php. See your converted code running on phpfiddle where php version is 5.3.29.

  • I also thought that might be it. And I’ve even done the tests with this syntax. But I still keep getting this error on the console... See a screenshot of the console: http://i.imgur.com/L6nwcud.png (+1 At the tip of the array, I didn’t know..)

Browser other questions tagged

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