3

Whenever an active PHP based site I look after needs an urgent code change, I change the code offline, test it on my local server and then when happy, upload the updated file to the production server via FTP.

This obviously works, but I have found that when I do this on a busy site, if someone accesses the file in their browser at exactly the same time I am uploading, they will receive a PHP parse error. I assume that this is because the upload via FTP hasn't completed at the point when they try to access it.

I can't wait until a quiet period to upload my new files as the site is busy 24/7, so how can I avoid this? Do certain FTP servers handle this better than others or am I going about deploying to the production server in the wrong way?

CENTOS 6.6, Apache, ProFTPd/PureFTPd, PHP 5.3

SammyBlackBaron
  • 847
  • 3
  • 13
  • 31
  • 4
    don't upload to the production dir then. upload somewhere else, then MOVE the file into place once the upload's done. a local move will be MUCH faster than ftp-into-place. – Marc B Jun 02 '15 at 15:45
  • @MarcB : true. Further, if the initial upload is on the same file system, the move operation is atomic, almost instantaneous as it simply requires an update to the inode. – YvesLeBorg Jun 02 '15 at 15:54
  • I'm with @MarcB, That's the way I do it. I push my commits to github. pull through ssh and then copy my data over locally when I do changes on my site. – Morgan Green Jun 02 '15 at 16:25

2 Answers2

1

You could achieve that by uploading all application into another directory. Your public directory can link into directory with your application current release. When you upload all of your application files you can simply switch the symlink.

For example you have some apache/nginx host configured at

/var/awesome-app/public_html

Store your application somewhere else, e.g. your home dir. Upload your application into separate release directory, like this:

~/awesome-app/releases/1
~/awesome-app/releases/2
~/awesome-app/releases/3
...
~/awesome-app/releases/<RELEASE_NUMBER>

Create a symbolic link from your application to the path where host is pointed. This command should be called once - when you setup your enviroment:

ln -s ~/awesome-app/current /var/awesome-app/public_html

After your application is uploaded create (replace) symlink to current release. This command should be called with every release.

ln -sf ~/awesome-app/releases/4 ~/awesome-app/current

You might want also look at the Software deployment.

Community
  • 1
  • 1
0

You can make two backends (copies, e.g. nginx upstream) of application and update it separately (with disable current updated backend).

Deep
  • 2,472
  • 2
  • 15
  • 25