Creating a Magento 2 Local Development Environment from an Existing Website

Creating a local environment can be frustrating when you’re new to Magento 2. I get asked a lot by developer friends how to do this so I thought this post might be useful.

Since most people reading this post already know how to do most of these tasks, I’m going to list the steps without going into detail.

  1. Checkout your site’s repository on a local folder (if your site isn’t setup to use git, do that first).
  2. If you used composer to install your site originally or have ignored your vendor folder in your repository, you’ll need to run composer install && composer update.
  3. Backup your site’s database to your local machine.
  4. Point Apache or Nginx to the local folder you checked out your repository.
  5. Create a new database and import the database you backed up to your local machine.
  6. In the database’s core_config_table change the base URLs (secure and unsecure) to your local domain and clear the cookie domain. If you’re using a CDN you will need to change the related entries for JS/CSS/Media files.
  7. Navigate to http://local.domain/setup.
  8. Complete the Magento 2 setup wizard. Don’t worry, all your files and database info will stay the same. This is just a simpler way of creating an env.php file for your local environment.
  9. For good measure, run php bin/magento setup:upgrade just in case composer updated any extensions in the second step.
  10. If your repository isn’t ignoring caching folders you’ll need to clear those first to make sure nothing is pointed to the wrong domain.

That’s it! You should now have a local environment that’s ready to develop on.