Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions cli/Valet/PhpFpm.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,35 @@ function updateConfiguration()
{
info('Updating PHP configuration...');

$contents = $this->files->get($this->fpmConfigPath());
$fpmConfigFile = $this->fpmConfigPath();

$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->ensureDirExists(dirname($fpmConfigFile), user());

$this->files->put($this->fpmConfigPath(), $contents);
// 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($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());
Expand Down Expand Up @@ -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";
}

/**
Expand Down
26 changes: 26 additions & 0 deletions cli/stubs/etc-phpfpm-valet.conf
Original file line number Diff line number Diff line change
@@ -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