Search code examples
phpftpproftpdpureftpd

How do you upload a core PHP file via FTP without interrupting a visitor to your site


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


Solution

  • 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.