Question

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).

Was it helpful?

Solution

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 :)

OTHER TIPS

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

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.

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.

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top