apache html internal-server-error php

500 Internal Server Error for php file not for html [duplicate]


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?

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.



  • 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!

    Jul 17, 2013 at 7: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, 2013 at 7:11

  • may your php code have some errors

    – Anoop

    Jul 17, 2013 at 7:12

  • 5

    500 Internal Server Error is generic, the real cause is hidden in your server logs.

    – DevZer0

    Jul 17, 2013 at 7:12

  • I think this related to file permission, can you check other PHP file permission and compare with the one that you renamed…

    – user1646111

    Jul 17, 2013 at 7:12


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!


  • 9

    How would one change those permissions?

    – JCMcRae

    Jul 10, 2016 at 15:03

  • 2

    Changing all the files permission to 755 and also the main folder to 755 Solve the problem for me

    – Oussaki

    Aug 17, 2016 at 6:17

  • Yep, that was the 500 error. It’s gone now. This answer needs more upvotes!

    Aug 16, 2017 at 11:53

  • 1

    What did the trick for me: set both group and owner of index.php as the Apache user, mine was nobody for group!

    – Heitor

    Jul 16, 2019 at 6:13

  • @JCMcRae to change permissions is simply : chmod 644 <path/file>.php

    – imrok

    Jul 29, 2019 at 9:58


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