mirror of
https://github.com/laravel/valet.git
synced 2026-02-05 16:40:05 +01:00
Serve static files through Caddy instead of PHP
This commit is contained in:
@@ -46,12 +46,13 @@ function install()
|
|||||||
$this->files->ensureDirExists('/usr/local/var/log', user());
|
$this->files->ensureDirExists('/usr/local/var/log', user());
|
||||||
|
|
||||||
$this->updateConfiguration();
|
$this->updateConfiguration();
|
||||||
|
$this->updateIni();
|
||||||
|
|
||||||
$this->restart();
|
$this->restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the PHP FPM configuration to use the current user.
|
* Update the PHP FPM configuration.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@@ -66,6 +67,20 @@ function updateConfiguration()
|
|||||||
$this->files->put($this->fpmConfigPath(), $contents);
|
$this->files->put($this->fpmConfigPath(), $contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the PHP FPM ini.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function updateIni()
|
||||||
|
{
|
||||||
|
$contents = $this->files->get($this->fpmIniPath());
|
||||||
|
|
||||||
|
$contents = preg_replace('/^default_mimetype = .+$/m', 'default_mimetype = ""', $contents);
|
||||||
|
|
||||||
|
$this->files->put($this->fpmIniPath(), $contents);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restart the PHP FPM process.
|
* Restart the PHP FPM process.
|
||||||
*
|
*
|
||||||
@@ -95,16 +110,30 @@ function stop()
|
|||||||
*/
|
*/
|
||||||
function fpmConfigPath()
|
function fpmConfigPath()
|
||||||
{
|
{
|
||||||
if ($this->brew->linkedPhp() === 'php71') {
|
$confLookup = [
|
||||||
return '/usr/local/etc/php/7.1/php-fpm.d/www.conf';
|
'php71' => '/usr/local/etc/php/7.1/php-fpm.d/www.conf',
|
||||||
} elseif ($this->brew->linkedPhp() === 'php70') {
|
'php70' => '/usr/local/etc/php/7.0/php-fpm.d/www.conf',
|
||||||
return '/usr/local/etc/php/7.0/php-fpm.d/www.conf';
|
'php56' => '/usr/local/etc/php/5.6/php-fpm.conf',
|
||||||
} elseif ($this->brew->linkedPhp() === 'php56') {
|
'php55' => '/usr/local/etc/php/5.5/php-fpm.conf',
|
||||||
return '/usr/local/etc/php/5.6/php-fpm.conf';
|
];
|
||||||
} elseif ($this->brew->linkedPhp() === 'php55') {
|
|
||||||
return '/usr/local/etc/php/5.5/php-fpm.conf';
|
return $confLookup[$this->brew->linkedPhp()];
|
||||||
} else {
|
}
|
||||||
throw new DomainException('Unable to find php-fpm config.');
|
|
||||||
}
|
/**
|
||||||
|
* Get the path to the FPM ini file for the current PHP version.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function fpmIniPath()
|
||||||
|
{
|
||||||
|
$versionLookup = [
|
||||||
|
'php71' => '/usr/local/etc/php/7.1/php.ini',
|
||||||
|
'php70' => '/usr/local/etc/php/7.0/php.ini',
|
||||||
|
'php56' => '/usr/local/etc/php/5.6/php.ini',
|
||||||
|
'php55' => '/usr/local/etc/php/5.5/php.ini',
|
||||||
|
];
|
||||||
|
|
||||||
|
return $versionLookup[$this->brew->linkedPhp()];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,15 +119,7 @@ public function mutateUri($uri)
|
|||||||
*/
|
*/
|
||||||
public function serveStaticFile($staticFilePath, $sitePath, $siteName, $uri)
|
public function serveStaticFile($staticFilePath, $sitePath, $siteName, $uri)
|
||||||
{
|
{
|
||||||
$extension = strtolower(pathinfo($staticFilePath)['extension']);
|
header('X-Accel-Redirect: ' . $staticFilePath);
|
||||||
|
|
||||||
$mimes = require(__DIR__.'/../mimes.php');
|
|
||||||
|
|
||||||
$mime = isset($mimes[$extension]) ? $mimes[$extension] : 'application/octet-stream';
|
|
||||||
|
|
||||||
header('Content-Type: '. $mime);
|
|
||||||
|
|
||||||
readfile($staticFilePath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
* Define the ~/.valet path as a constant.
|
* Define the ~/.valet path as a constant.
|
||||||
*/
|
*/
|
||||||
define('VALET_HOME_PATH', $_SERVER['HOME'].'/.valet');
|
define('VALET_HOME_PATH', $_SERVER['HOME'].'/.valet');
|
||||||
define('VALET_SERVER_PATH', '/server.php');
|
define('VALET_SERVER_PATH', realpath(__DIR__ . '/../../server.php'));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Output the given text to the console.
|
* Output the given text to the console.
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import VALET_HOME_PATH/Caddy/*
|
import VALET_HOME_PATH/Caddy/*
|
||||||
|
|
||||||
:80 {
|
:80 {
|
||||||
|
root /
|
||||||
|
internal /dev/null
|
||||||
|
|
||||||
fastcgi / /var/run/fpm-valet.socket php {
|
fastcgi / /var/run/fpm-valet.socket php {
|
||||||
index VALET_SERVER_PATH
|
index VALET_SERVER_PATH
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ http://VALET_SITE:80 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
https://VALET_SITE:443 {
|
https://VALET_SITE:443 {
|
||||||
|
root /
|
||||||
|
internal /dev/null
|
||||||
|
|
||||||
tls VALET_CERT VALET_KEY
|
tls VALET_CERT VALET_KEY
|
||||||
|
|
||||||
fastcgi / /var/run/fpm-valet.socket php {
|
fastcgi / /var/run/fpm-valet.socket php {
|
||||||
|
|||||||
Reference in New Issue
Block a user