Diagnose and correct a 500 error on a site hosted on cPanel

Procédure

How to debug a blank page or a 500 error

When you try to visit a website and you see the error message "500 Internal Server Error", this means that something has gone wrong with the website. The error can be particularly frustrating as it may not give you any information about the specific cause of the error. This article shows you how to debug a 500 error on your website.

What is the difference between a blank page and a 500 error?

A blank page is not necessarily a 500 error, and vice versa. A 500 error means that an error has occurred during the processing of the HTTP request. This could be an error in executing the associated script, a problem accessing a resource, etc. which causes the web server to return a response with the error code 500. A blank page, on the other hand, means that the web server has not returned any bodies in its response, or even no response at all.

In some situations, a 500 error means that the web server has no response to make, and therefore causes a blank page. This is possibly the case when no 500 error page has been configured, or also if error output has been disabled and so the site has no error message to mention.

Some browsers such as Chrome and Internet Explorer display their own 500 error page when they receive the HTTP header error code without the server providing any content in the body of the response:

Diagnose and correct a 500 error on a site hosted on cPanel

500 errors are often linked to a problem with one of the .htaccess files acting on the URL, or a PHP error. So, by activating error display with the php.ini display_errors option, you should see PHP errors appear instead of the 500 error.

Diagnose and correct a 500 error on a site hosted on cPanel

How can I tell if it's a 500 error?

To determine whether you have a 500 error, you need to look at the HTTP error code returned by the web server to your web browser. This can be identified using the "Network" tab in your browser's developer console:

Diagnose and correct a 500 error on a site hosted on cPanel

How do you identify the problems causing the 500 error?

The first thing to do is check the log files associated with the HTTP request: the Apache log file and the PHP log file. The last 300 events concerning you in the Apache log file can be consulted from the 'Errors' icon on your cPanel interface, while the PHP log file is generally the 'error_log' file visible next to the PHP file concerned:

Diagnose and correct a 500 error on a site hosted on cPanel

However, it is possible that errors are not displayed in the logs. This may be the result of a configuration that prevents PHP errors from being displayed and/or logged. Find out more.

However, if you are using WordPress, Prestashop or Joomla, it is quite possible that no changes will be visible. In this case, you will need toactivate error display in their respective configuration files .

How do you activate your site's debugging mode?

Most CMS such as WordPress have an internal error handling system, which prevents the PHP parameters in place from processing and taking action depending on the error encountered. By activating debug mode, you are asking this internal error management system to display errors and/or increase the verbosity of the log files.

To activate debug mode, you can connect directly to the"File Manager" accessible from your cPanel interface and edit the associated configuration file to activate this mode.

How do I activate debug mode on WordPress?

If your site was created with WordPress, you can activate debug mode from the"wp-config.php" file at the root of your web hosting. To do this, simply change the constant"WP_DEBUG" to"true" instead of"false".

If you wish, you can also add the WP_DEBUG_LOG constant to record errors in the"wp-content/debug.log" file.

You should also check that the"WP_DEBUG_DISPLAY" constant is not defined in your configuration file. If it is, you will also need to set this value to true.

The configuration file should look like this:

Diagnose and correct a 500 error on a site hosted on cPanel

How do I activate Debug mode on Prestashop?

On Prestashop, you can activate debug mode by going to the"define.inc.php" file in the"config" folder.

You will need to change the "_PS_MOD_DEV_" statement to"true" instead of"false". If necessary, you can also activate the"_PS_DEBUG_PROFILING_" mode, which will give you more information.

The configuration file should look like this:

Diagnose and correct a 500 error on a site hosted on cPanel

How do I activate Debug mode on Joomla?

For Joomla, you can activate debug mode by editing the configuration.php file. In this file, you need to change the"$debug" variable to 1 to activate it. You also need to change the $error_reporting variable to"maximum" so that all errors are displayed.

The configuration file should look like this:

Diagnose and correct a 500 error on a site hosted on cPanel

How do I activate debug mode on other CMS?

You may well be using another CMS. To find out how to activate debug mode, you can also type"CMS name + Debug" into the search engine. This should take you straight to a tutorial explaining how to activate this mode.

Understanding the different PHP errors

It is relatively easy to understand the origin of a 500 error, as it is very often the same errors that recur.

1. The first and most common error is the"Parse error". This often indicates a syntax problem (an error in the programming of your code). The error is defined as follows:

  • Parse Error: defines that this is a code error
  • A message in English is displayed to provide more information about the type of error
  • The path to the file in which the error occurs and the line affected by the error.

If we take the example of the index.php file on our Wordpress site where a semicolon is missing at the end of line 17, the Web file where the error is found is as follows:

Diagnose and correct a 500 error on a site hosted on cPanel

The error visible when you go to the URL will be as follows:

Diagnose and correct a 500 error on a site hosted on cPanel

2. The error"Parse error: syntax error, unexpected end of file" indicates that something seems to be missing at the end of the file.

Diagnose and correct a 500 error on a site hosted on cPanel

In this code, for example, the brace closing the if statement is missing.

3. Parse Error: syntax error, unexpected (T_STRING), expecting ','or'; ' is often due to an error related to the quotation mark in your code.

Diagnose and correct a 500 error on a site hosted on cPanel

In this code, the backslash on the word "error", as in the following code, is missing to make it work:

Diagnose and correct a 500 error on a site hosted on cPanel

4. You can also see an error of the"Fatal Error" type. This is one of the most serious errors you can encounter. It also causes your script to stop. It is defined as follows:

  • Fatal Error: This message indicates that the error is fatal and will stop your script from running.
  • Message: A message follows the "Fatal error" code to explain the reason for the error.
  • Access path: the access path and the line causing the problem are indicated.

This error often indicates that a function has not been defined, as in the following code:

Diagnose and correct a 500 error on a site hosted on cPanel

You will therefore see the following error: Fatal Error: Uncaught Error: Call to undefined function

This error is often due to one of the following:

  • You have a typo in the function you have defined
  • The PHP file containing the function has not been loaded into your script
  • If the function is part of a PHP extension, the PHP extension may not have been loaded.

5. It is quite possible that you will get a"Fatal Error: cannot redeclare" error indicating that the function has been defined a second time. The code could look like this:

Diagnose and correct a 500 error on a site hosted on cPanel

It is quite possible to avoid this error by:

  • changing the name of the redefined function
  • It may also be a namespace problem. In this case, you need to check the namespace and indicate the full access path to the function.

6. You may receive the error"Fatal Error: allowed memory size exhausted".

This indicates that the PHP script is using too much RAM and exceeds the maximum value authorised on PHP.INI. This is the "memory_limit" value. You can change this value in the cPanel formulas. If, despite increasing the value to a sufficiently high level, the problem persists, it may be that an operation consuming a lot of memory is being repeated too often (or even ad infinitum) in your PHP script. Infinite loops are also possible causes of this type of error.

7. The"Fatal Error: Maximum execution time exceeded" error means that the execution time of your script has been exceeded. You can modify the"max_execution_time" value in your PHP.INI configuration. Note however that any process running for more than 490 seconds is not allowed on our cPanel shared hosting packages, but above all that if a page requires a higher max_execution_time, this would also mean that it would load more slowly, which is generally not desirable. If the page that has generated this error processes a lot of data, we advise you to carry out batch processing. For example, instead of processing 1000 products each time the page is opened, it would be more appropriate to process batches of 100 products, using AJAX requests, for example. And you'll get a lower TTFB (Time-To-First-Byte).

8. The error"Fatal error: Uncaught Error: Call to undefined function mysql_connect()" means that the"mysql" module is not loaded on the PHP version you are using. The error occurs when:

  • PHP version 7 or higher is used but your site is not compatible with this version
  • You are using a PHP5 version but the "MySQL" module is not activated

You can easily change the PHP version by going to"Select a PHP version" on your cPanel interface.

9. The"Permission denied" error means that PHP does not have the rights to access a defined file or folder. This error can often be seen in the following form:

Warning file_put_contacts(/home/c123456/public_html/dossier/file.php): failed to open stream: Permission denied in /home/c123456/index.php on line 20

In this case, you need to check the chmods on your files and folders. In principle, the chmods are as follows:

  • 644: for a file
  • 755 : for a folder

10. The"No such file or directory" error indicates that PHP needs to include a file that does not appear to be present on your FTP space. The error represents the following:

Warning: require_once(/home/c123456/public_html/dossier/fichier.php): failed to open stream: No such file or directory in /home/c123456/public_html/index.php on line 20

In this case, you need to :

  • Check that the file in question exists on your FTP space. If this is not the case, you will need to re-upload the file.
  • Check that you have the correct rights to the file, i.e. CHMOD. Folders are generally chmod 755 and files are chmod 644.
  • Check that the path indicated in your PHP script is the correct one.

11. You may see the error"Warning:session_start(): Cannot send session cookie headers already sent" which indicates that a stream has already been generated and that it is therefore no longer possible to use the"session_start" function. This error can be seen in the following form:

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/c123456/public_html/dossier/session.php:2 in /home/c123456/public_html/dossier/session.php on line 20

The 3 possible causes of this error are as follows:

  • a directive displaying text before the function is called
  • A character set problem (in particular BOM_UTF8). This error always occurs on the first line of your code
  • Characters that are invisible on the screen but are present in your files. Code editors such as Visual Studio Code allow you to see these errors.

Conclusion

You can now find out the reason for a 500 or blank page error. You can also troubleshoot your website.

Don't hesitate to ask your questions and/or make comments.

Rate this article :

2.5/5 | 2 opinion

This article was useful to you ?

Article utileYes

Article non utileNo

Vous souhaitez nous laisser un commentaire concernant cet article ?

Si cela concerne une erreur dans la documentation ou un manque d'informations, n'hésitez pas à nous en faire part depuis le formulaire.

Pour toute question non liée à cette documentation ou problème technique sur l'un de vos services, contactez le support commercial ou le support technique

MerciMerci ! N'hésitez pas à poser des questions sur nos documentations si vous souhaitez plus d'informations et nous aider à les améliorer.


Vous avez noté 0 étoile(s)

Similar articles

3mn reading

Wordpress on cPanel: Solving the white page or 500 error problem

1mn reading

How to view Apache and PHP log files on cPanel

0mn reading

How do I correct a 403 Forbidden error on cPanel?

0mn reading

How do I correct a 404 error on cPanel?


Ask the LWS team and its community a question