98

With Magento 1 I used a deploy tool that pulled in the GIT repo, ran commands like modman deploy-all and made sure the var directory was writable. For the .gitignore I used this one which worked pretty well.

But what about Magento 2?

What gitignore works best, how do you deploy your project and what command should one run pre- and post deploy. Looking forward to hearing some insights from the community.

Question will stay open for quite some time

Sander Mangel
  • 37,528
  • 5
  • 80
  • 148
  • Good question @sander Mangel – Amit Bera Dec 13 '15 at 18:38
  • 1
    By definition there can be no canonical answer to this, so it is likely too broad and also a poor fit for the Q&A nature of the site. Should likely be meta. But you already know this. That said, I'll allow it until the bounty expires. – philwinkle Dec 16 '15 at 16:59
  • @philwinkle it might be broad but apparently not too broad since already 3 answers were given. As discussed here: http://meta.magento.stackexchange.com/questions/745/meta-website-is-starting-to-lose-its-purpose Meta is to be used for questions about MageSE, not random posts / questions If you want to delete it I can't stop you but it seems a lot of people are interested in the question and in my opinion it's a valid one, all be it not too specific. – Sander Mangel Dec 20 '15 at 10:51
  • Two things: First, Sander is correct about Meta - it should only be used for questions about the SE platform as it relates to Magento SE (NB: we've maybe not policed Meta well enough to reinforce this rule). Second, "a lot of people [being] interested in" a question has nothing to do with whether a question can be answered canonically or not (and therefore with a question's suitability to the StackExchange format). It's frustrating for sure (I've come up against this myself). I'm inclined to see where this Q/A thread goes. Perhaps an A can be stated well enough to be exclusively "right"... – benmarks Dec 21 '15 at 22:12
  • @benmarks in that case I've picked the wrong reason or subject for the bounty, my motivation behind it was to reward whoever took the time to write down a full answer for this. If this thread does not belong on here I'll copy it and post it somewhere online crediting the authors since I feel it still has value. Please notify me if before deleting – Sander Mangel Dec 22 '15 at 07:27
  • It's okay, I think this thing is going to stay here; Marius, Phil and I have discussed. It's the most contention I have with the SE platform, that a valuable Q/A thread may not be allowed (or may be closed) because there's no "one true answer" (ref "Why Layout XML?" on SO) . Actually, I just re-read "What types of questions should I avoid asking?", and based on that I think there is ZERO problem with this thread staying here. – benmarks Dec 22 '15 at 17:46
  • @benmarks thanks for the reply Ben, glad this falls within the rules of MageSE :) – Sander Mangel Dec 22 '15 at 20:22
  • Seems quite fast deployment is described here https://www.yireo.com/tutorials/magento/magento-2/1839-proper-magento-2-deployment – Gediminas Oct 31 '17 at 10:21
  • @benmarks thank you. I really appreciate when mods take a moment to keep the excellent information in SE sites. I've experienced too many diamond power mongers who give me the impression of closing great Q/As because they enjoy it -- and maybe resent that people like me can Google a Q/A and get answers to my problems from these "illegal" posts. – Krista K Dec 28 '17 at 16:21

5 Answers5

62

Steps below describe how to set up environment for custom module development, not for production.

Project initialization

  1. Add repo.magento.com credentials and github access token to auth.json in composer home directory

  2. Create project using the following command:

    composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition .

  3. Take this .gitignore and put into your project root. Almost all core files/directories are already added to the root .gitignore, but it is better to add the following 2 as well /update and /phpserver (just add these 2 lines to .gitignore)

  4. Initialize new git repository in the project root

  5. Add all untracked files to git and commit them

  6. Start development of your modules as usual (put them under app/code/VendorName/ModuleName), now you will have only your custom code in your git repository

Magento installation

  1. Make sure all filesystem permissions are set as outlined in the official guide

  2. Install Magento using command line, e.g.:

    ${project_root}/bin/magento setup:install \ --db-host=localhost \ --db-name=magento \ --db-user=root \ --backend-frontname=admin \ --base-url=http://base.url.goes.here/ \ --language=en_US \ --timezone=America/Chicago \ --currency=USD \ --admin-lastname=Admin \ --admin-firstname=Admin \ --admin-email=admin@example.com \ --admin-user=admin \ --admin-password=123123q \ --cleanup-database \ --use-rewrites=1

  3. Enable indexers cron job, e.g. on Ubuntu:

    echo "* * * * * php ${project_root}/bin/magento cron:run &" | crontab -u www-data -

  4. Magento will run in default mode and all missing content will be auto-generated upon first request. So no need to run compiler or static content deploy

  5. [optional] If using PHP Storm, run the following command in to enable XSD support:

    bin/magento dev:urn-catalog:generate .idea/misc.xml

MClaudio
  • 36
  • 4
Alex Paliarush
  • 13,751
  • 5
  • 51
  • 55
  • Hi Alex. Project initialization step 3 - could you expand it a bit? Did you find you had to manually copy that subdirectory to the root? (I am wondering if there is something not working correctly - I was not expecting that step.) – Alan Kent Dec 14 '15 at 04:00
  • @AlanKent currently you get all Magento-related files downloaded to vendor, including magento2-base, which is just a skeleton for a new project. Not sure why this step is not configured to be done automatically by composer, will try to find out. Regarding .gitignore copying from another repo, it is already being discussed, how to eliminate/simplify this step. – Alex Paliarush Dec 14 '15 at 06:51
  • Step 3 is not required. The marshaling of the files/folders is done during step 2. – Maddy Dec 14 '15 at 21:11
  • Thanks @Maddy. @AlanKent, copying magento2-base to the root is not necessary anymore (just verified), seems to be fixed recently. Removed this step from the answer. – Alex Paliarush Dec 15 '15 at 10:24
  • i put all of my code on the repo, already unstalled and everything, when i pull from that repo and just change the settings fort the admin pangel and the db credentials, will everything work correctly ? 2) since i forgot to exclude var/ and pub/ folder during the push, can i delete them completely, so they can delete on the remote repo, will they regenerate back ? Thanks.
  • – Lachezar Raychev Feb 19 '16 at 11:03
  • i ment already "*installed and everything" – Lachezar Raychev Feb 19 '16 at 11:25
  • @AlexPaliarush how to develop multiple magento modules(different git reps) in single magento instance – Aswanth Apr 01 '16 at 12:28
  • Why in that .gitignore do they do */* and /pub. What if you want files tracked in there? You have to git add -f – tread Nov 30 '16 at 15:12