2
  • I installed Magento 2 locally using Composer
  • I use Git to track my code
  • I need to deploy my local Magento 2 site to a staging server (shared hosting)

1) For what do I need Composer anyway on Staging server? Is this to get the vendors once only on the Staging server? Why shouldn't I do this via ssh on the server with php composer.phar install ?

2) I need Composer on the Staging server only 1 time for the installation isn't it? The site isn't getting 100 visitors per hour and are symlinks working on shared hosting?

2 Answers 2

2

Why shouldn't I do this via ssh on the server with php composer.phar install ?

That is exactly what you should do.

Composer will install your dependencies for you at the specific version you ask for. This is why it creates a composer.lock file which contains a record of the versions of each dependency that it has installed.

For what do I need Composer anyway on Staging server?

Standard practice is to install or update locally, test everything, commit in the composer.lock file as well as composer.json and your local modules, then push that. You should not need to commit in any of the dependencies installed with composer.

When you deploy to staging or production you just run the install command which reads the lock file and installs those specific versions of your dependencies for you.

I need Composer on the Staging server only 1 time for the installation isn't it?

You will need it to install the code base and to update it whenever you deploy new changes.

7
  • I installed Magento 2 local using Composer > I created my Custom theme > I created this .gitignore file. 1) Do I have to add /update to the .gitignore? 2) With the correct .gitignore I push my code to the Beanstalk remote repo. From this repo I pull the code to the Staging server. What is next step? How do I get all my Magento 2 code on the server? Do I have to do composer install or composer.phar install?
    – meez
    Jun 23, 2016 at 8:06
  • Git ignore should exclude anything that is installed with composer, particularly the vendor folder. Everything else including gitignore and composer json and lock should be committed and moved to your server, then you just run composer install on the server to pull all the dependencies in alongside your own code
    – scrowler
    Jun 23, 2016 at 8:15
  • Ok thanks. So I commit the whole /update folder? In this article they advised me to use Deploybot? But I don't understand what it exactly does. Do I really need this or can I do it without it (like you suggest)? I just want to track my code by Git and install a copy on the Staging server and push changes from local to the Staging server (through my remote repo). What is different in your method and using Deploybot to deploy to Staging server?
    – meez
    Jun 23, 2016 at 8:42
  • I've never heard of deploybot- you could probably ask that as a different question
    – scrowler
    Jun 23, 2016 at 9:02
  • Because they talking about 'avoiding running composer install in production' ..? But my composer install will be on the Staging server so I can follow your method isn't it? But then, when Staging server is tested and working fine, how do I get this copy on Production server?
    – meez
    Jun 23, 2016 at 9:11
1

You do not need composer on the staging server. Composer used only for getting needed dependencies. So you can install all dependencies locally and move vendor dir to server

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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