PHP - Error 500 - Centos 7





Error 500 Internal Server Error in PHP


I have a Google Instance running Centos 7.

I had this strange Error 500 message whenever I upload a piece of php code.

When accessing through the browser, it comes up with the error message, which was loading without issues in my local machine.


 

Internal Server Error


The error was something like this.
HTTP request sent, awaiting response... 500 Internal Server Error
2016-10-18 11:28:33 ERROR 500: Internal Server Error.
I searched around and found a solution probable solution.

Somebody suggested that I execute the following command to make it right.

sudo chcon unconfined_u:object_r:httpd_config_t:s0 myfile.php

It did work though I do not know why. My guess is that it could be something to do with the newline and return values.

Notepad plus, which is the editor that I used for this purpose, has the options, Windows, Unix and Old Mac under "Edit", "EOL Conversion". My guess is that choosing "Unix/OSX format" when saving you code in Notepad plus might be another method to solve the problem.


Here is another instance where the 500 Internal server error may occur. Let us suppose you have a symbolic link to a folder that is present elsewhere in the disk. You are referring to a specific file, it may be a config file which you want to include in your php code. This error is thrown because Centos has a problem accessing the file due to non availability of rights. As you know, every object in Unix is accessible based on rights only.

How to find the exact problem for Internal server error

Our system was Unix/Centos


We can find the exact problem by looking at the httpd server logs that are created in the Apache server or Nginx or any server that you may be running.

So, what is the Centos error log file location?

In Centos, the Centos error log file path would be  /var/log/httpd/-error_log

So, if your domain is google.com and you are running your webserver in a Centos machine, then the path to your error log file would probably be  /var/log/httpd/google.com-error_log

An example error_log file would look something like this.

[Tue Oct 18 11:35:28.950158 2016] [:error] [pid 15013] [client 172.xx.xx.49:33929] PHP Warning:  include(/home/ghost/rider/tajmahal.php): failed to open stream: Permission denied in /home/ghost/rider/opendata.php on line 3
[Tue Oct 18 11:35:28.950188 2016] [:error] [pid 15013] [client 172.68.146.49:33929] PHP Warning:  include(): Failed opening 'tajmahal.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /home/ghost/rider/opendata.php on line 3


If you look in the above log, it becomes obvious where the error lies. 

Hope it helped. 

No comments:

Two Reasons Google Ads Lead Form is Rejected

Two Reasons Google Ads Lead Form is Rejected An Investigation on Why the Google Ads Lead Form in My Google Ad Got Rejected. I just...

Most Popular

Copyrighted.com Registered & Protected DWYE-NHTO-NBNH-7FFM