How can I use Git(Hub) to make changes on my local (Wamp) and push these changes to live?

Silverstripe 4.5
How can I use Git(Hub) to make changes on local (Wamp) and push changes to a live website (hosted on a hosting provider)?

I would like to use GitHub to track any changes I make to my website.

Steps done so far:

  1. I installed a fresh (latest) Silverstripe on an internet hosting and configured it
  2. Installed a theme (Watea) and made a few HTML and CSS changes, but realised I needed a way to track this changes.
  3. Website runs as expected on the live hosting. However, to be more diligent, I would like to make these changes locally (on my own computer) so I can test them, before pushing them back to Github and finally pushing changes to the live site.
  4. From the live website, I made a first commit to Git, configured Git remote and pushed the project into Github
  5. My .gitignore file reads as:
/silverstripe-cache/
/.env
/vendor/
/themes/simple/
/_resources/
/public/_resources/
  1. Using Github, I made a clone of the repository to my localserver. I am using WAMP where I have a few installed Silverstripe websites I use for training and learning.
  2. The repository is in the same folder as the other local websites I created for training
    wamp64/www/clonedrepository

The clone repository came without the Silverstripe core files, which is expected, so my question is, what’s the best way to replicate the live conditions (core files/modules/themes) without replacing anything on the cloned repository?

Is the best way to migrate (copy and paste) the folders present in the .gitignore file, from the live FTP to my locaserver cloned repository folder?

Many thanks if anyone can help
Caio

You might want to have a look at something like deployer (https://deployer.org/) or Deploy HQ (https://www.deployhq.com/)

These will allow you to do automated deployments based on your repository. You’d do all your development locally, only committing your own files and things like your composer.lock file to the repo. The deployment scripts will then pull from your repo (from whatever branch / commit you want), run an automated build and upload the changed files the the target. If you get set up right, you never actually need to access the hosting filesystem directly… since the deployment system manages it all for you (even things like roll-backs, etc.)

Hope that helps!

Hi Tim,

Thank you for your answer. The tools you provided indeed help in terms of giving automated options, I have already signed up for one of them and it looks a more smooth deployment process, thank you.

However, I am still struggling on how to transform my cloned repository locally in a website (i.e. add the Silverstripe core files back, framework, etc).

I have read on other forums to run ‘composer install’ or ‘composer update’, but I am having no lucky with those, so I am still digging the tutorials and forums.

On this old thread, they suggest to run composer install, but that’s 4 years old. Is it still the case for 2020 to run composer install?:

Many thanks
Caio

Hi.

Composer is very much the way to manage your product.

If you have a composer.lock file in your local copy, running composer install should get all the external dependencies (core files, add-ons, etc.)

You’ll manage your local installation using composer… so if (for example) you want to add a new module, you’d use the composer require command to add it to your project. You’d refresh the packages with composer update and so-forth.
When you run these commands, composer will update your composer.json and composer.lock files.

If you commit your composer.lock file to your repo, as part of the deployment process you’d automatically run something like composer install --no-dev - this would make sure you have the same versions / combination of packages in your deployment target.

I hope that makes sense!

1 Like

Hi,

I’ve got a similar setup and wondering if someone can please help me also…

I have the following:

  • local dev environment using MAMP, installation with composer all working fine
  • GitHub repository which I can push changes to from local machine
  • CPanel repository on web host which pulls changes from GitHub repo
    This all seems to be working fine, ie. I can make a change on my local machine, push to GitHub, pull changes onto web host via CPanel Git VersionControl

In order to deploy, I need to set up a .cpanel.yml file as described in

I have tested this with their example using a single file or directory and also working fine, ie. .cpanel.yml is checked into repo and once pulled onto web host via CPanel allows me to manually deploy.

So, I’m just wondering which commands should I use in the .cpanel.yml file? Is the following sufficient, or is there more that I should be adding? In particular, how do I ensure that old project files (ie. files no longer on repo) get removed? I really want to be able to sync changes with repo.

---
deployment:
  tasks:
    - export DEPLOYPATH=/home/username/testwebsite/
    - /bin/cp -R * $DEPLOYPATH
    - composer install --no-dev -o

Note I haven’t yet tested whether composer install will work in this context. If anyone has any experience with using CPanel Git deployment, I’d be interested to know what you do :slight_smile: