Magento 2 running so slow on localhost development

The question:

I recently started developing on magento2 new extensions or customizations, and my first impression was a nightmare. I have to wait about 20-30s for every change I make? really?

I’m talking about development mode, I know that in production with cache enabled and other things the website can be smooth. But when I’m working with an extension or layout problem I need to be removing static files, clearing cache, etc.

My question is, how you all M2 developers work? because I don’t believe you have to wait 20s-30s for refreshing the page…

My environment: My pc is “good” i5 with 8gb RAM. I need to work with Windows so I use vagrant:

  • Use of all 4 cores CPU
  • Use 5120MB of RAM
  • Ubuntu/trusty64 – Ubuntu 14.04
  • PHP Version
  • MariaDB – 10.1.18-MariaDB-1~trusty
  • Magento 2.1.2 is installed only with sampledata (no more modules are installed)
  • (Ask me if you wanna know sth more)

What is happenning exactly?
Usually M2 responds okay, slow but okay, about 5-10s to load the pages, but sometimes (more usually than sometimes) it just stucks forever! sometimes is the first page and sometimes are the css,js,html files but always the problem is with TTFB.

I saw a problem going to setup wizard too… with angular.js these files lasts forever…

These 2 pictures are about navigating inside setup wizard.

Magento 2 running so slow on localhost development

Then another one navigating on frontend catalog:

What am I asking exactly?
Is this normal? you guys work with this timing? I commented this with some colleagues and we just don’t believe, I have to be working like this? I sometimes despair of waiting all the time watching the screen…

If someone asks me for show him a test, like creating a new product or something like that he just freaks out… Creating a new order, filling the fields and every field executes a js that lasts for 5-6s…

I don’t know but I feel so bad developing with this stuff…

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

I tried everything and the only thing it works is the virtual machine that provides bitnami.

Seriously, I don’t know what has this vm, but goes really fast. I tried creating my VM using a fresh installation of Ubuntu, CentOS, etc. But no works so fine like this VM.

Method 2

disable CSS/JS merging and minifying:

Stores > Configuration > CSS Settings (Javascript Settings) > Merge CSS (Merge JS) > NO

Stores > Configuration > CSS Settings (Javascript Settings) > Minify CSS (Minify JS) > NO

Also see this guide on how to improve Magento 2 performance.

Method 3

I found that developer mode disable everything – which was overkill. There’s certain aspects I do wish to cache, such as translation. Thankfully in env.php you can still set which caches to use specifically:

'cache_types' => 
      array (
        'config' => 1,
        'layout' => 0,
        'block_html' => 0,
        'collections' => 1,
        'reflection' => 1,
        'db_ddl' => 0,
        'eav' => 1,
        'customer_notification' => 1,
        'target_rule' => 1,
        'full_page' => 0,
        'config_integration' => 1,
        'config_integration_api' => 1,
        'translate' => 1,
        'config_webservice' => 1,
        'compiled_config' => 1,

This was the above that I chose to cache whilst developing on the Checkout, as this was heavily front-end. I chose to not cache Layout; Blocks and Full page to see my changes.

Method 4

Suggestions from Magento posted after this question was answered. Reading other answers I think this information could be a helpful addition

Optimal Configuration

The following is a list of optimizations you can make on your local development machine

  • Magento recommends installing and using the latest supported version
    of PHP 7 to increase performance.
  • Replace your MySQL database with
  • Make sure you install and enable PHP OPcache.
  • Xdebug is off by default. Enable this feature only when you need it because it requires a lot of memory and degrades performance. The xdebug.max_nesting_level configuration needs to be set to 200 or greater for Magento. You can increase the memory available to PHP to get an increase in performance with Xdebug on.
  • If you need sample data, you can install it using composer or by cloning repositories.
  • To speed up front end development, turn off merging of CSS and JavaScript.
  • Make sure caching is turned on (this is the default behavior). Generally, only page cache and block cache should be turned off for development and turned back on when testing.
  • Opcache timestamp validation should always be on for development. Development is impossible with opcache on and revalidation off because any PHP modification would require a cache reset.

Method 5

Turn on your cache.

Go to <your magento 2 directory>/bin and run this command magento cache:enable.

Clean the cache when you edit the frontend to see what you’ve edited.

Go to <your magento 2 directory>/bin and run this command magento cache:clean.

My Reference

I’m new to magento 2 too. I hope someone has a way to make magento 2 fast even when the cache is disabled.

Method 6

My Setup on Ubuntu 16.10 for frontend development for LESS edits:

  1. Set Developer mode:

    php bin/magento deploy:mode:set developer

  2. Enable all caches:

    php bin/magento c:enable

  3. Fronted Development Workflow set to Server side compilation

  4. After any changes in less files run

    grunt clean

(Last time I menage to start – grunt watch with live browsing and its great)

Method 7

Just want’s to share my personal experience, The solution i came up was to install Xampp with php version 7.0 as Magento is not fully compitable with higher version of Php. I tried Bitnami Image listed in answer but doesn’t worked as i was expecting
Xampp 7.0.23 Download Link

Method 8

Increasing PHP memory_limit in php.ini file will make good difference. However it won’t make it very very smooth(Although it will save time).

The default value is 512M. On my local machine I set this at “-1″(unlimited) and it gives better loading time.

The recommended value is memory_limit=2G mentioned here.

Magento is heavy and needs high performance hardware like SSD to be smooth 🙁

Method 9

If your having problems setting up on a Vagrant box, it will almost certainly be how your folders are shared. They should be shared over NFS.

After messing around with lots of different boxes, I realised that although I had set NFS in the config, it was not actually working and the standard VirtualBox sharing system was taking over.

I went back to basics and set up a simple LEMP box and installed this plugin:

Confirmed NFS was working and all was well.

Method 10

Things that can make your Magento 2 setup fast on your local server or in general on any server enviroment.

  1. Minify JS and CSS
  2. Use a caching application like Redis or Memcached.
  3. Enable all the cache like block_html, layout, page_cache etc
    provided by Magento 2.
  4. Merge CSS and JS
  5. Enable flat products and categories.

Now when on the development enviroment flush only the needed cache instead of flushing the whole cache to prevent the whole rebuild of cache.

Method 11

The main reason why magento2 is slow in developer mode is related to thousand of static and compiled files generated on the fly.

There are 3 solutions for this:

  • Mount whole directory with NFS (SSD is still mandatory).

  • Mount only app directory (whoever your hardware it will work fine) but you lose access to /vendor directory on your host machine.

  • Mount whole project with rsync and exclude directories where files are generated (pub/static, generated/code etc…).

I made that work, give it a try:

Method 12

One thing that can actually cause this is running composer update. It’s a documented bug that can reset the cache settings in env.php.

Look for the following settings and make sure they’re all set to 1:

    'cache_types' => [
        'config' => 1,
        'layout' => 1,
        'block_html' => 1,
        'collections' => 1,
        'reflection' => 1,
        'db_ddl' => 1,
        'eav' => 1,
        'customer_notification' => 1,
        'config_integration' => 1,
        'config_integration_api' => 1,
        'target_rule' => 1,
        'full_page' => 1,
        'config_webservice' => 1,
        'translate' => 1,
        'compiled_config' => 1

Method 13

There are few quick steps by which you can increase the website speed please click here to see the answer

Method 14

I am using mac I tried different tools to install magento (xampp,Mamp,vagrant etc) Here i am listing it by the fastest at top.
I am discussing about magento development on local environment not running the live website on server.

  1. Xampp for mac. ( The intl library is missing you have to follow the steps to install it) It is running magento very fast even after enabeling xdebug,(you have to install xdebug 1.X)
  2. Vagrant. Vagrant is a full virtual box environment there are full boxes which contains all the minimum software packages running in a virtual machine you can access it by ip or by a subdomain.
  3. MAMP Pro. Mamp pro is using fastCGI script and its beauty is that you can switch php versions very easily. It has very good interface but when it comes to running magento the performance is very poor.
  4. Bitnami Magento. Bitnami is one click install virtual machine, very fast to install(once click) but unfortunately it is running very very slow.

Method 15

Go to System > Tools > Cache Management in admin panel and scroll to bottom.
Then Flush JavaScript/CSS cache and Static Files Cache using the available buttons.
Finally click on main “Flush Magento Cache” button.

Worked for me in Magento 2.4.3

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment