views:

50

answers:

2

Hi,

We are creating a php script project; which we will be selling to customers.
The customers can host the script on their web server.

We would like to develop an update or upgrade process for this script.
Means if a customer is using the version 1.2 of the script and we have released the new version 1.3 of the script, the users will be able to see a text saying "new version is available" in the backend control panel.

The user can than go to update or upgrade page and hit a button to auto update the script.
I can understand that this process will involve the following things: 1. A process to check the current version of the script available from our home website.
2. File update process: download and update the required files from my server on the client server.
3. Make required database changes: Download the upgrade sql file from my home server and run it against the database.

I tried google to find a good start up tutorial to give me a kick start and to verify if I am missing something but I am not able to find anything.
Can you point me to some kick start tutorials or guide about developing or managing update process of a script?
I know that all major open source scripts like Wordpress, Joomla, osCommerce, Magento have this facility. So there must be resources available for this on the internet.

Thank you for our time.. have fun! :)

+1  A: 

To do this requires a solid separation of custom vs core code. You would want to make sure users have a seperate set of pages to hook into your code from. Perhaps you should run an MD5 check remotely on the pages before carrying out the update.

The easiest solution to this is to have your script (on customer side) run a SOAp/REST command sending its version and serial to your home server. In turn your server can send back a message with the new version.

If the user clicks the link, the customer side script would need to send another SOAP/REST command with information (FTP info for instance) to allow your server to connect and overwrite the core files.

Keep in mind, this requires the users to set correct chmod and chgrp/chown permissions on the files so that you can actually connect and overwrite the files.

Many scripts have this functionality however it is a large security risk. Think hard on if the effort to implement this correctly is worth it...Sometimes simply sending a tar/zip is easier.

By remotely updating, you are running into huge liability and security issues...

CogitoErgoSum
+1  A: 

Does this realy need a tutorial ? just bring your editor and start coding, if i were you, here's the way i'll be doing it:

  • In order to manipulate them, all your files need to be chmoded 777 (if unix).
  • create a file, say updater.php
  • that file will connect to your website (through curl for example) and check whether an update is available.
  • server side, consider making a manifest file with paths to files to be replaced + an SQL file with database changes + the replacing files and package all that in a tar (or zip).
  • make your updater.php script download that archive and store it in a local directory say 'temp'.
  • updater.php will have to uncompress (using php's zip extension for example) to ./temp/files
  • updater.php will have to use ./temp/files/manifest in order to find and replace files
  • before replacing do some file integrity checks and be sure the files have not been changed (compare checksums).
  • check database too, before making any changes.
  • if all is OK, commit changes.
  • remove temp data.
  • that's all.

you can add backup support to restore working copy if it fails.

youssef azari
The files don't need to be chmod `777`. They just need to be writable by the webserver's user. Leaving (or even allowing them to be) them `777` is just a bad move...
ircmaxell
@ircmaxell, Right. 777 will make files writable by all. consider restricted chmod.
youssef azari