install from zip, upgrade with git?

install from zip, upgrade with git?

by Lucien Stals -
Number of replies: 9

I have a moodle installation that was done from the downloaded zip file.

I'd like to upgrade it via the CLI, but the instructions here (https://docs.moodle.org/27/en/Administration_via_command_line) say I need to do a pull from GIT to get the latest files before running the upgrade command.

When I run the "git pull" command, I'm informed that "fatal: Not a git repository (or any of the parent directories): .git". and in fact I see no .git folder in my site.

How can I convert my zip installed Moodle instance to one that can talk to the git repo?


Average of ratings: -
In reply to Lucien Stals

Re: install from zip, upgrade with git?

by Ken Task -
Picture of Particularly helpful Moodlers

Error is correct ... git pull will not find the hidden .git directory cause it isn't there.

First things first ... ** BEFORE DOING ANY BELOW ... FULL SITE BACKUP ***
That means a tar ball of the code directory, a tar ball of the data directory,
and an SQL dump.   Once you have that proceed.

2 ways - here's one ...

Adjust locations to your system as you've not said specifically what you have.
Below is off the top of my head and for CentOS/RHEL/Fedora flavored Linuxes:

Moodle code is at /var/www/html/   You know the version.
fgrep '$release' version.php will show.
For the sake of example, let's say it shows 2.7.x

Note the ownerships/permissions of the html directory - write it down.

cd /var/www/

git clone git://git.moodle.org/moodle.git htmlgit

That will acquire the most recent Moodle code to a directory: htmlgit

cd htmlgit
git branch -a

will show that git is set to master.  We want same version you have.

git branch --track MOODLE_27_STABLE origin/MOODLE_27_STABLE
git checkout MOODLE_27_STABLE

Check version: fgrep '$release' version.php

This might result in a minor upgrade of your current code.  Not a problem.
It's really recommended.

Tricky part ...
*copy* the add-ons you have in html into same locations in htmlgit

From /var/www/html/ (existing code of Moodle)
Let's say you have an add-on block called 'simpleclock'.

cd blocks
cp -rp simpleclock /var/www/htmlgit/blocks/

This copies the folder from functioning site (not git) to the git enabled directory.

Do the same for any mods and themes.

** important ... copy the config.php file from html to htmlgit
from /var/www/html/
cp -p config.php /var/www/htmlgit/

If you think you done, we then move the html directory to a back ...
from /var/www/

mv html htmlback

then move the htmlgit directory into place
mv htmlgit html

Check ownerships/permissions on html.
Check ownerships/permissions on the files/folders contain in html

Ok, change into html, then run:

git pull
php admin/cli/upgrade.php --non-interactive

Check ownerships/permissions on all files ... remember you exeuted commaands as root user and therefore the files added by git, etc. have root:root.

Could do a chown apache:apache * -R
And then go back and harden permissions after you get it up and running.

Try your site with a browser now.

Read over this ... then if your curious, can also share the other way.

'spirit of sharing', Ken


Average of ratings: Useful (2)
In reply to Ken Task

Re: install from zip, upgrade with git?

by Lucien Stals -

Thanks Ken.

That sounds like exactly what I need smile

FYI, we are running on Amazon (AWS). I think it's RHEL or CentOS, or similar. (Not sure exactly).

I'm testing this on a  development instance, so if I kill it, it's not so bad, but yes, I'll do backups first.

Out of curiosity, in your instructions you mv the old copy of the site and then mv the new one into where the old one was. I've previously seen sys admins use symlinks for this instead. For example,  /var/www/html/moodle would be a symlink in  /var/www/html/moodle27. Then when upgrading to 2.8, they'd just change the symlink so it pointed to  /var/www/html/moodle28. 

