How to fix HTTP 500 Internal Server Error
This Postmortem article is based on one of my Holberton School projects, where we have to fix a server which has a 500 internal error.
The response code 500 Hypertext Transfer Protocol (HTTP) Internal Server Error indicates that the server has encountered an unexpected condition that prevents it from completing the request. So let's get started.
Here is an image showing the 500 error we were talking about before, to start debugging we are going to use the "ps auxf" tool which will display the status of a Process. Remember that the output of "ps auxf" is a table where each row is a process and the columns contain the following information:
note that in the results of the COMMAND column we find apache2 information with two PIDs at the bottom, with the USER www-data and the PID 1354, and also the USER www-data and the PID 1358
taking into account the above we are going to use another of our debugging tools, in this case we are talking about "strace" which will allow us to trace the system calls and the signals received during the execution of the process and return the results of the command with the errors it found. We will do it in the following way strace -p <PID> and in another terminal window we will execute again our command curl -sI 127.0.0.1, as I show in the following image testing each one of our PID until we get something related to the error 500. we use tmux to detach the window, for more information on configuring tmux here.
run the curl -sI 127.0.0.1 again in the other window and now we will see the errors and now let's take a look.
this was part of the strace output but let's take a closer look at part of it..
You will see that the strace will not generate any more output at which point we can stop our search, at this point we can see that there is an ENOENT error. which is short for Error NO ENTry (or Error NO ENTity), and can actually be used for more than just files/directories. that is to say, the file that we are looking for is not found or does not exist, for that we go to the path where this error appears and we will look for the file as such.
yes, the file exists, so that was not the problem, the problem was that where the file is called was misspelled as class-wp-locale.phpp so it did not recognise the file. so we researched the name of that file on the internet and found out that it was a WordPress configuration file, we also found out that there are two WordPress configuration files, with sensitive and important information that will make your site work correctly or even not work, these files are called wp-config.php and wp-settings.php
Now we will use the grep 'word' filename command to help us find any lines containing the word class-wp-locale.phpp in the file. note that the configuration files are in the html directory as shown below.
Recommended by LinkedIn
we have found the error !!!! and as we can see we have checked both files and the error is in the wp-settings.php file.
Now we just need to access the file and change that word to the correct one, it can be done manually but for this project we will use a puppet file like the following one:
to be able to run it we will do it in the following way puppet apply <file.pp> like this:
we checked with the curl -sI 127.0.0.1 command and successfully fixed the 500 error !!!
I hope you found it useful, have a excellent day!
---What are your questions? Let me know in the comments, for the next topics to cover! I hope this tutorial has helped you a lot.---
my question is there are also other files like index.html that raise the same error how are they supposed to be fixed
I had a lot of trouble solving this error, but you explained it in a very detailed and fun way that anyone even who has no relation to programming could understand. Very good job, congratulations! 🐒