0

I am running a fresh install of Linux Mint 17.3 and followed this guide to setup Apache, PHP (5.5.9), MySQL and PHPMyAdmin. The only other thing I did was enable mod_rewrite.

The problem I'm having is when executing PHP code that should return a warning or fatal error, it instead returns an HTTP error 500. For example, the following code works fine (as expected):

<?php
// convert fahrenheit to celsius
$temp = 80;
$temp -= 32;
$temp *= 5/9;
echo $temp;

Whereas I would expect the following code to return a PHP warning/error, but it instead returns a completely unhelpful HTTP error 500:

<?php
// convert fahrenheit to celsius
$temp = 80;
echo ($temp -= 32) *= 5/9;

What is going on and how do I fix this issue?

mister martin
  • 6,197
  • 4
  • 30
  • 63
  • You may find you ARE getting a warning/error, but it's not being shown because you've got error notices set to not display on screen. Check your apache / error logs, or look up how to display PHP warnings and errors. – Lee Sep 16 '16 at 15:30
  • @Lee even after changing the `/etc/php5/apache2/php.ini` value `error_reporting = E_ALL` (show all errors, warnings and notices) it still gives me an HTTP 500 error. – mister martin Sep 16 '16 at 15:35
  • It will always give a 500 error, as this is the error that is occurring. Have you checked your logs? – Lee Sep 16 '16 at 15:36
  • Does this help maybe? http://stackoverflow.com/questions/2687730/how-can-i-make-php-display-the-error-instead-of-giving-me-500-internal-server-er – Lee Sep 16 '16 at 15:37
  • If you ini_set the display_errors and logs_errors in your php script, the parse error occurs before, so they are not set. Try putting the settings in the apache configuration. – Thibault Sep 16 '16 at 15:40
  • @Lee Yes, you were right to mark this as a duplicate. I had to also change `display_errors = On` and restart the server again. Errors are displaying in the browser now. Thank you. – mister martin Sep 16 '16 at 15:41
  • Glad you're all sorted :) – Lee Sep 16 '16 at 15:41

2 Answers2

1

Are you able to check your apache error logs , im sure they will tell you exactly what the 500 error is .

you could also check the error reporting in apache config/s to make sure the errors are set to report correctly

olli3
  • 11
  • 2
1

Of course, as comments say, you will/should find errors in your logs saying you have a parse error in your code on the *= part.

Here is why

The ($temp -= 32) part of your code is OK, because the value 80-32 is set back to the $temp variable. However the *= 5/9 is not set back to a variable, but to the result of ($temp -= 32) which is just a scalar value, this is why you have an error.

Just use it without the = sign to echo the result:

echo ($temp -= 32) * 5/9;

Thibault
  • 1,566
  • 15
  • 22