mirror of
https://github.com/laravel/valet.git
synced 2026-02-07 17:10:05 +01:00
use caddy as the server into php
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
vendor/
|
vendor/
|
||||||
composer.lock
|
composer.lock
|
||||||
|
error.log
|
||||||
|
|||||||
12
Caddyfile
Normal file
12
Caddyfile
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
:80
|
||||||
|
|
||||||
|
fastcgi / 127.0.0.1:9000 php {
|
||||||
|
index server.php
|
||||||
|
}
|
||||||
|
|
||||||
|
rewrite {
|
||||||
|
r .*
|
||||||
|
to /server.php?{query}
|
||||||
|
}
|
||||||
|
|
||||||
|
errors ./error.log
|
||||||
@@ -12,11 +12,9 @@ class LaunchDaemon
|
|||||||
public static function install()
|
public static function install()
|
||||||
{
|
{
|
||||||
$contents = str_replace(
|
$contents = str_replace(
|
||||||
'SERVER_PATH', realpath(__DIR__.'/../server.php'), file_get_contents(__DIR__.'/../stubs/daemon.plist')
|
'VALET_PATH', realpath(__DIR__.'/../'), file_get_contents(__DIR__.'/../stubs/caddyDaemon.plist')
|
||||||
);
|
);
|
||||||
|
|
||||||
$contents = str_replace('PHP_PATH', exec('which php'), $contents);
|
|
||||||
|
|
||||||
file_put_contents('/Library/LaunchDaemons/com.laravel.valetServer.plist', $contents);
|
file_put_contents('/Library/LaunchDaemons/com.laravel.valetServer.plist', $contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
92
src/PhpFpm.php
Normal file
92
src/PhpFpm.php
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Valet;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Symfony\Component\Process\Process;
|
||||||
|
|
||||||
|
class PhpFpm
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Install and configure DnsMasq.
|
||||||
|
*
|
||||||
|
* @param OutputInterface $output
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function install($output)
|
||||||
|
{
|
||||||
|
if (! static::alreadyInstalled()) {
|
||||||
|
static::download($output);
|
||||||
|
}
|
||||||
|
|
||||||
|
static::updateConfiguration();
|
||||||
|
|
||||||
|
static::restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if DnsMasq is already installed.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function alreadyInstalled()
|
||||||
|
{
|
||||||
|
$process = new Process('brew list | grep php70');
|
||||||
|
|
||||||
|
$process->run();
|
||||||
|
|
||||||
|
return in_array('php70', explode(PHP_EOL, $process->getOutput()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download a fresh copy of PHP 7.0 from Brew.
|
||||||
|
*
|
||||||
|
* @param OutputInterface $output
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function download($output)
|
||||||
|
{
|
||||||
|
$output->writeln('<info>PHP 7.0 is not installed, installing it now via Brew...</info> 🍻');
|
||||||
|
|
||||||
|
passthru('sudo -u '.$_SERVER['SUDO_USER'].' brew tap homebrew/dupes');
|
||||||
|
passthru('sudo -u '.$_SERVER['SUDO_USER'].' brew tap homebrew/versions');
|
||||||
|
passthru('sudo -u '.$_SERVER['SUDO_USER'].' brew tap homebrew/homebrew-php');
|
||||||
|
|
||||||
|
$process = new Process('sudo -u '.$_SERVER['SUDO_USER'].' brew install php70');
|
||||||
|
|
||||||
|
$processOutput = '';
|
||||||
|
$process->run(function ($type, $line) use (&$processOutput) {
|
||||||
|
$processOutput .= $line;
|
||||||
|
});
|
||||||
|
|
||||||
|
if ($process->getExitCode() > 0) {
|
||||||
|
$output->write($processOutput);
|
||||||
|
|
||||||
|
throw new Exception('We were unable to install PHP.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$output->writeln('');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the PHP FPM configuration to use the current user.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function updateConfiguration()
|
||||||
|
{
|
||||||
|
quietly('sed -i "" -e "s/^user = \_www/user = '.$_SERVER['SUDO_USER'].'/" /usr/local/etc/php/7.0/php-fpm.d/www.conf');
|
||||||
|
|
||||||
|
quietly('sed -i "" -e "s/^group = \_www/group = staff/" /usr/local/etc/php/7.0/php-fpm.d/www.conf');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restart the PHP FPM process.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function restart()
|
||||||
|
{
|
||||||
|
quietly('sudo brew services restart php70');
|
||||||
|
}
|
||||||
|
}
|
||||||
18
stubs/caddyDaemon.plist
Normal file
18
stubs/caddyDaemon.plist
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>Label</key>
|
||||||
|
<string>com.laravel.valetServer</string>
|
||||||
|
<key>WorkingDirectory</key>
|
||||||
|
<string>VALET_PATH</string>
|
||||||
|
<key>ProgramArguments</key>
|
||||||
|
<array>
|
||||||
|
<string>./caddy</string>
|
||||||
|
</array>
|
||||||
|
<key>RunAtLoad</key>
|
||||||
|
<true/>
|
||||||
|
<key>StandardErrorPath</key>
|
||||||
|
<string>/tmp/com.laravel.valetServer.err</string>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
@@ -32,10 +32,14 @@
|
|||||||
$app->command('install', function ($output) {
|
$app->command('install', function ($output) {
|
||||||
should_be_sudo();
|
should_be_sudo();
|
||||||
|
|
||||||
|
Valet\LaunchDaemon::stop();
|
||||||
|
|
||||||
Valet\LaunchDaemon::install();
|
Valet\LaunchDaemon::install();
|
||||||
|
|
||||||
Valet\Configuration::install();
|
Valet\Configuration::install();
|
||||||
|
|
||||||
|
Valet\PhpFpm::install($output);
|
||||||
|
|
||||||
Valet\DnsMasq::install($output);
|
Valet\DnsMasq::install($output);
|
||||||
|
|
||||||
Valet\LaunchDaemon::restart();
|
Valet\LaunchDaemon::restart();
|
||||||
|
|||||||
Reference in New Issue
Block a user