1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-04 16:10:08 +01:00

Move PHP-FPM config to separate valet-specific file

This allows the valet configuration to stand separately from the default PHP config.
This benefits troubleshooting, makes customization of FPM workers and other settings easer
and allows for easier uninstallation.

Also renames any previously-existing `www.conf` pool config so it doesn't conflict with Valet nor run unnecessary additional processes.
This commit is contained in:
Chris Brown
2019-12-01 01:00:42 -05:00
parent fb562977f0
commit 139a916013
2 changed files with 50 additions and 10 deletions

View File

@@ -54,21 +54,35 @@ function updateConfiguration()
{
info('Updating PHP configuration...');
$contents = $this->files->get($this->fpmConfigPath());
$fpmConfigFile = $this->fpmConfigPath();
$this->files->ensureDirExists(dirname($fpmConfigFile), user());
// rename (to disable) old FPM Pool configuration, regardless of whether it's a default config or one customized by an older Valet version
$oldFile = dirname($fpmConfigFile) . '/www.conf';
if (file_exists($oldFile)) {
rename($oldFile, $oldFile . '-backup');
}
if (false === strpos($fpmConfigFile, '5.6')) {
// for PHP 7 we can simply drop in a valet-specific fpm pool config, and not touch the default config
$contents = $this->files->get(__DIR__.'/../stubs/etc-phpfpm-valet.conf');
$contents = str_replace(['VALET_USER', 'VALET_HOME_PATH'], [user(), VALET_HOME_PATH], $contents);
} else {
// for PHP 5 we must do a direct edit of the fpm pool config to switch it to Valet's needs
$contents = $this->files->get($fpmConfigFile);
$contents = preg_replace('/^user = .+$/m', 'user = '.user(), $contents);
$contents = preg_replace('/^group = .+$/m', 'group = staff', $contents);
$contents = preg_replace('/^listen = .+$/m', 'listen = '.VALET_HOME_PATH.'/valet.sock', $contents);
$contents = preg_replace('/^;?listen\.owner = .+$/m', 'listen.owner = '.user(), $contents);
$contents = preg_replace('/^;?listen\.group = .+$/m', 'listen.group = staff', $contents);
$contents = preg_replace('/^;?listen\.mode = .+$/m', 'listen.mode = 0777', $contents);
$this->files->put($this->fpmConfigPath(), $contents);
}
$this->files->put($fpmConfigFile, $contents);
$contents = $this->files->get(__DIR__.'/../stubs/php-memory-limits.ini');
$destFile = dirname($this->fpmConfigPath());
$destFile = dirname($fpmConfigFile);
$destFile = str_replace('/php-fpm.d', '', $destFile);
$destFile .= '/conf.d/php-memory-limits.ini';
$this->files->ensureDirExists(dirname($destFile), user());
@@ -116,7 +130,7 @@ function fpmConfigPath()
return $versionNormalized === '5.6'
? '/usr/local/etc/php/5.6/php-fpm.conf'
: "/usr/local/etc/php/${versionNormalized}/php-fpm.d/www.conf";
: "/usr/local/etc/php/${versionNormalized}/php-fpm.d/valet-fpm.conf";
}
/**

View File

@@ -0,0 +1,26 @@
; FPM pool configuration for Valet
[valet]
user = VALET_USER
group = staff
listen = VALET_HOME_PATH/valet.sock
listen.owner = VALET_USER
listen.group = staff
listen.mode = 0777
php_admin_value[memory_limit] = 128M
php_admin_value[upload_max_filesize] = 128M
php_admin_value[post_max_size] = 128M
;php_admin_value[error_log] = VALET_HOME_PATH/Log/fpm-php.www.log
;php_admin_flag[log_errors] = on
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3