7

I've been trying to find the best way on how to develop a Magento 2 webshop locally. So far, I had no luck: lots of JS, CSS and 404 errors (on which I tried lots of fixes which only partly solved my problems).

My question is:

What is the best (step by step) way to develop a Magento 2 webshop locally (and if possible, 100% error free after installation)?

The Magento 2 dev docs don't really provide a comprehensive guide on how to do this.

I prefer using Laragon over XAMPP: it works way better and has lots of customization options including localhost URL's like webshop.dev instead of localhost/webshop.

FYI: I currently use Windows at home, but in the future I am planning to buy a Mac, but for now I'd like to know how I can do this the best way possible on a Windows machine (or a universal way).

5

Your question is quite broad, so hard to give an exact answer without me spending ages on a reply - but using anything like XAMPP is a bad idea from the start (I know from experience) especially with Magento.

My preferred way is to use a virtual machine running Linux - in my case Ubuntu 16.04LTS server edition (as it's the same as my production server)

Virtualbox is free - https://www.virtualbox.org/wiki/Downloads

On this virtualbox, I install nginx, php7.0-fpm etc. (as per the Magento 2 devdocs) and configure in the same manner as my production/staging servers. I'd then make a host entry in Windows that points my 'dev domain' to the virtualbox IP.

I then use n98-magerun to export a 'developer' version of my production database, a must to avoid customer data being present on your local machine (GDPR, best practices)

Mount a folder from your virtualbox into windows, you can then open this folder in an editor such as atom to work on your project.

If you work this way, then you'll have no issues when you move to Mac also, as you can work on Mac, Linux or Windows. Your virtual machine image can always be the same, and as your production and staging servers with no nasty surprises when deploying. I recommend git for deployment and general version control also.

Larger companies also use things like docker, this lets you spin up a magento instance in its own container from an image - more portable than virtualbox, but virtualbox will fit your need just fine in my opinion.

Summary

  • Use same OS as your production/staging servers.
  • Use same PHP versions as production/staging.
  • Ensure to cleanse data from production db
  • Avoid one click install solutions, you'll learn way more about Magento by doing your own deployments.

If you have any questions, let me know and I will try to elaborate in my answer :)

  • I will try it out ! – Condor Jun 28 '18 at 6:42
  • 1
    Update, in 2019 I'm using docker for development :) – Ricky Odin Matthews Nov 13 '19 at 12:00
  • If you have no do idea about docker. My recommandation is use lando with the following receipt. – chmoelders Dec 13 '19 at 9:10
1

If you want a ready to use environment take a look to https://github.com/paliarush/magento2-vagrant-for-developers

  • Will try it out! – Condor Jun 28 '18 at 6:42
1

I just recently wrote a tutorial on this. With Docker, you can mimic just about any production environment. It’s modular and there is lots of support for it. Docker / Magento 2

I should note that at my full time job as a Magento Tech Lead I am constantly configuring a variety of Docker environments to match production environments. You can add Redis, RabbitMQ, Elasticsearch and so much more. If I was slightly nerdier I’d get the whale tattoo just beneath the Magento tattoo.

  • Hmm this sounds very interesting. Will try it out on the Mac I use on my intern (because it requires Windows 10 Pro, I have Windows 10 Home...). I'll come back to you! – Condor Jun 28 '18 at 6:42
  • I can't get pass the create project part at the beginning. It throws an error saying it requires mcrypt but since I have php 7.1.7 installed, mcrypt has become deprecated. I tried to downgrade to php 7.0 but no luck yet – Condor Jun 28 '18 at 9:37
  • 1
    When running composer create or composer update, try adding the —ignore-platform-reqs flag. – Shawn Abramson Jun 28 '18 at 12:03
  • 1
    That flag tells composer not to look at the php extensions installed on your host system bc it’s the php inside of docker that’s going to power the site – Shawn Abramson Jun 28 '18 at 12:05
0

The only problem with Laragon (Windows) is that you need to use the Copy method over Symlink and by doing this everything fails first.

app/etc/di.xml

<item name="view_preprocessed" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Copy</item>

Another fix that you need is the "backslash" -fix

#/vendor/magento/framework/View/Element/Template/File/Validator.php

From this file line: 114

$realPath = $this->fileDriver->getRealPath($path);

to

$realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path));

After a couple of refreshes every file is properly copied and available before timeout.

I really can't think any reason why you can not develop in Windows with Laragon because all you need to modify is inside /app/ -folder. Any modifications inside /vendor/ -folder is done via composer.

...and i have to say that Laragon is still the fastest and easiest thing that i've come across. The GUI is unbelievable good. Magento installs in no time and you have all the tools that you ever going to need available by no time without the need to open hardly any editor.

0

Running the Bitnami Magento 2 image in Oracle Virtual Box is a lot quicker than Xampp on Windows in my experience

0

This awesome and well maintained package offers a one command installer for any version of Magento you need!

https://github.com/markshust/docker-magento

Once you install it, then create your code in /app/code/vendorname/modulename

You will be able to develop/test from there.

But then you should also create your module into a composer package so that anyone (you or anyone else) can install any version of your module on any server where it is needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.