Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would you implement an auto-update for a standalone PHP project using GitHub?

My project is a collection of PHP scripts using MySQL as a database and needs to be installed locally using WAMP/LAMP/MAMP.

Previously I've been sending the users a link to a zipped archive and having them overwrite it, but since I took the plunge to GitHub, I've realized that there are far better ways; namely Service Hooks in GitHub. However, this would work fine as long as I don't alter the database in any way, which is a good possibility.

I've been toying with the idea of how I would implement this, but I can't find a clear solution. So far I've concluded with that I need to have a directory (say update/) which contains .sql files for each update. The PHP script will then check said directory for a file corresponding with the new version number (not sure how I will define a version number; I was thinking of using the commit ID, but that won't be available until after the commit, so...).

I would love some input on this!

like image 272
John Doe Avatar asked Mar 16 '26 08:03

John Doe


1 Answers

Here's how I would tackle this (not the most elegant or performant):

  1. Add a flag in the DB with a version number
  2. Add a min-version number in your DB layer PHP file
  3. Check that the DB version is greater than the min-version
    • If it is: continue about your business
    • Else: Run the PHP file in update/ which would have a series of ALTER TABLE commands to be run on the DB server
      • Update the min-version number in the DB to the latest number
  4. All done

Alternately instead of querying the DB you can have a file which is generated by your DB interface PHP file (and ignored with .gitignore) which you can just as above.

like image 162
Tarek Fadel Avatar answered Mar 17 '26 22:03

Tarek Fadel