How to debug Magento
Follow each point until you finally reach a solution.
1.Enable PHP Errors
This is key to most issues. For security or other reasons, PHP error display could likely be disabled by default by your PHP configuration.
You can enable errors with a more permanent solution, or merely something more temporary.
Permanent solution
For Apache/mod_php users
In your document root's
.htaccess file - just drop this at the top.
For Nginx/FastCGI users
In your Nginx virtualhost configuration, in either the final
location .php { directive, or in the fastcgi_params file (if you have one specified)
Temporary/Universal solution
For any platform
Edit the Magento bootstrap
index.php in your document root and uncomment the following line:
2.Enable Developer Mode
When you've had an error and suddenly hit the "Error Report" page, and been given a seemingly useless error string like
1184257287824 - you've got a few options.Permanent solution
For Apache/mod_php users
In your document root
.htaccess file - just drop this at the top.
For Nginx/fastcgi users
In your Nginx virtualhost configuration, in either the final
location .php { directive, or in the fastcgi_params file (if you have one specified)
Temporary/Universal solution
Edit the Magento bootstrap
index.php in your document root and either make the if statement always true, or enabled for your specific IP.
or
3.Check your permissions
Incorrect permissions will cause a wealth of problems, a lot of which are not that easy to find at first glance.
Otherwise, the site can appear to be functioning as normal - with no critical errors actually visible.
Please bear in mind, this practice is secure for dedicated hosting but may present security issues with shared hosting if the Apache process isn’t chroot’ed per user.
In our example, the SSH/FTP user is
sonassi , the Apache user is apache and the group is apache Add the FTP/SSH user to the Apache group
Most importantly, we need to make sure that the FTP/SSH user is part of the Apache group, in our example, its
apache (but is also commonly www-data )
Keep adding as many users to the group as you have for FTP/SSH.
Reset original permissions
So before we start, lets make sure all the permissions are correct.
Making the changes permanentACLs and Sticky Bits
ACLs in Linux allow us to define specific rules, in our case, what permissions files should inherit upon creation. A sticky bit (mentioned later) takes care of group inheritance, but does not help with the permissions, which is why we use ACLs.
Start by enabling ACL support on the active partition, please ensure your Kernel was compiled with ACL support.
Your partition may be
/ , /home , /var or something else, replace as appropriate.
Now ACLs are enabled, we can set the ACL rules and group sticky bits:
But I don’t have ACL support
If your Kernel doesn’t support ACLs you can also use
umask (which is a run time setting for BASH, FTP and PHP) to set the default file permissions. Magento usually sets umask(0) in index.php , however, it would be in your interests to change this.
In your
index.php change the umask line to be
And in your BASH environment for SSH, set this in either your
.bashrc or .bash_profile
For your FTP server, you’ll need to read the documentation for it, but the principle is the same.
4.Revert theme to default
Its possible that either your theme or package is responsible for this issue. Reverting back to a vanilla Magento theme is a quick way to find out.
**This comes with the caveat that some modules may be dependent on certain theme features*
Rather than change anything via the admin panel, it is much simpler to merely rename the offending directories.
Via SSH
Or via your FTP client, traverse and rename your package to something else. eg.
myBrokenTheme.tmp If this resolves your issue
Then you need to dig a bit deeper as to what part of the template is problematic. So restore your package and attempt the following, testing between each.
Essentially, the process is to gradually enable directories as you traverse down the file tree - until you can find the offending file.
Then if either yields a fix, rename all files within the layout directory to
.tmp - (for the SSH users ls | xargs -I {} mv {} {}.tmp or rename 's/^/.tmp/' * )
Then gradually enable each file 1 by 1 until resolved.
If this doesn't resolve your issue
There is potential that your
base/default or enterprise/default directories have become contaminated - and are best replaced with a known clean version.
You can do this by downloading a clean build of Magento and replacing your directories as necessary. Via SSH you can do this:
You can also take the opportunity to
diff the two directories if you want to verify any changes.
NB. This method will cause more errors during the process, as module dependency dictates the existence of specific files. Unfortunately, its par for the course.
5.Disable local modules
By default, Magento defines the PHP include path to load classes in the following order
Again, rather than disable modules via the Magento admin panel, it is more practical to do this at a file level.
Typically, to disable a module the "proper" way, you would edit the respective
./app/etc/modules/MyModule.xml file and set <active>false</active> - however, this doesn't actually prevent a class from loading.
If another class extends a given class in a module (ignoring any Magento dependency declarations), it will still be loaded - regardless of whether the extension is disabled or not.
So again, the best means to disable an extension is to rename the directory.
Begin by disabling local
Just rename the directory via FTP, or use the following SSH command
Then disable community
If the issue is resolved from either
Then it is a case of understanding which module in particular the error stemmed from. As with the example given above for the package diagnosis, the same process applies.
So restore the X directory and attempt the following, testing between each.
Essentially, the process is to gradually enable directories (modules) one-by-one until the error re-occurs
If the issue is not resolved
Then it is possible the core itself is contaminated. The main Magento PHP core consists of
So again, rename these directories and copy in a clean variant. Assuming you already downloaded a clean version of Magento as above, via SSH, you can do this:
Then if the issue still isn't resolved, replace the
lib directory too
At this point, your Magento store will be nothing more than a vanilla installation with a modified database.
Some models are actually still stored in the database (Eg. order increment) - so at this point, it becomes a case of manually making those edits. So far, all the steps above have been reversible with no lasting damage. But if we were in import a clean Magento database too - it could prove irreversible (short of restoring a backup).
The guide above serves to get you on your way to identifying an error; not to fixing the resultant error.
|
Comments
Post a Comment