How to self-update PHP+MySQL CMS?

SaltLake picture SaltLake · Mar 13, 2010 · Viewed 7k times · Source

I'm writing a CMS on PHP+MySQL. I want it to be self-updatable (throw one click in admin panel). What are the best practices?
How to compare current version of cms and a version of the update (application itself and database). Should it just download zip archive, upzip it and overwrite files? (but what to do with files that are no longer used). How to check if an update is downloaded correctly? Also it supports modules and I want this modules to be downloadable from the admin panel of cms.
And how should I update MySQL tables?

Answer

Bart van Heukelom picture Bart van Heukelom · Mar 13, 2010
  • Keep your code in a separate location from configuration and otherwise variable files (uploaded images, cache files, etc.)
  • Keep the modules separate from the main code as well.
  • Make sure your code has file system permissions to change itself (use SuPHP for example).

If you do these, simplest would be to completely download the new version (no incremental patches), and unzip it to a directory adjacent to the one containing the current version. Because there won't be variable files inside the code directory, you can just remove or rename the old one and rename the new one to replace it.

You can keep the version number in a global constant in the code.

As for MySQL, there's no other way than making an upgrade script for every version that changes the DB layout. Even automatic solutions to change the table definition can't know how to update the existing data.