2

This question already has an answer here:

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.

marked as duplicate by user40980, Bart van Ingen Schenau, GlenH7, durron597, gnat Mar 30 '15 at 16:39

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • @MichaelT: That's not really a duplicate - it is related, but a significantly narrower question. – sleske Mar 30 '15 at 9:11
  • How do you currently work? Do you log in on the host and edit files there directly? Do you work locally and push to the host? How? – sleske Mar 30 '15 at 9:12
  • Your better approach is learning a real programming language like c#, java or python and use a serious framework. You will se how things change radically – JuanRocamonde Mar 30 '15 at 10:59
  • 1
    @sleske: 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. – dboth Mar 30 '15 at 11:02
  • @JuanRocamonde I regret the decision to develop the app in PHP. But now it's to late as the development is to much progressed. – dboth Mar 30 '15 at 11:09
5

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.

  • I was unspecific when I wrote that I am alone. I am the only programmer, but the testing also is done by a second person, thats why it is necessary to have the dev system online. I tried to set up this system in git, but encountered other problems, which lead to another question: programmers.stackexchange.com/questions/277804/… – dboth Mar 30 '15 at 22:57
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)

  • Yes, the scripts are only loaded once they're needed by the php runtime, so there's no problem on changing them while the system is running. How would a dev system in the git way look like, would it be a clone of the master branch? So workflow would be committing to the clone and when everything is alright pushing from the clone to the master? I specified some things on the comments above, is it possible to keep that folder structure? – dboth Mar 30 '15 at 11:17
  • As Said above by Steske, development on a prod server should be avoided. But If you REALLY need to dev on the server, you can setup your git so in the Dev folder you have your dev branch, and the "main" folder will have your Master branch. When your mod are safe / valid you merge your dev branch to the master. – Gorkam Mar 30 '15 at 13:29
  • I tried to set up this system in git, but being not quite experienced with git I couldn't get this to work, which led to another question: programmers.stackexchange.com/questions/277804/… – dboth Mar 30 '15 at 22:59
0

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.