3

I have my local git repo on my machine with composer and all of that installed. I then have a remote server for hosting my website where I have a bare repo that has a post-receive hook that does a checkout to the var/www/ file (GIT_WORK_TREE=/var/www/ git checkout -f).

Now, when I was using codeigniter or other non-composer based websites, it was as simple as committing changes and pushing it to the server. As this is my first experience with composer, I'm having a few headaches.

How do I go about setting up laravel 4 on the remote server so I can push changes to it? Do I need to install composer? If I update my composer.json required, do I need to do "composer dump-autoload" on the server as well or "composer update"? Basically, is there a quick rundown or tutorial on how to manage the workflow?

I'd insanely love it if I had the simple "git commit && push" and it did everything for me, including all the composer stuff, on the server.

Thanks!

3
  • Check out the default .gitignore. You will need composer on your remote server. I run composer update on my local and remote installs after updating composer.json. Commented Nov 17, 2013 at 22:10
  • I saw that it doesn't include vendor/. Why is that? Shouldn't I be able to remove it from my .gitignore and update the vendors manually? Commented Nov 17, 2013 at 22:11
  • Sorry, mine does include vendor/. I would think that you would want to only update vendor manually. Commented Nov 18, 2013 at 3:33

1 Answer 1

3

How you can accomplish this depends on a bit on your hosting. You need a certain level of access to auto-deploy from Git. Some companies, such as Heroku and FortRabbit, have this functionality built in. If your hosting doesn't, here's a few notes on how you might accomplish that:

1. Remove composer.lock from .gitignore

This is in the .gitignore file as the creators of Laravel don't want it in the repository. You should have it in your version control, however, as it's what your production server should read when updating dependencies on your production server.

When you update your server from git, you should have the composer.lock file updated in there as well.

2. Set up auto-deploy from your Git repo.

The steps for this are usually:

  1. Setup a Github web hooks (Yep, I'm assuming Github. You'll need a way to send a request to your server to let it know that your repository was updated)
  2. Have your server listen for web hook
  3. Have your server respond to web hook by pulling the latest from git

These are outlined in detail on this article about deploying from github using webhooks and nodejs

3. Post-deploy scripts

After you get the latest code from Github, you may have updated dependencies as defined in your composer.json file (and set in your composer.lock file). Here's a little explanation on why you use composer.lock in production in conjunction with the composer install command. (composer update is good for development, composer install for production).

You can run (probably from the same script which tells git to pull the latest in production) to run composer install after the latest changes from Git are pulled in.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I'm going to investigate your answer a little bit and then I'll mark as correct!

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.