2021-11-30 00:10:54 +01:00
|
|
|
# Avoid PHP-FPM Reloading
|
2021-11-30 00:04:41 +01:00
|
|
|
|
|
|
|
Deployer symlinks _current_ to latest release dir.
|
|
|
|
|
|
|
|
```
|
|
|
|
current -> releases/3/
|
|
|
|
releases/
|
|
|
|
1/
|
|
|
|
2/
|
|
|
|
3/
|
|
|
|
```
|
|
|
|
|
|
|
|
## The problem
|
|
|
|
|
2022-01-28 00:13:13 +01:00
|
|
|
PHP Opcodes get cached. And if `SCRIPT_FILENAME` contains _current_ symlink, on
|
2022-09-06 09:17:58 +02:00
|
|
|
new deploy nothing updates. Usually, a solution is simple to reload **php-fpm**
|
2021-11-30 05:28:12 +01:00
|
|
|
after deploy, but such reload can lead to **dropped** or **failed** requests.
|
2022-01-28 00:13:13 +01:00
|
|
|
The correct fix is to configure your server set `SCRIPT_FILENAME` to a resolved path.
|
2021-11-30 00:04:41 +01:00
|
|
|
You can check your server configuration by printing `SCRIPT_FILENAME`.
|
|
|
|
|
|
|
|
```php
|
|
|
|
echo $_SERVER['SCRIPT_FILENAME'];
|
|
|
|
```
|
|
|
|
|
2022-09-06 09:17:58 +02:00
|
|
|
If it prints something like `/home/deployer/example.com/current/index.php` with
|
2022-01-28 00:13:13 +01:00
|
|
|
_current_ in the path, your server configured incorrectly.
|
2021-11-30 00:04:41 +01:00
|
|
|
|
|
|
|
## Fix for Nginx
|
|
|
|
|
|
|
|
Nginx has special variable `$realpath_root`, use it to set up `SCRIPT_FILENAME`:
|
|
|
|
|
2021-11-30 00:10:54 +01:00
|
|
|
```diff
|
2021-11-30 00:04:41 +01:00
|
|
|
location ~ \.php$ {
|
|
|
|
include fastcgi_params;
|
|
|
|
fastcgi_pass unix:/var/run/php/php-fpm.sock;
|
2022-09-06 09:17:58 +02:00
|
|
|
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
2021-11-30 00:04:41 +01:00
|
|
|
+ fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Fix for Caddy
|
|
|
|
|
|
|
|
:::tip
|
2022-09-06 09:17:58 +02:00
|
|
|
If you're already using servers provisioned by Deployer, you don't need to fix
|
2022-01-28 00:13:13 +01:00
|
|
|
anything, as everything is already configured properly.
|
2021-11-30 00:04:41 +01:00
|
|
|
:::
|
|
|
|
|
|
|
|
Use `resolve_root_symlink`:
|
|
|
|
|
|
|
|
```
|
2021-12-07 20:22:01 +01:00
|
|
|
php_fastcgi * unix//run/php/php-fpm.sock {
|
2021-11-30 00:04:41 +01:00
|
|
|
resolve_root_symlink
|
|
|
|
}
|
|
|
|
```
|