diff --git a/src/Symfony/Bundle/WebServerBundle/Command/ServerRunCommand.php b/src/Symfony/Bundle/WebServerBundle/Command/ServerRunCommand.php
index de5a8c5b3c5ff..e306a65925f87 100644
--- a/src/Symfony/Bundle/WebServerBundle/Command/ServerRunCommand.php
+++ b/src/Symfony/Bundle/WebServerBundle/Command/ServerRunCommand.php
@@ -31,13 +31,15 @@ class ServerRunCommand extends Command
{
private $documentRoot;
private $environment;
+ private $pidFileDirectory;
protected static $defaultName = 'server:run';
- public function __construct(string $documentRoot = null, string $environment = null)
+ public function __construct(string $documentRoot = null, string $environment = null, string $pidFileDirectory = null)
{
$this->documentRoot = $documentRoot;
$this->environment = $environment;
+ $this->pidFileDirectory = $pidFileDirectory;
parent::__construct();
}
@@ -129,7 +131,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
try {
- $server = new WebServer();
+ $server = new WebServer($this->pidFileDirectory);
$config = new WebServerConfig($documentRoot, $env, $input->getArgument('addressport'), $input->getOption('router'));
$message = sprintf('Server listening on http://%s', $config->getAddress());
diff --git a/src/Symfony/Bundle/WebServerBundle/Command/ServerStartCommand.php b/src/Symfony/Bundle/WebServerBundle/Command/ServerStartCommand.php
index 55bf7a7c650ce..c481856b291b1 100644
--- a/src/Symfony/Bundle/WebServerBundle/Command/ServerStartCommand.php
+++ b/src/Symfony/Bundle/WebServerBundle/Command/ServerStartCommand.php
@@ -31,13 +31,15 @@ class ServerStartCommand extends Command
{
private $documentRoot;
private $environment;
+ private $pidFileDirectory;
protected static $defaultName = 'server:start';
- public function __construct(string $documentRoot = null, string $environment = null)
+ public function __construct(string $documentRoot = null, string $environment = null, string $pidFileDirectory = null)
{
$this->documentRoot = $documentRoot;
$this->environment = $environment;
+ $this->pidFileDirectory = $pidFileDirectory;
parent::__construct();
}
@@ -133,7 +135,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->getApplication()->setDispatcher(new EventDispatcher());
try {
- $server = new WebServer();
+ $server = new WebServer($this->pidFileDirectory);
if ($server->isRunning($input->getOption('pidfile'))) {
$io->error(sprintf('The web server has already been started. It is currently listening on http://%s. Please stop the web server before you try to start it again.', $server->getAddress($input->getOption('pidfile'))));
diff --git a/src/Symfony/Bundle/WebServerBundle/Command/ServerStatusCommand.php b/src/Symfony/Bundle/WebServerBundle/Command/ServerStatusCommand.php
index 95e8122a2d318..bedb31a678461 100644
--- a/src/Symfony/Bundle/WebServerBundle/Command/ServerStatusCommand.php
+++ b/src/Symfony/Bundle/WebServerBundle/Command/ServerStatusCommand.php
@@ -30,6 +30,15 @@ class ServerStatusCommand extends Command
{
protected static $defaultName = 'server:status';
+ private $pidFileDirectory;
+
+ public function __construct(string $pidFileDirectory = null)
+ {
+ $this->pidFileDirectory = $pidFileDirectory;
+
+ parent::__construct();
+ }
+
/**
* {@inheritdoc}
*/
@@ -64,7 +73,7 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
- $server = new WebServer();
+ $server = new WebServer($this->pidFileDirectory);
if ($filter = $input->getOption('filter')) {
if ($server->isRunning($input->getOption('pidfile'))) {
list($host, $port) = explode(':', $address = $server->getAddress($input->getOption('pidfile')));
diff --git a/src/Symfony/Bundle/WebServerBundle/Command/ServerStopCommand.php b/src/Symfony/Bundle/WebServerBundle/Command/ServerStopCommand.php
index f86df7ff00fd9..9287c2196c0a4 100644
--- a/src/Symfony/Bundle/WebServerBundle/Command/ServerStopCommand.php
+++ b/src/Symfony/Bundle/WebServerBundle/Command/ServerStopCommand.php
@@ -28,6 +28,15 @@ class ServerStopCommand extends Command
{
protected static $defaultName = 'server:stop';
+ private $pidFileDirectory;
+
+ public function __construct(string $pidFileDirectory = null)
+ {
+ $this->pidFileDirectory = $pidFileDirectory;
+
+ parent::__construct();
+ }
+
/**
* {@inheritdoc}
*/
@@ -55,7 +64,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
try {
- $server = new WebServer();
+ $server = new WebServer($this->pidFileDirectory);
$server->stop($input->getOption('pidfile'));
$io->success('Stopped the web server.');
} catch (\Exception $e) {
diff --git a/src/Symfony/Bundle/WebServerBundle/DependencyInjection/WebServerExtension.php b/src/Symfony/Bundle/WebServerBundle/DependencyInjection/WebServerExtension.php
index bf08a2bac9c97..bf263e1bb654e 100644
--- a/src/Symfony/Bundle/WebServerBundle/DependencyInjection/WebServerExtension.php
+++ b/src/Symfony/Bundle/WebServerBundle/DependencyInjection/WebServerExtension.php
@@ -31,6 +31,12 @@ public function load(array $configs, ContainerBuilder $container)
$container->getDefinition('web_server.command.server_run')->replaceArgument(0, $publicDirectory);
$container->getDefinition('web_server.command.server_start')->replaceArgument(0, $publicDirectory);
+ $pidFileDirectory = $this->getPidFileDirectory($container);
+ $container->getDefinition('web_server.command.server_run')->replaceArgument(2, $pidFileDirectory);
+ $container->getDefinition('web_server.command.server_start')->replaceArgument(2, $pidFileDirectory);
+ $container->getDefinition('web_server.command.server_stop')->replaceArgument(0, $pidFileDirectory);
+ $container->getDefinition('web_server.command.server_status')->replaceArgument(0, $pidFileDirectory);
+
if (!class_exists(ConsoleFormatter::class)) {
$container->removeDefinition('web_server.command.server_log');
}
@@ -54,4 +60,16 @@ private function getPublicDirectory(ContainerBuilder $container)
return $kernelProjectDir.'/'.$publicDir;
}
+
+ private function getPidFileDirectory(ContainerBuilder $container): string
+ {
+ $kernelCacheDir = $container->getParameter('kernel.cache_dir');
+ $environment = $container->getParameter('kernel.environment');
+
+ if (basename($kernelCacheDir) !== $environment) {
+ return $container->getParameter('kernel.project_dir');
+ }
+
+ return \dirname($container->getParameter('kernel.cache_dir'));
+ }
}
diff --git a/src/Symfony/Bundle/WebServerBundle/Resources/config/webserver.xml b/src/Symfony/Bundle/WebServerBundle/Resources/config/webserver.xml
index 047e2cb483feb..bb76b22098999 100644
--- a/src/Symfony/Bundle/WebServerBundle/Resources/config/webserver.xml
+++ b/src/Symfony/Bundle/WebServerBundle/Resources/config/webserver.xml
@@ -10,20 +10,24 @@
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: