How to handle a 500 error?

  • What is a 500 error?

    An HTTP 500 error (Internal Server Error) refers to an internal error on the web server.

    On a server that serves pages generated by PHP code, it indicates that the server encountered a problem preventing it from responding normally.

    This can originate from a PHP code error, a missing extension, a corrupted file, a misconfiguration (php.ini, .htaccess), a memory overflow, etc.

     

    The causes can be numerous, but the first thing to do to understand a 500 error is to consult its details and its trace.

  • How to display a 500 error in the front office?

    Preliminary notes on PrestaShop debug/dev mode and Symfony

    In general, dev mode should not be enabled without restriction, otherwise it will also be displayed to website visitors. There are workarounds to enable it only with, for example, a parameter passed in the URL, or by IP address filtering when modifying the URL is not possible.

     

    From PrestaShop 1.7 onwards (i.e. including Symfony) : To find the cause of a 500 error, enabling Symfony debug mode is not necessarily recommended, as it will display the error page for the first error/warning/notice encountered.

     

    You may therefore see, for example, an error page showing the details of a notice (rarely impactful) when you are actually trying to identify the fatal error (which is the true cause of the 500 error).

     

    Erreur 500

     

    How to trigger the display?

    To enable error display in a controlled manner, edit the file /config/defines.inc.php by adding a condition in the following if block :

     

    if (_PS_MODE_DEV_ === true || isset($_GET['debug_XXXXXXXXXXX']) )
    {
        @ini_set('display_errors', 'on');
        @error_reporting(E_ALL | E_STRICT);
        define('_PS_DEBUG_SQL_', true);
    }
    else
    {
        @ini_set('display_errors', 'off');
        define('_PS_DEBUG_SQL_', true);
    }

     

    Explanation :

    XXXXXXXXXXX being a random string of numbers/letters.

     

    This modification allows debug mode to be activated only by adding a custom GET parameter in the URL, for example :

    https://yoursite.com/?debug_XXXXXXXXXXX

     

    Advantages of this method :

    • Error display is only activated when you add the parameter to the URL, so normal visitors do not see the errors.
    • Notices are displayed but do not block execution — look for the "fatal" error at the bottom of the page.
  • How to find an error using server logs ?

    On the server

    Apache logs are stored in the /var/log/apache2/ directory :

    • access.log : Contains the history of all HTTP requests received by the server (accessed URLs, response codes, IP addresses, etc.)
    • error.log : Contains PHP errors, Apache errors, and all anomalies encountered by the server.

     

    Notes: The filename varies depending on the vhost. It ends with "access.log". Log rotation/compression is in place. Log splitting does not occur at exactly midnight. To consult logs around midnight, you should generally check the previous day's log file.

     

    Accessing logs: You can access these files in 2 ways :

    1. Via SFTP by navigating directly into the /var/log/apache2/ folder

    2. Via SSH using commands such as tail -f /var/log/apache2/error.log to follow errors in real time, or if the output is too verbose grep -F votreIP /var/log/apache2/nomdedomaine-error.log

     

    On some versions of PrestaShop, PrestaShop logs are located in the /var/www/(Site)/var/logs/ directory.

     

    Notes: SSH access was provided to you when your hosting was set up. If you no longer have it, feel free to contact us at [email protected]

     

    In your browser

    At 77-24, log access is available directly from the front office :

     

    Steps to access logs :

    1. Connectez-vous sur votre compte client 772424.com et accédez à votre abonnement

    2. Click on the Dashboard tab.

    3. In the Quick Access panel, click on Logs.

    4. You will be redirected to the log interface where you can connect directly to the client VM with your credentials to view logs in real time.

     

     

  • What to do with these logs?

    Once you have the log available, you can locate your error. It will contain the error details (a message explaining the cause), and possibly a stacktrace (call trace) in the case of a PHP error, which will allow you to fix your issue.

     

    If necessary, forward it to your agency for processing.