500 Internal server error for php file not for html

My site has only 4-5 static pages. index.html and index.php . index.html is working fine. If I switch to index.php, it will give 500 Internal Server Error . I do not know where is my mistake?

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

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

If I use a .htaccess file with empty ,

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 displays correctly.

Thank...

+45
html php apache internal-server-error
Jul 17 '13 at 7:10
source share
6 answers

500 Internal server error is displayed if your php code has fatal errors, but error display is disabled. You can try this to see the error, not 500 error pages:

In your php file:

 ini_set('display_errors', 1); 

In the .htaccess file:

 php_flag display_errors 1 
+101
Jul 17 '13 at 7:14
source share

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

+43
Dec 16 '15 at 3:10
source share

I know this question is old, however I ran into this problem on Windows 8.1 trying to use .htaccess files for rewriting. My solution was simple, I forgot to change the next line in httpd.conf

 #LoadModule rewrite_module modules/mod_rewrite.so 

to

 LoadModule rewrite_module modules/mod_rewrite.so 

We rebooted the Apache monitor, now everything works fine. Just post this as an answer, because someone in the future may run into one problem with a simple fix.

Good luck

+1
Mar 08 '14 at 18:15
source share

I had this problem because I was trying to connect to MySQL, but I did not have the required package. I figured this out due to @Amadan's comment to check the error log. In my case, I had an error: Call to undefined function mysql_connect()

If your PHP file has any code to connect to the My-SQL database, you may need to install php5-mysql . I was getting this error because I did not install it. All of my file permissions were good. On Ubuntu, you can install it with the following command:

sudo apt-get install php5-mysql

+1
Nov 17 '14 at 19:35
source share

Google leads me here, but it didn’t help me, it is a very general question, and there are different reasons, so I post my problem and solution here for reference if someone can read it later.

Another possible cause of error 500 is a syntax error in the header(...) function, for example:

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

Remember that there must be a place between the server protocol and the status code, so it should be:

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

Therefore, I suggest checking your HTTP header if it is in your code.

0
Jul 31 '15 at 14:38
source share

It changed the line ending (from Windows CRLF to Unix LF) in the .htaccess file, which fixed it for me.

0
Nov 11 '15 at 20:50
source share



All Articles