Skip to content

Commit 311051f

Browse files
authored
Merge branch 'master' into master
2 parents 489eb96 + 4d49e66 commit 311051f

25 files changed

+646
-285
lines changed

cli/Valet/Brew.php

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,28 @@ function hasInstalledPhp()
4242
{
4343
return $this->installed('php71')
4444
|| $this->installed('php70')
45-
|| $this->installed('php56')
46-
|| $this->installed('php55');
45+
|| $this->installed('php56');
46+
}
47+
48+
/**
49+
* Determine if a compatible nginx version is Homebrewed.
50+
*
51+
* @return bool
52+
*/
53+
function hasInstalledNginx()
54+
{
55+
return $this->installed('nginx')
56+
|| $this->installed('nginx-full');
57+
}
58+
59+
/**
60+
* Return name of the nginx service installed via Homebrewed.
61+
*
62+
* @return string
63+
*/
64+
function nginxServiceName()
65+
{
66+
return $this->installed('nginx-full') ? 'nginx-full' : 'nginx';
4767
}
4868

4969
/**
@@ -71,6 +91,8 @@ function ensureInstalled($formula, $options = [], $taps = [])
7191
*/
7292
function installOrFail($formula, $options = [], $taps = [])
7393
{
94+
info("Installing {$formula}...");
95+
7496
if (count($taps) > 0) {
7597
$this->tap($taps);
7698
}
@@ -109,7 +131,12 @@ function restartService($services)
109131
$services = is_array($services) ? $services : func_get_args();
110132

111133
foreach ($services as $service) {
112-
$this->cli->quietly('sudo brew services restart '.$service);
134+
if ($this->installed($service)) {
135+
info("Restarting {$service}...");
136+
137+
$this->cli->quietly('sudo brew services stop '.$service);
138+
$this->cli->quietly('sudo brew services start '.$service);
139+
}
113140
}
114141
}
115142

@@ -123,7 +150,11 @@ function stopService($services)
123150
$services = is_array($services) ? $services : func_get_args();
124151

125152
foreach ($services as $service) {
126-
$this->cli->quietly('sudo brew services stop '.$service);
153+
if ($this->installed($service)) {
154+
info("Stopping {$service}...");
155+
156+
$this->cli->quietly('sudo brew services stop '.$service);
157+
}
127158
}
128159
}
129160

@@ -146,8 +177,6 @@ function linkedPhp()
146177
return 'php70';
147178
} elseif (strpos($resolvedPath, 'php56') !== false) {
148179
return 'php56';
149-
} elseif (strpos($resolvedPath, 'php55') !== false) {
150-
return 'php55';
151180
} else {
152181
throw new DomainException("Unable to determine linked PHP.");
153182
}
@@ -162,17 +191,4 @@ function restartLinkedPhp()
162191
{
163192
$this->restartService($this->linkedPhp());
164193
}
165-
166-
/**
167-
* Create the "sudoers.d" entry for running Brew.
168-
*
169-
* @return void
170-
*/
171-
function createSudoersEntry()
172-
{
173-
$this->files->ensureDirExists('/etc/sudoers.d');
174-
175-
$this->files->put('/etc/sudoers.d/brew', 'Cmnd_Alias BREW = /usr/local/bin/brew *
176-
%admin ALL=(root) NOPASSWD: BREW'.PHP_EOL);
177-
}
178194
}

cli/Valet/Configuration.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ function install()
2828
$this->createSitesDirectory();
2929
$this->createExtensionsDirectory();
3030
$this->createLogDirectory();
31+
$this->createCertificatesDirectory();
3132
$this->writeBaseConfiguration();
3233

3334
$this->files->chown($this->path(), user());
@@ -94,6 +95,16 @@ function createLogDirectory()
9495
$this->files->touch(VALET_HOME_PATH.'/Log/nginx-error.log');
9596
}
9697

98+
/**
99+
* Create the directory for SSL certificates.
100+
*
101+
* @return void
102+
*/
103+
function createCertificatesDirectory()
104+
{
105+
$this->files->ensureDirExists(VALET_HOME_PATH.'/Certificates', user());
106+
}
107+
97108
/**
98109
* Write the base, initial configuration for Valet.
99110
*/

cli/Valet/Nginx.php

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
namespace Valet;
44

