This tutorial shows how to solve the common OpenCart errors.
Issue 1. Blank White Pages or 500 Internal Server Error
Blank white page is a PHP error which is just not visible when the server is not configured to display the errors, while the 500 Internal Server Error means something has gone wrong but the server cannot specifically state what the exact problem is.
Log into your Opencart admin.
Go to System – Settings – ‘Edit’ and set ‘Output Compression Level’ to 0:
Open php.ini and add the code below:
display_errors = 1;
error_reporting = E_ALL;
log_errors = 1;
If php.ini is not used or read by the server, you can use an alternative method – open index.php file and add the following code to the top of the file (line 2):
As soon as the issue is fixed, please remove the above code.
Error 2. Undefined Index / Variable
The error appears when you are referencing the variable that has not been declared in PHP.
– PHP Notice: Undefined index: company in /path/public_html/catalog/model/account/customer.php on line 8.
– PHP Notice: Undefined variable: order_id in /path/public_html/catalog/controller/account/order.php on line 149.
– PHP Notice: Undefined variable: product in /path/public_html/vqmod/vqcache/vq2-catalog_view_theme_default_template_product_product.tpl on line 272.
If you get this issue after installing a third party extension, disable the extension.
If the error refers to file inside the ‘/vqmod/vqcache’ folder, it means the error is caused by the vQmod file. Rename the vQmod file to vqmod_file.xml_.
Issue 3. Undefined Function / Method
If you get ‘Fatal error: Call to undefined function’ or ‘Fatal error: Call to undefined method’, it means you try to call the function/ method that doesn’t exist. The error commonly happens if the files are not uploaded properly or the extensions are not compatible with your OpenCart version.
Related to OpenCart core files:
– Fatal error: Call to undefined function utf8_strlen() in /path/public_html/system/helper/utf8.php on line 39;
– Fatal error: Call to undefined method Customer::isLogged() in /path/public_html/catalog/model/catalog/product.php on line 8;
– Warning: require_once(/path/public_html/system/library/customer.php) [function.require-once]: failed to open stream: No such file or directory in /path/public_html/index.php on line 22;
– Fatal error: require_once() [function.require]: Failed opening required ‘/path/public_html/system/library/customer.php’ (include_path=’.:/usr/lib/php’) in /path/public_html/index.php on line 22;
Related to vQmod files:
– Fatal error: Call to undefined method ModelAccountCustomer::getPaymentAddress() in /path/public_html/vqmod/vqcache/vq2-catalog_controller_checkout_confirm.php on line 38;
Related to PHP built-in functions:
– Fatal error: Call to undefined function imagecreatefromjpeg() in /path/public_html/system/library/image.php on line 34
– Fatal error: Call to undefined function mysql_connect() in /path/public_html/system/database/mysql.php on line 6
Related to OpenCart core files:
– Some files were not uploaded properly or corrupted during the upload process. Re-upload the files to your server with ASCII mode, not binary:
– “Warning/ Fatal error: require_once” means the file is not available. You need to re-upload the file mentioned in the error message or fix the server path for config.php (make sure the config.php file is located in admin/config.php).
Related to vQmod files:
– vQmod fails to generate new cache from the extensions of vQmod files. Check vqmod/cache folder permissions, make sure they are writable and clear all cache files.
– Enable / disable the vQmod files you have one by one.
– The extensions are not compatible with the OpenCart version you use.
Related to PHP built-in functions:
– Errors related to PHP built-in functions are server issues. Get in touch with your hosting provider to solve such type of issues.
Issue 4. Headers Already Sent
The error message “headers already sent” commonly occurs right after installing, modifying, updating OpenCart or vQmod files.
– Warning: Cannot modify header information – headers already sent by (output started at /path/public_html/config.php:31) in /path/public_html/index.php on line 175.
– Warning: session_start() [function.session-start]: Cannot send session cookie – headers already sent by (output started at /path/public_html/config.php:31) in /path/public_html/system/library/session.php on line 11.
– Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at /path/public_html/config.php:31) in /path/public_html/system/library/session.php on line 11.
Download the file mentioned in the error message and apply the solution bellow:
Remove spaces at the beginning and at the end of the file.
<?php //contain space
echo "remove all space or line-break before <?php and after ?>";
Save the file with Notepad++ or other editor (encode file as ANSI or UTF-8 without BOM):
Re-upload the file to the server through FTP in ASCII mode, not binary.
Issue 5. Session Issue
The PHP session stores the user information on the server for later use (i.e. login status, shopping items, etc.). In most cases the session issue throws error messages. But when there are no error messages mentioned, there are some cases of indication of the session issue:
– Products in the cart get self-cleared;
– Products in the cart get cleared after the user logs into;
– OpenCart admin keeps asking to log in and there is the message ‘Invalid token session. Please login again’.
– Warning: session_start () [function.session-start]: open (/tmp/sess_41abirkdiesf9efwej46wtib2, O_RDWR) failed: No such file or directory (2) in /path/public_html/system /library /session.php on line 11;
– Warning: session_start () [function.session-start]: open (/tmp/sess_41abirkdiesf9efwej46wtib2, O_RDWR) failed: Permission denied (13) in /path/public_html/system /library /session.php on line 11;
– Warning: session_start() [function.session-start]: open(/tmp/sess_41abirkdiesf9efwej46wtib2, O_RDWR) failed: No space left on device (28) in /path/public_html/upload/system/library/session.php on line 11.
No such file or directory issue:
Open php.ini and add code below:
session.save_path = /tmp;
If the solution above does not work, please contact your hosting provider asking them how to set the session.save_path.
‘Permission denied’ error. Ask your hosting to check the session directory permissions.
‘No space left on device’ error. Ask your hosting if this is the server issue or if you need to upgrade to the package with more hosting space.
Issue 6. Allowed Memory Size Exhausted
This error occurs when your memory is not enough to execute the php code. It means that the memory used by the PHP script exceeded the value of the memory_limit configuration option.
– Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 47200 bytes) in /path/public_html/system/library/image.php on line 34;
– Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 13069817 bytes) in /path/public_html/system/library/mail.php on line 144;
– Fatal error: Out of memory (allocated 33554432) (tried to allocate 14024 bytes) in /path/public_html/library/image.php on line 34.
Apply one of the following solutions to increase the limit to 64MB, 128MB, 256MB or 512MB depending on your host.
Increase the memory limit value in php.ini file:
memory_limit = 128M;
Or add the code below to .htaccess file:
php_value memory_limit 128M
If you get this issue quite often and the solution above does not work, please contact your hosting provider.
Issue 7. Restriction in effect
You get an error message ‘SAFE MODE Restriction in effect’. This is a PHP restriction issue. This issue is not related to OpenCart or a template but is related to your server configuration.
– Warning: session_start() [function.session-start]: SAFE MODE Restriction in effect. The script whose uid is 10025 is not allowed to access /path/public_html/system/library/session.php on line 11;
– Warning: imagejpeg() [function.imagejpeg]: SAFE MODE Restriction in effect. The script whose uid is 10305 is not allowed to access /path/public_html/image/cache/data owned by uid 48 in /path/public_html/system/library/image.php on line 44;
– Warning: is_dir(): open_basedir restriction in effect. File(/path/public_html/image/87cngmlc22pe96fof5fhmq9c290phri7) is not within the allowed path(s): (/path/server/) in /path/public_html/catalog/controller/checkout/confirm.php on line 248.
Since this is a server issue, asking your host to turn off the restriction is the best way to fix it.
But in case you want to try to resolve it on your own, please add this piece of code to php.ini:
safe_mode = Off;
Or put the code below to .htaccess:
php_value safe_mode off
This is the end of the tutorial. Now you know how to resolve the common Opencart errors.