I am developing a web application in PHP and JS. The software until recently was only being developed on and not being used by clients, so I could just change the script files directly. After the application went into release I just copied the application in a beta folder in which I could do changes. After testing the changes I manually selected the changed files and copied them into the release system.
Well, I really think there must be a better approach to my problem, that does not include manually copying files from beta to release. I used git for projects to collaborate with other people, but those always were non web applications, that were not running, while changing them. Collaboration is not as important, for I am working alone, at least in the medium term. Are there approaches to use git oder something else for working web applications?
As IDE I am using Netbeans, which is synchronized with the server.
Edit: Currently the productive code is located in the htdocs folder of the webserver. A copy of the whole stuff is in htdocs/dev. I do changes on the code in dev via Netbeans, without any version control plug-in, it just synchronizes the project files via sftp with the files in dev. After changing I am able to test the changes using example.org/beta. If everything’s fine I copy the changed files into the productive system.
6
If, as you write, you directly edit files on the server over SFTP, your only option (as far as I can see) is to install git on the server, login via SSH and do all git operations locally. You’d have to create a repository on the server, add all your files and then commit regularly. In that case your working directory would be the directory where all the JS and PHP files live.
However, I would not recommend this approach, as it has some problems. Among others, you need SSH login on the server, your git repo must be on the server, and if your application’s files are spread over multiple directories, it gets difficult to put everything into one repository.
What I would recommend instead is: Develop locally, then deploy to server.
That means you install PHP, webserver etc. locally, then keep the code on your workstation and do most of your development there. Then you can alwso use git locally to version your code.
Once a feature is ready, you deploy your code to the production web host, to make it go live (or to a test installation for final testing). This gives you much more flexibility while developing (easier to use various tools, like git, no need for constant server access, less risk to mess up the server while developing etc.).
To do this, you need
- a local installation of PHP and all other required infrastructuresome, and
- some kind of deployment system.
Local installations of PHP are readily available (see for example the question PHP server on local machine? ).
For deployment, there are many existing systems, and there are deployment solutions specifically for PHP. You could also just start out with a simple script that SFTPs everything to the server, and makes them live (restarts any services as required, clears caches etc.) and then go on from there.
1
SVN/GIT or any control version should work.
Except for very specific application, web application a rarely live ( in the sense Physically loaded in memory) and i assume your application doesnt rewrite itself ( else you have the risk of rewriting the push you just made).
Then if you push your file the next call on the webserver/php will load the new code (except if you have a cache system obviously) and go foward on the new code.
So Git push your change, remove the cache and you should be good to go.
In Case you DO have an application wich is simultaneously fully charged in memory and use no cache, you should use a cyclic call to check for a flag File.
When you push a mod, push also the Flag.
Make your soft do a soft landing ( no new connection, wait until all old connection die down ), do the mod, delete the flag and then restart into normal (accepting connection) mode.
At first make the check a lot ( something like every minute, at least every hour), then when you stabilize your dev cycle more you can space out the check ( something like once a day, once a week)
3
My answer to What version control system can manage all aspects? may help. Basically, you need to tag the released version so an automated process can check it out. I’ve used cron to check for and apply changes on a periodic basis.