Like any software, Magento 2 can sometimes pose challenges to its users. Today, we'll discuss common issues you might encounter during the upgrade process and ways to troubleshoot them.
Magento 2 Problem Investigation: Common Procedure
Whether you're a seasoned Magento developer or someone new to the platform, encountering issues in Magento 2 is not uncommon. The correct first step is to learn more about the issue and try the most generic ways of fixing it.
Read More: Fixing a Critical Issue in Magento 2.4.7
How to investigate any technical issue in Magento 2
1. Check ./var/log directory or your Magento 2 installation. Look for any errors or exceptions in logs, especially in log and system.log Note: If you receive a ‘There has been an error processing your request’ message while trying to open the page, take the report id from the message and check ./var/report directory. There will be a file with the same name. If it's a file permissions problem, check the owner of the files in the Magento 2 store directory and their permissions. Use chown (change owner) and chmod (change mode) UNIX commands to update them accordingly. 2. Check the web server logs. F.e., for Apache it’s /var/log/apache2 or /var/log/httpd. The folder depends on your system. 3. Clear Magento 2 cache files (if cache is enabled):
./var/cache
./var/page_cache
./var/generation
4. Switch the store to developer mode: open .htaccess file in Magento root directory and enable SetEnv MAGE_MODE “developer” or using the CLI command: php bin/magento deploy:mode:set developer. You can see more technical information about the error in this mode.
5. Enable PHP errors reporting in the ini file:
ini_set(‘display_startup_errors’,1);
ini_set(‘display_errors’,1);
error_reporting(-1);
Note: For front-end Magento 2 issues, check the browser console for errors (in Chrome:Developer tools / Console). Additionally, enable Magento 2 template page hints: in the admin panel, open the section: Stores / Settings / Configuration / Advanced / Developer / Debug / ‘Enabled Template Path Hints for Storefront’.
How to solve uncovered Magento issues?
If you are not a developer, we advise you to request the assistance of a Magento 2 experts or ask for help in Magento 2 communities such as:
- stackexchange.com/questions/tagged/magento2
- https://community.magento.com/t5/Core-Technology-Magento-2/ct-p/Magento-2
- quora.com/topic/Magento-2
- reddit.com/r/magento2/
Alternatively, you can try the solutions we list below.
Expert Magento Assistance
Overcome unsatisfactory performance, slow loading speed, and UX issues with our professionals.
Resolve all Issues with Your Magento Store
- Professional insights into fine-tuning performance and configuration best practices.
- Tips on issue logging and investigation.
- Guidance on implementing security patches and version updates.
12 Most Common Magento 2 Problems and How to Fix Them
Whether you're a seasoned Magento developer or someone new to the platform, encountering issues in Magento 2 is not uncommon. While these issues may initially seem minor, neglecting to address them promptly can lead to more significant problems.
Let's delve into the most common problems in Magento 2 and explore the ways of fixing them:
1. Installing sample data after Magento 2 setup
First, download sample data: sudo php bin/magento sampledata:deploy
Then install sample data: sudo php bin/magento setup:upgrade
2. Clearing theme/CSS cache
To clear the cache for themes or CSS, run the following commands:
sudo php bin/magento cache:flush
sudo php bin/magento cache:clean
3. Re-indexing
In Magento 2, one or more indexers may be invalid. So, you need to make sure that your Magento cron job is running.
For re-indexing your store, run the command php bin\magento indexer:reindex
in your CLI.
If you want to re-index only one indexer then write the command php bin\magento indexer:reindex indexer_name
where indexer_name
can be found by typing the command php bin\magento indexer:info
4. Removing blocks from layout
In more recent versions of Magento 2, the remove method is:
<referenceBlock name="block_name" remove="true"/>
For example: [php]
<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation=".
./../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="block_name" remove="true"/>
</body>
</page>
[/php]
5. Setting developer mode
The developer mode can be set up from the CLI with the following command:
bin/magento deploy:mode:set developer
6. Getting Magento 2 base URL
If you want to get base URL, try the below code:
$this->_storeManager->getStore()->getBaseUrl().
For getting media base URL:
$this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
7. Checking module installation
To check the enabled or disabled module list use the below command.
magento module:enable [-c|--clear-static-content] [-f|--force] [--all] <module-list>
magento module:disable [-c|--clear-static-content] [-f|--force] [--all] <module-list>
8. Using jQuery library
If you are adding your custom JS library other the jQuery then you need to include the JS code inside the required function like require(['jquery', 'jquery/ui'], function($){ });
9. Setting backend session timeout
You can set the backend session timeout from the admin panel by going to Stores->Settings->Configuration->Advanced->Admin->Security->Admin Session Lifetime (seconds)
10. 404 error for scripts and CSS
When not in production mode, Magento 2 will try to create symlinks for some static resources. You can change this behavior by doing the following:
- Open app/etc/di.xml and find the virtualType name="developerMaterialization". Here you'll find an item name="view_preprocessed" that needs to be modified or deleted. You can modify it by changing the contents from Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink
to Magento\Framework\App\View\Asset\MaterializationStrategy\Copy
- Delete the files under pub/static to get rid of any existing symlinks. Be careful not to delete the .htaccess!
11. Magento 2 front end is not working after updating
Try to regenerate the static content. When not in production mode, switch to developer mode by using this command: php bin/magento deploy:mode:set developer
Then run Command Prompt and go to Magento 2 installation directory
Run: php bin/magento setup:static-content:deploy
Then go to var directory, and run:rm -rf var/cache/*
rm -rf var/composer_home/*
rm -rf var/generation/*
rm -rf var/page_cache/*
rm -rf var/view_preprocessed/*
After that, run: php bin/magento indexer:reindex
.
Once you complete all these steps, everything should be working fine.
12. Magento 2 file not found
You may face this error when clicking on some links or when trying to log in to the admin panel. To solve it:
Run Command In Terminal: sudo gedit /etc/apache2/apache2.conf
Change the code to:<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
At the end, restart apache2: sudo service apache2 restart
Most Common Magento 2 SEO Issues
In our analysis of the Magento 2 platform, we've identified common SEO mistakes that can impact the success of Magento 2-based websites. Achieving flawless SEO is crucial for success, and the latest Magento versions have made key improvements in this area. Let's explore the most common SEO mistakes and their solutions.
Indexing both http and https versions of the website
Indexing both the http and https versions of a website can lead to duplicate content issues. To prevent this, it's advisable to index the preferred version and have the other version point to it using rel canonical. For instance, if https is your preferred version, the HTML coding for the http version should include rel canonical pointing to https, and vice versa.
TXT blocking layered navigation parameters
Magento's standard layered navigation can negatively impact your website's SEO. It's advisable to prevent filters, sorting, and layered navigation from being indexed in their original state. Consider using layered navigation extensions to transform filtered and sorted pages into well-optimized landing pages.
Magento 2 Extension Issues and Quick Solutions
When you are using third-party extensions for Magento 2, you might encounter the following issues:
Installation Challenges
Adhere to the steps outlined in the installation guide to avoid issues. Also, make sure to download the latest release of an extension for enhanced features.
- Compatibility Check: Before downloading any Magento 2 extensions, confirm their compatibility with your current Magento version. Some extensions designed for M 2.1 may not work with 2.0.
- Correct Extension Placement: Ensure that the extensions are copied to the right folders for proper functionality. For example, MConnect Media's extension should be placed under
app/code/Mconnect/MODULE_NAME
. - System Requirements: Verify that your system meets all the requirements before running Magento 2.
Cache Management
- Clear Static Cache: After installing an extension, remember to clear the static cache at:
System > Cache Management > Flush Static Files Cache
. - Static Content Cache: Clear the static content cache when making changes to settings or extensions to ensure the front end reflects the new settings and not outdated CSS files.
Functionality Issues
- Admin Sessions Problem: When facing admin session issues, resolve them by logging out and then logging back into your admin panel.
Evaluate Functionalities: Before downloading and applying an extension to your store, carefully check its functionalities to prevent conflicts with existing extensions on your store.