I am building a self hosted PHP application and I want to have a remote update system that will work like WordPress. So, when the user logs in, if there is an available update, he will see the update button and once clicked, the application will be updated. I searched Google but couldn’t find anything to start with. If you have any ideas or resources about this, can you please share here?
If it’s just the one copy of your application you should be pushing the code to the server with source control like git.
If your software is hosted on many servers it’s still possible to just push changes to the different servers.
It’s only if it’s really distributed and you don’t know where your software will be running that I’d consider implementing what you’re describing. Even then, you could leave it up to the users of the software to update it.
With all that said it’s basically just downloading and replacing the application files, running any database migrations that are required, maybe cleaning up the temporary files and if you’re really good having it roll back on failure.
Yes, it is distributed and the user will have the option to update or not just as in WordPress. There is no database, just plain .php files. “just downloading and replacing the application files”, this is where I have no idea how to handle.
Upon log in, connect to remote server and provide current version to see if there are any updates
If there are, download zip file in a temp folder, unzip to current app’s directory directly overwriting current version
New files contain latest version number, so next time they log in, it will do check again, and since there won’t be any changes, it does nothing
PHP has a function called ZipArchive which you can use to unzip files, but it’s an add-on library and may not be included in all PHP builds by default. So if you are going to execute this through WP, then you can include WP context in your script, and then you’ll be able to use all of WP’s functions for unzipping files and stuff, and that will save you a lot of coding because WordPress contains all of the plumbing code.