1

Here is the context of my problem : we have managed servers (Hetzner) and are trying to implement a zero downtime deployment with symlinks. Here is what we do on each push : we deploy the new code in a new directory, change the symlink of the document root to point to that new directory, keep the last 4 releases and delete the older one, clear opcache by calling a php file via curl (opcache_reset() in it). The problem is random : sometimes it works fine and sometimes we are experiencing 500 HTTP errors and some "cannot redeclare" errors and it seems it's trying to serve 2 releases in the same time as you can see down here : enter image description here

The thing is we are doing the same thing for another app, but this one running on Symfony and we have no problem at all.

We are running on Apache, PHP 8.1 with OPCache activated and the following php config : enter image description here

I tried to change the opcache config (validate_timestamps 0/1, use_cwd, etc) and it did'nt resolve my problem.

I also tried to add a composer clear-cache command after resetting opcache, didn't work either.

I tried to change +FollowSymlinks to +SymLinksIfOwnerMatch in .htacces file, didn't work.

The strange thing is that it can either work for 10 back to back push and then doesn't work, it's completely random.

If any of you have an idea or solution, that would be great ! Thanks.

  • I'm also having this problem on Digital Ocean servers managed by Runcloud. Our deploy with Ansible also updates a symlink which works on other servers I've used in the past, but Apache seems to be caching the old symlink path and I'm at a loss. Still researching it. Wondering if you got anywhere? – Sherri Jul 13 '23 at 16:19
  • Discovered that setting opcache.revalidate_path=1 in the global php.ini file for php-fpm solved the issue. I'm in the same boat though, my server is managed with Runcloud. I'm still determining how to set this without overriding the Runcloud settings. Doesn't seem to work in a local php.ini file. Either way, it seems to be a PHP opcache issue. – Sherri Jul 13 '23 at 17:32

1 Answers1

0

There is a recommened way to do this found in this Stackoverflow question, but in our case with managed servers, I have limited ways to customize the Nginx settings. So I found that I needed to have PHP's opcache revalidate the cached paths. While you could do this globally with the php.ini setting for PHP FPM, my servers (managed by Runcloud) have a specific place to override PHP settings in /etc/php-extra/<web_application_name>.conf.

Ultimately the goal is to set the php setting opcache.revalidate_path=1 and you may need to find out from Hetzner what the recommended way to do this is. A local php.ini file within my app itself did not work.

This post has a good write up and this one talks about realpath caching.

Sherri
  • 816
  • 2
  • 9
  • 18