How to fix HTTP 500 Internal Server Error

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.

No alt text provided for this image

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:

  • USER: user under which the process is running
  • PID: ID of the process
  • %CPU: percentage of time the process has been running since it was started
  • %MEM: percentage of physical memory used
  • VSZ: virtual memory of the process measured in KiB
  • RSS: "resident set size", it is the amount of physical memory not swapped that the task has used (in KiB)
  • TT: terminal controlling the process (tty)
  • STAT: status code of the process (detailed information below)
  • STARTED: start date of the process
  • TIME: accumulated CPU time
  • COMMAND: command with all its arguments

No alt text provided for this image

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.

No alt text provided for this image

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.

No alt text provided for this image

this was part of the strace output but let's take a closer look at part of it..

No alt text provided for this image

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. 

No alt text provided for this image

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.

No alt text provided for this image

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:

No alt text provided for this image

to be able to run it we will do it in the following way puppet apply <file.pp> like this:

No alt text provided for this image

we checked with the curl -sI 127.0.0.1 command and successfully fixed the 500 error !!!

No alt text provided for this image

I hope you found it useful, have a excellent day! 


https://www.linode.com/docs/guides/use-the-ps-aux-command-in-linux/

https://man7.org/linux/man-pages/man1/strace.1.html

https://www.hamvocke.com/blog/a-quick-and-easy-guide-to-tmux/

https://wordpress.org/support/article/editing-wp-config-php/#:~:text=One%20of%20the%20most%20important,WordPress%2C%20the%20wp%2Dconfig.

https://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/

https://www.puppetcookbook.com/posts/exec-a-command-in-a-manifest.html

https://linuxhint.com/use-linux-strace-command/


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

Like
Reply

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

To view or add a comment, sign in

More articles by Shannel Bejarano

  • Activation Functions

    The activation function returns an output that will be generated by the neuron given an input or set of inputs. Each of…

    1 Comment
  • ¿ What is IoT - Internet of Things ?

    The Internet of Things (IoT) is the collection of interconnected electronic devices and sensors that measure, collect…

    1 Comment
  • What happens when you type a command in the Shell?

    first let's go step by step: What is a Shell? A Shell or also known as a Command Interpreter, terminal, prompt, cmd, or…

    1 Comment
  • C - Static libraries

    WHY USE LIBRARIES One of the tools that compilers supply us with are libraries. A library is a file containing several…

  • C COMPILATION PROCESS

    The word compile means to translate programming code into machine executable code. There are different ways to compile…

Others also viewed

Explore content categories