Webserver configuration
Sometimes it is recommended when doing a zero downtime deployment to restart your webserver or even thephp-fpm
daemon, this is however not strictly necessary as long as the webserver is configured correctly.
We even strongly recommend against doing this since restarting the webserver or the php-fpm
daemon will cause a short downtime of your application which is not very zero downtime 😉.
NGINX
A default installation of NGINX will not be able to handle the zero downtime deployments out of the box. By default there will be a file calledfastcgi_params
or fastcgi.conf
in the /etc/nginx
folder which contains the following lines:
grep -R SCRIPT_FILENAME /etc/nginx/
.
This line will cause NGINX to serve the index.php
file from the current release folder, however it will not see that the folder is a symlink so it SCRIPT_FILENAME
(and DOCUMENT_ROOT
) will be set to something like:
SCRIPT_FILENAME
will still be the same and PHP will still serve the cached version of the file instead of the new version.
To fix this we need to change the SCRIPT_FILENAME
to the actual file path that is being served, which is in the release folder, we do this by changing the snippet to use the $realpath_root
variable instead of $document_root
:
SCRIPT_FILENAME
(and DOCUMENT_ROOT
) to the actual path that is being served, which is something like:
php-fpm
deamon or NGINX after a deployment because on every deployment the release folder changes so the file is no longer cached and will be retrieved from the disk before being cached again.