Are You Suddenly Seeing an Error on Every Page of Your Joomla Website?

We just got a call from a new client. The client told us that he was suddenly seeing an error on every page of his Joomla website. The page still loads, but there is an error on every page that loads. It’s not the first time that we had such a call, and that’s why we decided to write a comprehensive post about this topic. So, what is the reason for this and how can this be fixed?

Well, there are two scenarios when you have this problem:

  1. The error appears on every page, but the page still loads

    In this case, what you’re seeing is a warning or a notice, and not an error. The reasons for seeing warnings and notices are many, and they include (but are not limited to) the following:

    • Header issues: You are printing something (like an empty space) before the headers are sent to the browser – this causes a warning to be raised. Usually the cause of this is that there is a character (such as an empty space) that was wrongly inserted in one of your Joomla files.
    • Session issues: The Joomla engine is trying to retrieve/store non-necessary information from/to the $_SESSION array, but it’s unable to do so.

    • File issues: You are including a file that doesn’t exist or that was already included using the include PHP function. The solution to this problem is by ensuring that you use include_once and you only include files that do exist.

    • Database issues: There is an error in one of your SQL queries. This error however, is still tolerated by the Joomla engine and that’s why the page still loads (generally this is the case when the SQL error happens in one of the non-critical modules).

    • Missing argument(s): This warning happens when you are calling a function that requires n mandatory parameters, but you are passing less than n values to the function. For example, let’s say you have this following function:

      function add(a, b){
      return a + b;
      }

      A correct call of the function above is add(2, 3);. If you omit the second argument (3), then you will get the following warning: Missing argument 2 for add().

    • Array warnings: For example, a script on your Joomla website is trying to access an invalid element of an array (e.g. the array consists of 4 elements and your script is trying to access element #8), or is trying to use array functions on non-arrays. (such as using array_merge or ksort)

    All of the above are warnings and not notices. Notices, which are just information sent by PHP, generally do not indicate anything major on your website, and they are there just to inform you about something. Most of the notices on a Joomla website are about coding standards and deprecated functions. The default installation of the latest Joomla version (1.5.25, 1.7, or 2.5) does not raise any notices – so whenever you see a notice it’s because of some code that you have added to your website, or because of a badly written/old extension.

    Notices and warnings can be suppressed by logging in to your Joomla control panel and then going to SiteGlobal Configuration, and then setting the Error Reporting field to None, and finally clicking on the Save button on the top left.

  2. The error appears on every page, and the rest of the page does not load

    In this situation, what are you are seeing is an actual error. The difference between warnings/notices and errors is that the latter will halt any progress of the page loading process. There are many errors that can happen on a Joomla website, and they are can be categorized into five types:

    1. Joomla Errors: Joomla errors include the famous “invalid token” problem as well as the component not found error. Joomla errors are raised by the Joomla engine and are Joomla specific errors. Joomla errors indicate a misuse (or bad coding) of the Joomla extensions/templates/functionalities.
    2. PHP Errors: PHP errors on a Joomla website are errors that have to do with the coding or with the environment. Common PHP errors include:

      • Parse errors: Parse errors are errors that result usually from typos or missing (or extra) brackets, parenthesis, or semicolons. Parse errors are easily solved as the PHP parser will indicate exactly where they are (which file and which line).
      • Permission errors: Permission errors happen when Joomla is not able to read or write from/to a critical file because of wrong permissions. For example, Joomla needs to read the configuration.php file at all times, but if the permissions on that file are 222 (can only be written) then Joomla cannot read it.

      • Include errors: Include errors happen when PHP is trying to include a file, but that file does not exist or exists in another location than the one specified. Include errors happen when you use the require or the require_once functions instead of the include or include_once functions.

      • Memory errors: Memory errors mean that the script has exceeded the memory limitation set by the default PHP configuration. Memory errors are when you see something like Fatal error: Allowed memory size of n bytes exhausted (tried to allocate m bytes). Memory errors can be easily solved by increasing the memory for the PHP instance either in the php.ini, or, more conveniently, by using the ini_set function. For example, placing ini_set('memory_limit', '1024M'); in your index.php file will increase the memory allocated for your Joomla website to 1 GB (1024 MB).

      • Execution time exceeded errors: These errors happen when the page just takes so much time to be executed on the server before sending it to the client. Most hosting companies set the maximum execution time to around 30 seconds. If the page does not get executed within the maximum execution time, then the page will display the following error: Fatal error: Maximum execution time of n seconds exceeded. Again, this error can be addressed by increasing the maximum execution time in php.ini or by adding the following code to the top of your index.php file:

        ini_set("max_execution_time", "600");

        The above code changes the maximum execution time of the script to 10 minutes (600 seconds) – which should be more than enough for any PHP script out there!

      • Usage in wrong context errors: For example, you are trying to use an object as a string or as an array.

      • Object errors: For example, you are trying to access a static method as non-static or vice versa. In this case, you will see the following error: Fatal error: Cannot make non static method [functionname] static in class [classname] in /home/yourjoomlawebsite.com/public_html/modules/modulename/classname.php on line n. Another object error is when you’re trying to invoke a method on a non-object (in this case you will see: Fatal error: Call to a member function on a non-object)

      • Other fatal PHP errors include: Re-declaring functions/classes (you will see something like Cannot re-declare function… or Cannot re-declare class), division by zero errors, redefining constants, etc…

    3. Database Errors

      Some (not all) database errors can crash your whole website, causing a “fatal error” to show on every single page. Common database errors include:

      • Connection errors: Connection errors happen when the Joomla website cannot connect to the database at all. Connection errors usually happen because of one (or more) of the following:
        • The link between Joomla and the database is lost. This often happens when the Joomla website (e.g. PHP code) is on one server, and the database is on another server, and the connection between the two servers cannot be established for one reason or the other.

        • The username and/or password to the database is wrong. This happens when the supplied username and/or password in the configuration.php do not match the correct username and/or password for that particular database.

        • The database doesn’t exist. This often happens because of a typo in the database name, or when moving the Joomla website from one server to another, where the name of the database is different.

        Usually, when there is a connection error, you will see the following error message on every page of your Joomla website: Database Error: Unable to connect to the database: Could not connect to MySQL.

      • SQL errors: These errors happen because of a wrong query statement. Of course, we have already listed SQL errors as warnings above and we stated that they don’t break the website. However, there are some queries on your Joomla website that are critical to the website as a whole, and if they are wrong, they can definitely break it. Site breaking queries include System plugins queries – such queries can render the whole website inoperable if wrong as they run on every page!

    4. .htaccess errors: The .htaccess file located in the root directory of your Joomla website is a very delicate file. If you make a mistake anywhere on this file there is a high chance that your whole website will go down – displaying the much dreaded “Internal Server Error” message.

    5. Internal Server Errors: These errors can be any of the errors mentioned above, it’s just there’s a way to program Joomla to throw a “500 – Internal Server Error” whenever a fatal error occurs. You will need to turn debugging on in order to know what the actual error is. Note that often, an internal server error means that there’s something wrong with your .htaccess file and it relates to Joomla’s SEF or sh404. Disable the aforementioned extensions and see if this resolves the problem.

    6. If you are seeing an error on every page of your Joomla website and are unable to fix the problem then why don’t you contact us? We are fast, we are friendly, we can definitely help you, and our fees are very reasonable!

2 Responses to “Are You Suddenly Seeing an Error on Every Page of Your Joomla Website?”
  1. Pingback by “Allowed Memory Size of x Bytes Exhausted” Error on Joomla | itoctopus — March 8, 2012 @ 12:38 pm

    […] allowed memory size is not a Joomla error, it’s a PHP error (here’s a list of all the possible errors that may occur on a Joomla website). It happens when PHP needs more memory to run your scripts, but is unable to allocate more memory […]

  2. Pingback by How to Debug Joomla? | itoctopus — July 30, 2012 @ 11:27 am

    […] error suddenly appears on your Joomla site – or you see the same error on every page of your Joomla website. (If you see a blank page then make sure you enable error reporting – see here for a full […]

Leave a comment