5+
use DomainException;
6+
57
class Nginx
68
{
79
var $brew;
810
var $cli;
911
var $files;
1012
var $configuration;
1113
var $site;
14+
const NGINX_CONF = '/usr/local/etc/nginx/nginx.conf';
1215

1316
/**
1417
* Create a new Nginx instance.
@@ -37,7 +40,9 @@ function __construct(Brew $brew, CommandLine $cli, Filesystem $files,
3740
*/
3841
function install()
3942
{
40-
$this->brew->ensureInstalled('nginx', ['--with-http2']);
43+
if (!$this->brew->hasInstalledNginx()) {
44+
$this->brew->installOrFail('nginx', ['--with-http2']);
45+
}
4146

4247
$this->installConfiguration();
4348
$this->installServer();
@@ -51,10 +56,12 @@ function install()
5156
*/
5257
function installConfiguration()
5358
{
59+
info('Installing nginx configuration...');
60+
5461
$contents = $this->files->get(__DIR__.'/../stubs/nginx.conf');
5562

5663
$this->files->putAsUser(
57-
'/usr/local/etc/nginx/nginx.conf',
64+
static::NGINX_CONF,
5865
str_replace(['VALET_USER', 'VALET_HOME_PATH'], [user(), VALET_HOME_PATH], $contents)
5966
);
6067
}
@@ -92,6 +99,8 @@ function installServer()
9299
*/
93100
function installNginxDirectory()
94101
{
102+
info('Installing nginx directory...');
103+
95104
if (! $this->files->isDir($nginxDirectory = VALET_HOME_PATH.'/Nginx')) {
96105
$this->files->mkdirAsUser($nginxDirectory);
97106
}
@@ -101,6 +110,19 @@ function installNginxDirectory()
101110
$this->rewriteSecureNginxFiles();
102111
}
103112

113+
/**
114+
* Check nginx.conf for errors.
115+
*/
116+
private function lint()
117+
{
118+
$this->cli->quietly(
119+
'sudo nginx -c '.static::NGINX_CONF.' -t',
120+
function ($exitCode, $outputMessage) {
121+
throw new DomainException("Nginx cannot start, please check your nginx.conf [$exitCode: $outputMessage].");
122+
}
123+
);
124+
}
125+
104126
/**
105127
* Generate fresh Nginx servers for existing secure sites.
106128
*
@@ -120,7 +142,9 @@ function rewriteSecureNginxFiles()
120142
*/
121143
function restart()
122144
{
123-
$this->cli->quietly('sudo brew services restart nginx');
145+
$this->lint();
146+
147+
$this->brew->restartService($this->brew->nginxServiceName());
124148
}
125149

126150
/**
@@ -130,7 +154,9 @@ function restart()
130154
*/
131155
function stop()
132156
{
133-
$this->cli->quietly('sudo brew services stop nginx');
157+
info('Stopping nginx....');
158+
159+
$this->cli->quietly('sudo brew services stop '. $this->brew->nginxServiceName());
134160
}
135161

136162
/**

cli/Valet/PhpFpm.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ function __construct(Brew $brew, CommandLine $cli, Filesystem $files)
3636
*/
3737
function install()
3838
{
39-
if (! $this->brew->installed('php71') &&
40-
! $this->brew->installed('php70') &&
41-
! $this->brew->installed('php56') &&
42-
! $this->brew->installed('php55')) {
39+
if (! $this->brew->hasInstalledPhp()) {
4340
$this->brew->ensureInstalled('php71', [], $this->taps);
4441
}
4542

@@ -57,6 +54,8 @@ function install()
5754
*/
5855
function updateConfiguration()
5956
{
57+
info('Updating PHP configuration...');
58+
6059
$contents = $this->files->get($this->fpmConfigPath());
6160

6261
$contents = preg_replace('/^user = .+$/m', 'user = '.user(), $contents);
@@ -67,6 +66,16 @@ function updateConfiguration()
6766
$contents = preg_replace('/^;?listen\.mode = .+$/m', 'listen.mode = 0777', $contents);
6867

6968
$this->files->put($this->fpmConfigPath(), $contents);
69+
70+
71+
$contents = $this->files->get(__DIR__.'/../stubs/php-memory-limits.ini');
72+
73+
$destFile = dirname($this->fpmConfigPath());
74+
$destFile = str_replace('/php-fpm.d', '', $destFile);
75+
$destFile .= '/conf.d/php-memory-limits.ini';
76+
$this->files->ensureDirExists(dirname($destFile), user());
77+
78+
$this->files->putAsUser($destFile, $contents);
7079
}
7180

7281
/**
@@ -76,8 +85,6 @@ function updateConfiguration()
7685
*/
7786
function restart()
7887
{
79-
$this->stop();
80-
8188
$this->brew->restartLinkedPhp();
8289
}
8390

@@ -88,7 +95,7 @@ function restart()
8895
*/
8996
function stop()
9097
{
91-
$this->brew->stopService('php55', 'php56', 'php70', 'php71');
98+
$this->brew->stopService('php56', 'php70', 'php71');
9299
}
93100

94101
/**
@@ -102,7 +109,6 @@ function fpmConfigPath()
102109
'php71' => '/usr/local/etc/php/7.1/php-fpm.d/www.conf',
103110
'php70' => '/usr/local/etc/php/7.0/php-fpm.d/www.conf',
104111
'php56' => '/usr/local/etc/php/5.6/php-fpm.conf',
105-
'php55' => '/usr/local/etc/php/5.5/php-fpm.conf',
106112
];
107113

108114
return $confLookup[$this->brew->linkedPhp()];

0 commit comments

Comments
 (0)