New Magento 2 install is terribly slow

There are a lot complains on the Internet about the loading time of a Magento 2 website, some people have even been switching to another CMS ! Here at Linkstraffic we like to analyse what’s behind the scene and how could a new Magento 2 install could generate such performance issue.

First thing to say, avoid installing the 2.1 version for production as it is not fully stable at the moment. However for this test, we will stick to this latest build.

Reproduce the Magento2 performance problem

In our case, we’ve just installed the CMS using composer on a Debian server running Apache 2.4, Php 5.6.x version along with Mysql 5.7. We’ve loaded the sample data and set up a home page such as in Luma Theme.

Please refer to Magento 2 system requirements for more informations.

When you are in Dev. mode, here is what we notice :

  • it takes ages to load
  • Making changes is so long….

We can definitively not work on it.

So what can we do if  we don’t want to quit the dev mode and keep not using cache ?

1st TRY on fixing the slowness of Magento2  :

Update Magento 2 using Composer :

$ composer require magento/product-community-edition 2.1.7 –no-update
$ composer update

$ rm -rf var/di/ var/generation/ var/cache/ var/log/ var/page_cache/*

$ php bin/magento cache:clean
$ php bin/magento cache:flush

$ php bin/magento setup:upgrade
$ php bin/magento setup:di:compile
$ php bin/magento indexer:reindex

Steps are taken from the dev docs of Magento.

With those changes, we didn’t see any performance increase, we are still experiencing a high CPU usage on page loading which gives a very slow website.

Using the TOP command on linux, we can notice that the loading average is way too high and reaches 4 !

2nd TRY on improving loading time

Let’s quit the developer mode and play with cache management.

$ php bin/magento deploy:mode:set production

We can see a slight but not acceptable website loading time, the load average is still above 3 and even 4 during checkout for only 1 product !

So now it’s time to remove things from our installation, starting from unneeded modules.

We check our current Php modules by issuing the following command :

$ php -m

There is no xdebug and no other module which could cause such problem, anyway, we don’t see any problem using other websites running with other CMS such as Drupal, WordPress and Odoo so we need to look further.


Database maintenance

The sample data is taking more than 2500 products, we clean them up to only keep a few items.

Magento 2 modules

We use the backoffice to check for modules to deactivate :

Store => Configuration -> Advanced -> Advanced

After these changes, there is no better results.


What’s wrong with our install ? Let’s check on the server side.

Server requirements for Magento2

At beginning we have showed our current configuration using the following commands :

$ mysql -V

mysql Ver 14.14 Distrib 5.7.18, for Linux (x86_64) using EditLine wrapper

apache2 -v

Server version: Apache/2.4.25 (Debian)
Server built: 2017-01-25T22:59:26

php -v

PHP 7.0.20-1 (cli) (built: Jun 9 2017 08:04:20) ( NTS )

BEWARE here : you may have different versions on your server, the best way to check your Php version is by running the phpinfo() function on your website. for instance here Apache2 is using Php 5.6.

Our server is having the following :

  • 3GB memory
  • Double Core CPU


Other websites using WordPress, Odoo and Drupal are running smoothly. A Zend 3 website running real fast.

Speed audit of Magento 2 after all the changes above

Result from GT Metrics :

GT Metrics page performance

Do you see this fully loaded time ? That is awkward just to reach the homepage with only one product.


Nest step : minifying JS & CSS

Using the backoffice we now minify CSS and Javascript files and we combine them all.

You will have to clean up all caches and even run the update command for the database plus compiling again before reaching your website.

The result so far is disappointing, you might think, well let’s give up and switch to Prestashop or another CMS ! But we haven’t given our last word, now it’s time to start over by removing the whole Database and files.

If you need to install Magento2, just follow the steps at the website.

From your default user  to operate files changes :

$ composer create-project –repository-url= magento/project-community-edition html

Now get inside html (in our case) and issue :

$ find var vendor pub/static pub/media app/etc -type f -exec chmod u+w {} \;

$ find var vendor pub/static pub/media app/etc -type d -exec chmod u+w {} \;

$ chmod u+x bin/magento

Now get to the url :

Then follow the instructions.

Run the cron job as follow :

$ php bin/magento cron:run


$ php bin/magento indexer:reindex

With GTMetrix, we see a clear improvement in the speed of our site :

But this not sufficient.

But sincerely with caching and so on, right now we can browse the website with ease, that’s a pleasure.

Next we apply all the following tweaks :

  • minifying
  • combining…
  • Single mode site
  • Use Static URLs for Media Content
  • Allow Dynamic Media URLs in Products and Categories = No

Now adding the theme and homepage content :

Checking GT metrix :

8.8s in full loaded time, the rest is pretty similar.

First time page loading is long but once this is done, the browsing experience is fairly quick but adding products/content via the backoffice is still painful.


Final Step – Upgrading Php

Remember the system requirements from Magento dev docs ? The server should run with a minimum Php version of 5.6, how about tuning up and use the Php 7 engine ? As you may know there have been a lot progress in terms of performance for object manipulations with the last Php engine so let’s apply it to our Magento 2 installation.

Make sure you backup everything, then remove your older Php version and reinstall Apache2 over Php 7.

Once you have your Apache2 server running along with Php 7, you will notice a serious progress !

While php -v might give you the latest version, apache2 could use an older version, so check the version using phpinfo() from a page on your website.

Php 7 or 5, files permissions - Magento 2 install

Don’t install Sample data and uncheck modules you don’t need.

Make sure to follow the file permissions carefully later when you are dealing with your files using different users, it can definitely screws everything if not set properly, you might check the tutorial on files’ permissions.


After all these tests, the main configuration to consider is definitively on the server side by using the latest Php build. All other tweaks will help you optimize the website for better performances. One thing to remember also is that if you are running in production mode, follow the Magento2 guidelines and use the 2.0 version and not the 2.1. On the other hand, you can watch regularly for updates and if you like to dive into the coding of Magento2 then you are more than welcome to use the latest build.

I hope you’ve found this article useful and if so, please give us some credits by following us on social media.


2 responses to “New Magento 2 install is terribly slow”

  1. Alex says:

    Thanks for sharing this article, Its very helpful for Magento owners, When I was using Magento 1. I was using Cloudways full page cache extension, I am agree with point 4. Many people don’t understand the situation and ask developers to fix and they charge a lot, but getting best Hosting company and running FPC can resolve the issue.

  2. marvenniffi says:

    Thanks for sharing this awesome article about speeding up Magento, I was having an issue while installing but your post helped me a lot and also there’s another way I chose after working manually, speeding Magento is much easier and time saving with Cloudways managed Magento hosting, It might help your readers or beginners to install it without going that much technical.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Want more information?

Related links will be displayed within articles for you to pick up another good spot to get more details about software development, deployment & monitoring.

Stay tuned by following us on Youtube.

%d bloggers like this: