Why is Magento 2 so slow? The way in which Magento 2 is structured, is very clever as it improves the time and cost it takes to develop an eCommerce store. However, it also has the knock-on effect of slow performance and increased loading times if Magento isn’t setup correctly.
Well today, I’d like to share with you 12 very simple tips that you can change yourself in the backend of Magento, that can drastically improve your site-loading speeds in both the Frontend and Backend.
Before I start, you’ll find a link to an article I wrote that supports this video. You’ll find pictures, instructions and links that I’ll go over in a moment.
So, I wasn’t quite sure how to approach this video at first, because there are so many variables involved when it comes to improving the performance of Magento 2. So, I decided to focus on the really easy quick-wins that anyone with any skill level can follow. Some changes will be like “meh” and others will be like night and day.
I’ve also included 2 bonus tips at the end of this video, which can also result in a drastic performance increase. And although they’re a little bit more technical, I decided that they were too important not to mention.
I should also state, that if you’re currently still building your store, then think twice about using some of these tips. As they might hinder your development time.
Why is Magento 2 so slow? – Before and After
I’d first like to show you a side-by-side example of what I’d consider a worst case scenario (featured on the left) and a best case scenario (features on the right).
When the countdown hits zero, I’m going to start a race between the 2 examples. First I’ll navigate to an item of clothing, add it to my cart, and then head to the checkout.
As you can see (on the left), Magento takes a hot-minute to respond to my mouse-clicks and the pages take even longer to load.
On the right, Magento 2 feels super-responsive. As you can see, there’s a considerable difference between the 2 examples. And right now, the version on the right is still in Developer Mode. But more on Modes towards the end of this video.
So, let me repeat this experiment using the backend of Magento. I’m going to login to Magento, and create a new order.
Here, you’ll see similar results to the first. However, the keen-eyed amongst might notice that the backend is still a little bit slow on the optimised version. That’s because the tasks that you carry out on the backend of Magento are more sophisticated than what someone would do on the frontend. Meaning not as many things are able to be cached. But this is totally normal.
1. The Web Server
Now, bare in mind that I’m only running my copy of Magento on a Development Server that costs me less than $20 per month. I have many development servers with several different providers, and the optimised results I’m showing you here are all the same.
Web Hosts I use
But whilst on the subject of Web Servers, my first Tip would be to choose a server location that’s in your country. For example, when I build servers, the default setting to host the server is usually in the US. But both my customers and I are based in the UK.
Having a server so far away will result in increased delays on your store as information has to bounce backward and forwards oversees. If there isn’t a server available in your country, get one as close as you can or turn to a different provider.
2. Enable all Magento caches
My next tip has a very significant impact in performance. So, I’ll show you this now.
Head over to System > Cache Management. Make sure that all of your Cache Types are set to “Enabled”. If they aren’t then choose Select All from the Dropdown, then Enable and hit the Submit button.
Once everything is set to enabled, you will start to notice that pages you visit will be cached into the system. So, the second time you visit the page it will load much faster. This applies to both the Frontend and the Backend.
3. Enable Flat Categories and Products
Next, I’ll enable Flat Categories and Flat products.
Head over to Stores > Configuration > Catalog > Catalog and expand “Storefront”. Now set both “Use Flat Catalog Category” and “Use Flat Catalog Product” to “Yes”.
This is a form of database caching, which will result in faster loading of information on the frontend of your store. It gets much of your necessary attributes from various tables in your database, and merges them it into one easily accessible table.
You can choose which attributes get merged into your Flat Catalog by adjusting your Product attributes.
Simply go to Stores > Product. This will list all of your Product Attributes. Then chose your attribute (in my case I’ll select “color”).
Then under the “Storefront Properties” section, scroll down to “Used in Product Listing” and ensure this is set to “Yes”.
4. Merge and Minify CSS & JS Files
5. Disable JS Bundling
So this is something I tend to leave off as the benefits of having it off tend to outweigh having it on.
6. Magento Updates
This next one might sound a little obvious, and maybe it is, but I’m still going to mention it. It’s really important to ensure that your version of Magento is up-to-date. Things like old bugs and optimisation opportunities get address as more patches get released. It’s unlikely you’ll get a significant performance boost after an update, but every little helps.
You can check for updates by going to System > Web Setup Wizard and choosing System Upgrade. When the page finishes loading, it will tell you if there is an update available and walk your through the steps.
By-the-way, if you’ve made it this far during the video, I’d really appreciate it if you hit the like button on this video as it helps to support the channel. And don’t forget to subscribe for more weekly Magento videos.
7. 3rd party extension Update
So, on the subject of Magento updates, the same thing can be said for 3rd party extensions you might have installed. Just click on Extension Manager (You’ll need to wait a minute or two), but once loaded you’ll see a list of extensions you have installed with available updates. This is indicated by the blue icon. From the actions column on the right, you can choose to update the extension which will walk you through the steps.
8. Remove Third Party Extensions
One final note to mention whilst we’re in the Web Setup Wizard, is disabling unused extensions. Clicking on the Module Manager will display a list of all installed modules. Most if the items in this list are important Magento modules. But you’ll also be able to use the Actions column to disable unwanted modules that you may have installed in the past.
9. Scheduled Indexing
Next I want to talk about Indexing. I actually did a video on Indexing a few weeks ago that will explain what it is in more detail. I’ll add a link in the video description if you’d like to learn more.
Head over to System > Index Management. There’ll be a good chance that your Indexer Modes will all be set to “Update on save”. This is great if you have a few hundred products. But if you have a few thousand products, then you might find Magento a little sluggish after you make changes to your Categories or Products. Especially, if there are a few of you that edit records over the course of the day.
In cases like these, I’ve found it much more efficient to change the mode to “Update by schedule”. You can then schedule Indexing to take place over several intervals during the day, which helps reduce bottlenecking. The only downside is that your changes won’t be displayed on the frontend until the Index has taken place. In most cases I’ve found this not to be an issue.
By-the-way, if you do decide to change this to “Update by schedule”, then you can amend the schedule by going into Stores > Configuration > Advanced > System > Cron.
After expanding the Index Group, you’ll see a value for “Generate Schedules Every”. By default, this is set to 1 minute, but you could change this to whatever you feel is best. The value you set should take place from the time you save the configuration. So if it’s 12:15 and I save a value of “60” then the next scheduled Index would take place at 1:15. Unfortunately, it doesn’t appear you can set a specific time of day just yet.
10. Disable any debug logs
Sometimes you can find debug logs a heavy resource on your store. These type of logs tend to write large files to your system that aren’t necessary. Your results may vary between seeing no difference to seeing a little difference in store optimisation.
You’ll also find that debug logs are normally off by default, but it’s worth checking. To check your setup, head over to Stores > Configuration > Advanced > Developer > Debug and check that Log to File is set to “No”. If you’re in Production mode, this will be disabled by default. Again, I’ll get to Magento Modes later in this video.
You should also check that any 3rd party extensions you’ve installed are also not using debug logging. So make sure you check those settings, wherever they may be.
A quick note…
Now, these next two tips require you to be able to navigate your way around your web server via SSH. If this scares the living daylights out of you, or you have no idea what I’m talking about, that’s fine. In my article, I’ll add a message that you can copy & paste in a support ticket to your Web Host so that they can do this for you.
11. Enable Production Mode
So the first thing I want to mention are Magento Modes. There’s actually 3 Modes that Magento can switch between. They’re designed to be used during different stages of your websites development.
You’ve got Developer Mode, which is what my sites mode is in right now. It doesn’t use a great deal of caching because that just makes things harder to develop. Therefore, this mode is the slowest of them all.
Next you’ve got Production Mode. This mode is designed to cache as much as possible, and it even automatically disables some developer features that could drag down your stores performance. As you can imagine, it’s the fastest state that Magento can be in.
Lastly, you have Default Mode. This is a mixture between the first 2 modes. And as you can tell by the name, it’s also the mode that Magento comes in when you first install it.
If your store is currently live and ready for business, you’ll definitely want to switch to Production mode. However, this can only be done with the Command Line Interface, which you can only access via SSH.
To do this, first log into your server and navigate to the root directory of Magento. You’ll know that you’re there because when you type “ls -la”, you should see a list of files similar to this.
If we want to check which mode we are currently in, then simply type:
bin/magento deploy:mode:show (and hit Enter)
As you can see, I’m currently in Developer Mode.
To enable Production Mode, type:
bin/magento deploy:mode:set production (and hit enter)
After a few moments, you’ll see a bunch of text scroll down the screen followed by a confirmation message that you’ve switched modes. If you come across any errors, they can often be caused by a low PHP Memory Limit that I’ll move onto now.
Raising a ticket
Copy and paste the below message, if you would prefer to get your Web Host to do this for you:
Please, can you change the Mode of my Magento 2 store. I believe it is currently in DEFAULT MODE but would like to change this to PRODUCTION MODE. This can only be done via the Command Line Interface. Could you run the following command as the file owner: “bin/magento deploy:mode:set production”. Thanks
12. PHP Memory Limit
So my final tip of the video also requires access to your server via SSH or FTP. This instruction will only work for those using Apache with PHP. Checkout this post if you’re running Nginx.
The tip focuses on increasing your PHP Memory Limit. By default, Magento uses 756M. I’ve found that increasing this value to 2G can make a significant difference when running certain tasks.
So, assuming that you’re still in the root directory of Magento, you’ll want to edit your htaccess file using a text-editor called nano. So type:
nano .htaccess (and hit enter)
You’ll see a bunch of configuration text on the screen. Just use a combination of both Page Down and your Arrow Keys on your keyboard to navigate down to a line that says “php_value memory_limit 756M”.
You’re going to find to instances in the file. In my case, I’ve already changed the values. One for PHP5 and one for PHP7. If you’re not sure what version you’re using, just change both. Simply delete “756”M and replace with “2G”.
When typing numbers in the nano text-editor, be sure to use the number keys at the top of your keyboard rather then on the right – As they function slightly differently in the nano editor.
Once you’re happy with your changes, press Control+X to exit. Then type “Y” and Enter to save. These changes will now let Magento know what it can use more of the RAM on your web server.
Raising a ticket
Copy and paste the below message, if you would prefer to get your Web Host to do this for you:
Please, can you change the PHP Memory Limit of my Magento 2 store. I believe it is currently set to 756M, but I need it changing to 2G. The configuration options are in the .htaccess file of my Magento Root Directory. Thanks
Well, I hope you found these tips of some use. Don’t forget to backup your store before making any changes.
What you’ve seen here today focuses on super-simple settings that you can easily change in the backend of Magento 2 (with the exception of the last 2 that I just had to mention). At some point in the future, I’ll cover this topic again but discuss both Server Optimisations and 3rd Party Services to make Magento 2 faster.
Latest posts by Craig (see all)
- How to install Magento 2.3 and build a web server - 10th December 2018
- Why is Magento 2 so slow? 12 EASY Tips to make Magento 2 faster - 26th August 2018
- Magento 2.3 update – 16 things to expect - 16th August 2018