Not being a sys admin myself (but it appears I'm rapidly falling into that role with Moodle), is there any real advantage/disadvantage to the two approaches?

Anyway, I'll try your suggestions and let you know how it goes.

Cheers,

Lucien.

In reply to Lucien Stals

Re: install from zip, upgrade with git?

by Ken Task -
Picture of Particularly helpful Moodlers
Didn't address the question concerning symlinks ...

Yes, that's one way.   symlinks, however, have some considerations to take into account.  Apache will be set to follow symlinks.  So if using something apache and one removes/deletes, apache will follow those symlinks.

If you have total access to the apache config file one could also point document root to the new moodle code directory.

To extend either a little ... there is also virtual apaches ... this would allow one to have a dev site on the same server (thus using the same environment - minus https) that could be the next highest version of Moodle or something you are working on integrating that is accessible only by those who know of it's existence using the 'hostfile' trick.

'spirit of sharing', Ken

In reply to Lucien Stals

Re: install from zip, upgrade with git?

by Ken Task -
Picture of Particularly helpful Moodlers

So as not to confuse, here's the other way ...

*** Same for backing up
*** Same example locations, etc..

cd /var/www
git clone git://git.moodle.org/moodle.git htmlgit
cd htmlgit
git branch --track MOODLE_27_STABLE origin/MOODLE_27_STABLE
git checkout MOODLE_27_STABLE
cp -rp .git ../html/  (this copies recursively the hidden .git directory into the current code directory)
cd html
ls -l .git

Now try:

git pull - this might pull down files and result in a minor upgrade

php admin/cli/upgrade.php --non-interactive

change ownerships
chown apache:apache * -R

Try the browser now.

Go to Notifications

Check on any updates to plugins.  Forgot to mention that in previous response.

** NOTE:  not only should one know how to do a full site backup, but one should also know how to restore that full site backup should the attempts to get code under git fail for some reason.

NOTE: should you get lost in commands, capture your history to a file:

history > commands.txt

commands.txt ... towards the bottom will have all the commands you issued in the sequence you issued them .

I usually make a little text document and keep it on my laptop that contains the commands - a commands cheat sheet so to speak.   I edit for version numbers, etc.  Then all I have to do is copy and paste between my cheat sheet and the terminal screen.

'spirit of sharing', Ken


Average of ratings: Useful (2)
In reply to Ken Task

Re: install from zip, upgrade with git?

by Lucien Stals -

Thanks Ken.

This worked perfectly :D

What about upgrading between Moodle versions? For example, going from 2.7 to 2.8?

Is it as simple as doing the following?

git branch --track MOODLE_28_STABLE origin/MOODLE_28_STABLE
git checkout MOODLE_28_STABLE

In reply to Lucien Stals

Re: install from zip, upgrade with git?

by Lucien Stals -

I'll answer this one myself ;)

FYI, in this case I was testing the process on an existing test 2.6 install, going to 2.7. Once I get my head around this process I'll have to take our prod site from 2.6.11 to whatever the stable version of 2.8 is.

After finding this post... https://moodle.org/mod/forum/discuss.php?d=274729

I ran the following commands...

 git branch -a
 sudo git checkout -b MOODLE_27_STABLE origin/MOODLE_27_STABLE
 sudo php ./admin/cli/upgrade.php

This appears to have worked. At least the site is now Moodle 2.7.8.  smile

But I've lost all my themes and plugins. Is this normal when upgrading between versions? The plugins survived the 2.6.6 to 2.6.11 upgrade.

I suppose I can copy them back, but is there something in the upgrade process I skipped that will preserve the current themes and plugins when upgrading from 2.6 to 2.7?

In reply to Lucien Stals

Re: install from zip, upgrade with git?

by Ken Task -
Picture of Particularly helpful Moodlers

See you are progressing all by yourself now.   Good.   Just a word of caution ... good idea to read the release notes on each version before gitting the code.   Why?  For the questions you've asked indicate changes have caught you by surprise. 

One of the major changes from 2.6.x to 2.7.x IS themes.   All the 2.6.x themes not compat with 2.7.x and in 2.7.x you only have two (to start with).   When you go to notifications now, check for updates, if you see a link that says something about 'some of your plugins' ... then follow it.   Those plugins need updating to a version that is compat with the core version of Moodle.   You will see there that the old themes will be deleted from the DB.   That's as it should be.   To acquire more themes, visit Moodle's https://moodle.org/plugins/.

Also remember you need to pay attention to the version numbers.   2.4 add-ons may not be compatible with your current version.  The plugins area of Moodle.org displays version numbers ... pay attention to them and don't try to bludgeon a mod/block/theme tagged as being compat with say 2.4 into your 2.7, 2.8, or something higher.

One of the nice things ... you can update plugins via the Moodle UI now.

And another note: unless you acquired the plugins via git, when one does a git pull, it will update only the core files of Moodle ... not the addons.   For that, go to Notifications, click check update, and use the Moodle UI to update plugins.

And, may not make a difference, but one also might loose a tool or two due to changes in code.   In 2.6.x you had an Assignments Upgrade Helper in the Site Admin menu.  In 2.7 and onwards, you won't.   That helper for converting old assignments mod to new assign mod.

Again ... good idea to read the release notes for the version you are heading towards:

https://docs.moodle.org/dev/Releases#Moodle_2.7

https://docs.moodle.org/dev/Moodle_2.7.8_release_notes

And a comment/personal preference:   I normally *don't* go after upgrading to anything .0 on a production server.  .0 to me is like being an 'omicron tester'.  I'd prefer to be close to the leading edge but not on the bleeding edge with a production box. ;)

'spirit of sharing', Ken



Average of ratings: Useful (1)
In reply to Ken Task

Re: install from zip, upgrade with git?

by Lucien Stals -

Thanks Ken.

I have now successfully updated our production server to 2.6.11. smile

I'm going to practice a bit more on our staging server before I attempt to update production to 2.8.

In reply to Lucien Stals

Re: install from zip, upgrade with git?

by Ken Task -
Picture of Particularly helpful Moodlers

Welcome and congrats1   Wise decision to practice on staging server!!! ;)

'spirit of sharing', Ken