如何在没有时间限制的情况下在生产中迁移单个(php || javascript || ...)文件

I have simple files (php||javascript||...) running in production (apache+(php||javascript||...)).

I am trying to think to the proper way of migrating a simple file while not stopping serving web clients.

Possible influences are:

  • Apache cached files: I do not know how apache deal with files (php, img, ...). Does it cache them, and check for update timestamp to reload, or does it reload on each http request ?
  • Linux files are changed in an atomic manner: If I cp a file with new content, apache can only see the full content final save results of my command ?
  • Apache execution process: Can I pause Apache, holding current requests, while copying new file versions.

I imagine the following:

  • Have files, like php require_once file, named with versions (ex: ABusinessClassD-v1.0.php), support backward compatibility, and simply do a cp of new files one by one, going from bottom up (database, static files (img, ...), php files, javascript files, ...)
  • Force refresh browser code on demand.

Imagination != as simple as this != Reality.

Please, can somebody summarize globally simple manual steps to update a simple file in an apache production, without stopping serving web clients, in a manual intentionally slow process ?

The only sure way to guarantee no issues when moving over a PHP codebase would be to have two servers or two deployments on the same server.

You have Server 1 which contains your old code. Server 2 is set up with the new code. Then, your DNS records or load balancer/proxy settings are changed so your site is instead served from Server 2.

Or with one server, you configure Apache to serve your application from /path/to/old, and then set up your new version in /path/to/new. Then you change your Apache configuration to use /path/to/new for the application and restart the server.

If you ever need to use version numbers in file names (ABusinessClassD-v1.0.php) then you need to learn about version control software like Git or Mercurial.