How to fix the most common issues in Magento2

How to fix the most common issues in Magento2
Posted in: Magento 2 Guides

The new version of Magento i.e. Magento 2 has come with new challenges. When you are planning to upgrade your older versions to the new one, you may face some of these issues that we will discuss today, and tell you how to troubleshoot them.

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.
Learn More


Most common Magento 2 problems and their troubleshooting

The experienced Magento developers or any other person can face the most common issues when you are exploring the Magento 2 platform. The issues which you may face can be undeniable little trouble but if you do not try to resolve these soon they can become bigger problems for you.

So, let us understand the most common problems faced in Magento 2 with their solutions:

Installing sample data after Magento 2 setup

First, download sample data: sudo php bin/magento sampledata:deploy and then install sample data: sudo php bin/magento setup:upgrade

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

Re-indexing

In Magento 2, one or more indexers are 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 command php bin\magento indexer:info

Removing block 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]

Setting developer mode

The developer mode can be set up from the CLI bin/magento deploy:mode:set developer

Getting Magento 2 base URL

If you want to get Base url ,then you can try below code:

$this->_storeManager->getStore()->getBaseUrl()

Also use:

$this->_objectManager->get('Magento\Store\Model\StoreManagerInterface')

                                                           ->getStore($storeId)

                                                           ->getBaseUrl();

For getting media base URL:

 $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);

Checking module installation

To check the enabled or disabled module list use 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>

Using jQuery library

If you are adding your custom js library other the jQuery then you need to include the js code inside require function like:

require(['jquery', 'jquery/ui'], function($){

});

Setting backend session timeout

You can set the backend session timeout from the admin panel by Stores->Settings->Configuration->Advanced->Admin->Security->Admin Session Lifetime (seconds)

404 error for scripts and CSS

When not in the production mode, Magento 2 will try to create symlinks for some static resources. You can change that behavior by doing the following.

  1. Open up app/etc/di.xml and find the virtualType name="developerMaterialization" In that section 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
  2. Delete the files under pub/static to get rid of any existing symlinks. You may want to be careful not to delete the .htaccess

Magento 2 frontend is not working after updating

Try to regenerate the static content.

  1. When not in production mode, turn on theme to developer mode, use this: php bin/magento deploy:mode:set developer
  2. then run Command Prompt
  3. go to Magento 2 installation directory
  4. run: php bin/magento setup:static-content:deploy
  5. 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. When all the steps are taken, everything should work fine.

Magento 2 file not found

You may face this error when clicking on further links or when trying to log in to the admin panel. To solve it:

  1. run Command In Terminal: sudo gedit /etc/apache2/apache2.conf
  2. change the code to:

<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

In the end, restart apache2: sudo service apache2 restart

Most Common Magento 2 SEO Issues

While analyzing the new Magento 2 platform, we came across the most common mistakes when it comes to SEO. The Magento 2 based websites can be successful when their SEO is set flawlessly. In the latest versions of Magento, you can find the key improvements done in SEO. The most common SEO mistakes and their solutions are:

Indexing both http and https versions of the website

When you index the http and https versions of the website, it considers one of the version as the duplicate content.

To avoid this mistake, you should be indexing the preferred version and the other version of the same URL should point to the https version with rel canonical. For example, https is the preferred version for your website, then in the HTML coding, the http version should have the rel canonical pointing to https and vice versa.

txt blocking layered navigation parameters

Usually, the layered navigation is not at all good for your website in terms of SEO. You should always avoid the filters, sorting and the layered navigation being indexed in their 'raw' state. Also, you can use layered navigation extensions which can turn your filtered and sorted pages into properly optimized landing pages.

Magento 2 extension issues and  solutions

When you are using any extension for the Magento 2 version, check for the following issues and the fixes:

  • Compatibility with the Magento versions: Before you download any of our Magento 2 extensions, check whether it is compatible with the Magento version you are currently using. For example, a lot of extensions made for M 2.1 may be not working for 2.0.
  • Installation steps: Follow all the steps provided in the installation guideline
  • Latest versions of Magento 2 extensions: If you want to use any of the extensions, download the latest release of that extension for the better features.
  • Clearing Static Cache: Once you have installed the extension, don’t forget to clear the static cache before you actually use the extension on your store. You can do that by: System > Cache Management > Flush Static Files Cache.
  • Static Content Cache: When you have made any changes in settings or extension, make sure you clear the static content cache. This will make sure that the front end is working on the new settings and not the old CSS files.
  • Admin Sessions Problems: To solve the admin sessions issue, try to logout and then login again to your admin panel.
  • Functionalities: Before you download, install and apply the extension on your store, check the functionalities carefully as it may clash with the functionalities of the existing extension on the store.

Problems in installation:

  • Right place to copy the extensions: The extensions should be copied to the correct folders to work properly. For example, the MConnect Media’s extension will go under: app/code/Mconnect/MODULE_NAME
  • System requirements: Before you run Magento 2, make sure you have all the system requirements.

Common procedure for Magento 2 problem investigation

How to investigate the technical problem:

  • Check ./var/log directory or your Magento 2 installation — look for any errors or exceptions in logs, especially in log and system.log
  • If you’ve got ‘There has been an error processing your request’ message on page opening, take the report id from that message and check ./var/report directory: there will be a file with the same name.
  • There can be file permissions problem: check the owner of the files in Magento 2 store directory and their permissions. Use chown(change owner) and chmod (change mode) UNIX commands to update them accordingly.
  • Check the web server logs. F.e., for Apache it’s /var/log/apache2 or /var/log/httpd,  the folder depends on your system.
  • Clear Magento 2 cache files (if cache is enabled), sometimes it helps:
    • ./var/cache
    • ./var/page_cache
    • ./var/generation
  • 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
    It can show more technical information (error) in this mode.
  • Enable PHP errors reporting in the ini file:
    • ini_set(‘display_startup_errors’,1);
    • ini_set(‘display_errors’,1);
    • error_reporting(-1);
  • Front end issues:
    • Check browser console for the errors (in Chrome: Developer tools / Console).
    • 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 the found Magento issues?

This article was provided by M-Connect Media, an official Amasty partner.

At M-Connect Media, our experienced developers always pursue the Magento guidelines and hierarchy to code and design your projects. And we perform each cases and actions on the dev environment before deploying it to the production. Our Magento based services have been appreciated by many of our clients' due to results they have got for their websites. If you are looking for a user-friendly design, advanced functionalities and flawless performance, then try our Magento support services and we are sure that you would keep coming back!

September 15, 2016
September 23, 2016
July 9, 2016
Comments
Vasilii
May 4, 2017
$this->_objectManager This method is not suggested to use at all, as it was described int official Magento documentation and Github. That is a bad practice.
Reply
Make Vana
January 24, 2018
Cache management page notification is appearing often every 2 minutes. , even after refreshing. Do you know any solution!
Reply
rohimic
June 29, 2018
One can upgrade magento 2 using the two basic methods, one is from admin panel and other is using composer.
Reply
vijay
June 27, 2022
after updating magento 2 backend frontend is not getting updated
Reply
vidhant24 on-demand services
July 5, 2022
This was a very meaningful post, so informative and encouraging information. normal home services
Reply
Leave your comment

Your email address will not be published

This blog was created with Amasty Blog Pro

This blog was created with Amasty Blog Pro

© 2009-2023 Amasty. All Rights Reserved.