SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Automatic upgrade script

    Hi Guys- I have a commercial application written in PHP and I would like to allow my members to automatically upgrade to the latest release from within their admin section.

    I have seen this kind of thing done within Wordpress, but I am just wondering what is the best way to create such an upgrade script? I guess what I am asking is, what are the steps I need to take in order to create a successful automatic upgrade script?

    Thank you in advance.

  2. #2
    SitePoint Guru
    Join Date
    Feb 2008
    Posts
    655
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the best way to think about it is to visualise the steps that a person would take when manually upgrading and simply automate that.

    So they would:
    1. Check what upgrades exist
    2. Back up their database (and verify the backup)
    3. Backup all the files that will be upgraded
    4. Download the new version
    5. Unpack it into the correct locations
    6. Check all file permissions are accurate
    7. Run any database upgrade scripts that are necessary
    8. Verify everything is in the right place

    When you break it down into steps, I guess it sounds pretty straight forward. I think the important thing is to keep everything backed up and verified at every stage so if anything goes wrong you can revert back to the original version.

  3. #3
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Isn't wordpress an open source project? Does it mean that you can download the source and find how they do this sort of thing?

  4. #4
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,617
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Sharedlog.com View Post
    Isn't wordpress an open source project? Does it mean that you can download the source and find how they do this sort of thing?
    Easier said than done. It's better to understand the basics before attempting to pick apart the code of an existing code base.

    I've wondered about this question as to how it's actually done. My best guess is that you can use the fopen() function on an RSS feed or PHP file on your server, then another fopen() to actually perform the download of the zip/gzip file. After that, I'm not quite sure.

  5. #5
    SitePoint Wizard ryanhellyer's Avatar
    Join Date
    Oct 2006
    Location
    New Zealand
    Posts
    2,323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    AFAIK WordPress doesn't back anything up, I could be wrong though.

    There is a plugin for WordPress which automates the entire process including backups I think.

  6. #6
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by ryanhellyer View Post
    AFAIK WordPress doesn't back anything up, I could be wrong though.

    There is a plugin for WordPress which automates the entire process including backups I think.
    That plugin became part of the base code in version 2.7. The steps it follows are similar to what corbyboy described.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  7. #7
    SitePoint Member h0ll0vvman's Avatar
    Join Date
    Jun 2008
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    for me,

    svn update

  8. #8
    SitePoint Zealot GOPalmer's Avatar
    Join Date
    Jan 2009
    Location
    Wiltshire, UK
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've developed similar in the past and it turned out to be a real pain in the rear. corbyboy has the right idea, think it through and code to match the human process. You may find this of some help http://php.net/manual/en/book.ftp.php

    Best Regards George

  9. #9
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want a really good auto upgrade system, then you have to use some sort of package manager like pear installer

    The way these installers work is that a package usually comes it a .tar or .tar.gz file and this archive file has an xml file that contains information about every file in the package like where to install it, what file permissions to set (if it's necessary), the checksum of each file and of cause the version number.

    Then the installer on your server downloads the package (archive) from package website, unpacks it, examines the xml file and installs all files according the instructions in the xml file, if necessary it will also set writable or executable permissions on some folders and scripts. Installer may also change the schema of existing database tables or add a new table. All these instructions and new schemas are also in xml format in the package.

    If something goes wrong, you can always revert back to the previously installed package, except that you should still backup the database before each upgrade, just in case.

    This is difficult for package developers to maintain and may require the site owner to use sudo to run the installation with root privileges because when you run upgrade from browser, all scripts run under the same user as a web server and usually this account does not own the directories where files going to be installed.

    This solution is great for enterprise system where site is hosted on a dedicated server and admin has root access and can setup sudoers file.

    pear is not the only installer out there. The new pyrus installer that pear will be using in the near future is said to be much faster than the old installer.

    The other way upgrade may work is that you supply the ftp login and password to remote installer. It then ftp to your server and uploads all necessary files, overriding the old versions of the files.

  10. #10
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've pondered this as well, specifically in regards to a custom cms, and how would I make it so clients can automatically or manually update application once I make overall enhancements to the system.

    I'm sure this is a backwards way approach to it, and perhaps svn is worth looking into (which I haven't really explored yet). But I know from the server-side, you can use fopen to write the contents of a php file.

    see as follows, the script will open a file called multiply.php and write the php code to it..
    Code:
    <?php
    
    $file = "multiply.php";
    $handle = fopen($file, 'w') or die("error dude");
    $message = "<?php\n";
    $message .= "\$result = (3 * 3);\n";
    $message .= "echo \$result;\n";
    $message .= "?>";
    fwrite($handle, $message);
    fclose($handle);
    echo "File ".$file." successfully created! View it <a href=\"".$file."\">here</a>.";
    ?>
    I wonder if you can have the updated file available for download from a central database (say on your server), so when the client goes to update a script, it reads the updated script from your database, then writes it to a file on their server.

    I'm really a noob in this regard, and like I said, this method is probably backwards, but is something worth looking into. Say I made an interface that lets the client browse photos, but 1 yr later I make like the ultimate interface with lots more options for sorting, ordering etc. Having a way for the client to update their cms would be nice.

    On a side note, maybe something with cURL is another option (I haven't messed around with this yet either but I think it has to do with downloading url's from other sites (your server to theirs)).

  11. #11
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I have started to build my own script that will automatically upgrade the users software. I have managed to backup the database. Now I need to create a function that will backup the files on the site and create a gzip or zip file.

    How can I read the contents of a directory and compress the contents on the fly?

  12. #12
    SitePoint Member
    Join Date
    May 2009
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Open Source can be nightmare to pick through
    Quote Originally Posted by Sharedlog.com View Post
    Isn't wordpress an open source project? Does it mean that you can download the source and find how they do this sort of thing?
    eTrust : privacy and e-commerce website certification

    * Everything I post represents my personal opinion.

  13. #13
    SitePoint Enthusiast reflash's Avatar
    Join Date
    Jul 2008
    Location
    Pocono Mtns.
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Zaggs View Post
    Ok, I have started to build my own script that will automatically upgrade the users software. I have managed to backup the database. Now I need to create a function that will backup the files on the site and create a gzip or zip file.

    How can I read the contents of a directory and compress the contents on the fly?
    I'd be interested to see how you backed up the database on the fly. Where do you store the backups - on the server, or on the machine from which you launch it?
    Whatever is worth doing is worth over-doing...

  14. #14
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Generally backups are created on the server and you then need to provide a separate option for downloading the backup to the local computer. This can't be easily integrated since it is necessary to ask where on the local computer to save the copy of the backup (since each local computer has its own arrangement for what is where).
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •