86

My site having 4-5 static pages only. index.html & index.php both are there. index.html is working fine. If I change to index.php, it's giving 500 Internal Server Error. I don't know where is my mistake?

Note: If I use .htaccess file with php_flag display_errors 1,

It's showing Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

If I use .htaccess file with empty,

It's showing Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

And if I give ../contact-us.php, it's showing correctly.

Thanks...

pnuts
  • 58,317
  • 11
  • 87
  • 139
KarSho
  • 5,699
  • 13
  • 45
  • 78
  • Are you typing /index.php into your address-bar or did you actually change the directory-index to index.php? Also please post the code contained in the index.php file! – Lars Ebert Jul 17 '13 at 07:11
  • 7
    Check your logs (`/var/log/apache/error.log` or `/var/log/httpd/error.log`, most likely); but I'd guess your PHP file has an error. – Amadan Jul 17 '13 at 07:11
  • may your php code have some errors – Anoop Jul 17 '13 at 07:12
  • 5
    500 Internal Server Error is generic, the real cause is hidden in your server logs. – DevZer0 Jul 17 '13 at 07:12
  • I think this related to file permission, can you check other PHP file permission and compare with the one that you renamed... –  Jul 17 '13 at 07:12
  • if i give `../contact-us.php`, it's showing correctly – KarSho Jul 17 '13 at 07:27

6 Answers6

185

500 Internal Server Error is shown if your php code has fatal errors but error displaying is switched off. You may try this to see the error itself instead of 500 error page:

In your php file:

ini_set('display_errors', 1);

In .htaccess file:

php_flag display_errors 1
Bart Friederichs
  • 33,050
  • 15
  • 95
  • 195
ozahorulia
  • 9,798
  • 8
  • 48
  • 72
  • 1
    @KarSho check this out: http://stackoverflow.com/questions/11179706/getting-internal-server-error-while-trying-to-access-my-site – ozahorulia Jul 17 '13 at 07:31
  • just want to point out that .htaccess file is present in your project root. if it isn't , simply create a new file and rename its extension – ansh sachdeva Feb 18 '20 at 11:41
  • In some case these settings aren't enough. For example I'm using PHP fast CGI and I'm stuck at internal server error but don't know where it come from. Everything seems to be alright, error was set to displayed but I think it was come from execution timeout. So, I have to enable both `FcgidIOTimeout` in apache and `max_execution_time` in PHP. If user who use PHP fast CGI, also check fcgi settings in apache config. https://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html – vee Jul 30 '21 at 10:21
90

A PHP file must have permissions set to 644. Any folder containing PHP files and PHP access (to upload files, for example) must have permissions set to 755. PHP will run a 500 error when dealing with any file or folder that has permissions set to 777!

David Valenza
  • 1,159
  • 9
  • 4
3

I was having this problem because I was trying to connect to MySQL but I didn't have the required package. I figured it out because of @Amadan's comment to check the error log. In my case, I was having the error: Call to undefined function mysql_connect()

If your PHP file has any code to connect with a My-SQL db then you might need to install php5-mysql first. I was getting this error because I hadn't installed it. All my file permissions were good. In Ubuntu, you can install it by the following command:

sudo apt-get install php5-mysql

TheRookierLearner
  • 3,643
  • 8
  • 35
  • 53
3

It was changing the line endings (from Windows CRLF to Unix LF) in the .htaccess file that fixed it for me.

Saran
  • 3,845
  • 3
  • 37
  • 59
2

I ran into this problem on Windows 8.1 while trying to use .htaccess files for rewriting. I forgot to modify the following line in httpd.conf:

#LoadModule rewrite_module modules/mod_rewrite.so

to

LoadModule rewrite_module modules/mod_rewrite.so

Restarted the apache monitor, now all works well. Just posting this as an answer because someone in the future may run across the same issue with a simple fix.

Good luck!

isherwood
  • 58,414
  • 16
  • 114
  • 157
Winter
  • 1,699
  • 1
  • 19
  • 26
1

Google guides me here but it didn't fix mine, this is a very general question and there are various causes, so I post my problem and solution here for reference in case anyone might read this later.

Another possible cause of 500 error is syntax error in header(...) function, like this one:

header($_SERVER['SERVER_PROTOCOL'] . '200 OK');

Be aware there should be space between server protocol and status code, so it should be:

header($_SERVER['SERVER_PROTOCOL'] . ' 200 OK');

So I suggest check your http header call if you have it in your code.

Lin
  • 620
  • 7
  • 11