PHP - localhost is currently unable to handle this request. HTTP ERROR 500

I'm currently trying to get php , apache and mysql up and running on Ubuntu. I've recently switched from Windows to Ubuntu to learn. But i'm facing a bit of a problem. When the code is correct the file gets executed properly in browser, where as when there is an syntax error, instead of showing the error in browser it throws an error as shown.

HTTP 500 Error

I've checked my php setting via phpinfo() and its as follows.phpinfo

I think error reporting is enabled, and I've tried reading similar other questions on the various threads,but they didn't really help me out. They pointed out that i need to verify that .htaccess file is in good shape. I'm not exactly sure how do i verify that, can anyone help me out? I've also tried changing directory permissions to 777 and 755 but that didn't help either. Any idea as to how can i fix it?

2

3 Answers

You display_errors directive is set to no.

To fix this:

  1. Edit /etc/php/7.0/apache2/php.ini and set:

    ; display_errors
    ; Default Value: On
    ; Development Value: On
    ; Production Value: Off
    ; display_startup_errors
    ; Default Value: Off
    ; Development Value: On
    ; Production Value: Off
    #to
    ; display_errors
    ; Default Value: On
    ; Development Value: On
    ; Production Value: On
    ; display_startup_errors
    ; Default Value: On
    ; Development Value: On
    ; Production Value: On
  2. Restart your apache with:

    sudo systemctl restart apache2
  3. To have the same behaviour on the cli edit the /etc/php/7.0/cli/php.ini

  4. To set this value locally add this to a .htaccess file in the server root: /var/www/html

Do

 vim .htaccess

Press i

Type the following:

 # Displaying php errors php_flag display_errors on php_value error_reporting 6143

Press
Esc
:x
Enter

Note:

Mine was php version 7.0. Change to your particular version. And in your image both local and master values are both set to Off so:

  1. step 1 will change the master value, and

  2. step 4 will change the local value.

2

You just need to add following lines of code to your PHP file for temporary configuration

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

you can fix now this way

1 : /etc/php/7.0/apache2/php.ini

2: ; error_reporting Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED Development Value: E_ALL Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT 3 : sudo systemctl restart apache2

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like