Pages

Monday, November 5, 2012

SugarCRM Troubleshooting: Those Pesky 500 Errors

Many of us have at some point come across the dreaded Internal Server Error 500 message while routinely visiting random web sites. 

For web site visitors, it can be a frustrating experience, especially if the error is occurring on a page one needs to access to obtain important information. For system administrators, this error is even more frustrating as there is no universal solution to the problem.

Given that SugarCRM is also a web based system, it should be no surprise that it is possible to experience similar errors while using it. Before we get into some of the potential sources of this error, let us take a moment to discuss some items you can quickly cross off your list as potential sources:

1. The web browser. When an error 500 is encountered, it will manifest itself in the same manner on all browsers, whether it be Firefox, Chrome, Internet Explorer, etc. This is because it is a server side problem, thus there is no need to test different browsers.

2. The operating system. As described in the previous point, it is a server side problem. As a result, changes in either the browser or operating system at the end user side will not help alleviate the problem.

Now, let us explore some potential causes for this error. 


Although the error itself is not very informative, it does at least tell us that the problem is at the server, not the client. In the case of SugarCRM, this usually leads us to the conclusion that a bit of code in one of its source PHP files could not be parsed or did not execute. Under normal circumstances, one would not be modifying said files and the problem is indeed often times rooted in a customization.

Some common causes for such errors include:

A. Unbalanced brackets, parentheses, or braces within a code file.
Example:

<?php
//some code
if (true)
{
  //Execute some code
?>

Note the missing ending brace symbol needed to close off the IF statement. Take a look at your logic hooks, custom controllers and similar customizations and supporting files for potential syntax errors of this type and correct as necessary.

B. Using echo to output data from an array.
Example:

<?php
$myArray = array("a", "b", "c");
echo $myArray;
?>

This too is not permissible, but again, the error message does not really point us to this being its cause. As with point A above, examine your customization files for potential problems.

C. Endless loops. Take a look at your logic hooks and other custom code files. Ensure that all loops that they may contain have some method for terminating. If they do not, the endless loop will eventually consume as much memory as it can and crash. Sometimes even crashing the entire web server.

D. Improper PHP settings. Some PHP settings can also cause problems, as described in a previous post.
PHP settings are always worth a look as one can never be too sure that they are not causing problems, even though SugarCRM may appear to function correctly. For example, all features work, but specific tasks that require more memory/execution time, such as installing a module or performing a Mass Update may generate errors.

E. SugarCRM bug. Older versions of SugarCRM (early 6.3 series) had a problem where the Uservardefs.php file in cache/modules/Users would not get created correctly by SugarCRM and cause error 500 messages. To resolve the problem, upgrade your SugarCRM system. Alternatively, make the Uservardefs.php file read-only once you have a good copy of it so as to prevent SugarCRM from potentially recreating a bad version. A good copy can be obtained by forcing SugarCRM to re-create the file by means of a simple deletion of the file. Once a good copy is created, the error 500 messages will immediately disappear. 

F. Permissions. Improper permissions can generate error 500 messages. Some common scenarios are: limited permissions to the cache or custom directories, .htaccess settings limiting PHP execution and other.

In summary, unless you are making customizations to core code files, error 500 messages during SugarCRM usage are likely the result of either custom code or PHP/server configuration. 

6 comments:

  1. Excellent post! Would the extra spaces after a closing php tag also cause this error in some situations? Or is that a different error?

    ReplyDelete
    Replies
    1. Thanks Jason, can't say I've seen that with the spaces, although I have seen other problems caused by not using the PHP closing tags.

      Delete
    2. Not 500 errors, but I have seen spaces after closing statements cause issues when you're trying to process the returned data, e.g. JavaScript processing some JSON-formatted information that has extra newlines and throws off the JSON processor.

      Delete
  2. Great run-down, Angel.

    Of course I one weird exception to add to the list. We recently found a bug in a SugarCRM hotfix that caused 500 errors but was specific to only Firefox users. Weird, right? My guess is that Firefox processed/sent data slightly differently than other browsers (Chrome, specifically, worked fine) and thus the system would issue a 500 after a long delay.

    ReplyDelete
  3. how do you solve SyntaxError: missing ; before statement on sugarcrm 6.4.13

    ReplyDelete
    Replies
    1. Sharif,

      It is rather difficult to say without any context. When does it happen? Does it happen for all users? All modules?

      However, it sounds to me like you are missing a semicolon at the end of a line in a customization, perhaps a logic hook.

      Delete

Your comments, feedback and suggestions are welcome, but please refrain from using offensive language and/or berating others. Thank you in advance.