How to start local server with symfony 5 or downgrade version to 4.4?
Asked Answered
R

6

15

I started a new project in new Symfony 5 and i can't open my local server.

On Symfony 4.4 the command PHP bin/console server:run is OK,

But with Symfony 5 the command appears not to be defined...

C:\Users\Chris\Code\api-test> php bin/console server:run
Command "server:run" is not defined.
Do you want to run "server:dump" instead?  (yes/no) [no]:

So how to downgrade or start the local server?

Refugio answered 4/12, 2019 at 11:2 Comment(1)
This command is deprecated from Symfony 4.4 and has been removed on Symfony 5 read here, you can use Symfony Local Web Server instead. Please note that the link you provide above is for actual web server application configuration, which can be used in production. This command is for development only.Geneva
Z
37

The Web Server Bundle is not included with Symfony 5.

But you can simply require it and install it separately.

E.g.:

composer require symfony/web-server-bundle 4.4

It is important that you specify the version (4.4), because otherwise it will attempt to install version 5 (which does not exist, and it will fail).

After that you'll be able to run bin/console server:run as you used to do.


Otherwise, you may use the Symfony CLI as well. This is an executable binary which includes the Symfony Server by default. Then you may run symfony server:start or the better know alias symfony serve to start the local webserver.

Read more about Symfony's server here.


You can also use the built-in web server in the PHP runtime. Just go to your project's root directory and run:

php -S localhost:8000 -t public/

It's not a fully featured webserver, but for developing purposes it is usually more than enough.

Zohar answered 8/1, 2020 at 9:29 Comment(3)
This should be markes as the right answer. Thanks palMolybdenite
should be noted that server:run provides no significative advantage over builtin php's web server, and server:start does not run with symfony 5.*+Midian
how change symfony binary php version? cause now it uses my old PHP version.Starshaped
L
9

For running a local web server you can now use Symfony Client, or simply 'Symfony'.

  1. Download the binary and install it globally.

  2. Open a terminal and run once: symfony server:ca:install. This will install a local SSL certificate authority that allows you to run the local webserver on https://.

  3. Inside the terminal, move into your project directory and run symfony serve. A local webserver will start; by default on https://localhost:8000/.

If you wish to run the webserver on another port you can use symfony serve --port=8080 (in this case port 8080). For the most useful commands Symfony Client has to offer, simply run symfony. To see all available commands run symfony help.

Litre answered 4/12, 2019 at 20:32 Comment(0)
D
8

I am using symfony 5 and I just replace the former command php bin/console server:run" by php -S localhost:3000 -t public and it works in a similar way.

-t public to indicate the targeted file.

Deprecatory answered 24/1, 2020 at 8:19 Comment(1)
Thanks. This solution is working on Symfony 5Sibilant
L
1
  1. php -S localhost:9000 -t public | PHP Inbuild Server / -t set to the public dir

  2. php bin/console server:run | Only for Symfony 4.* and below

  3. symfony serve | Symfony Server symfony ServeBundle

  • To run symfony serve you must first install the ServerBundle: composer require symfony/web-server-bundle
  • The really really really cool think is that you can use https out of the box. You need only run symfony server:ca:install.
Larrabee answered 24/3, 2022 at 8:14 Comment(0)
H
0

I am using symfony 5,4 and I just use command

$ symfony serve
Hunan answered 4/12, 2019 at 11:2 Comment(2)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Coax
Please share more details. This command was already provided in some other answers. Is there any need to duplicate them? If you want to share new insights, please do so by adding them to your answerYancey
M
-1

You need to install symfony by running theses commands: cd my-project composer require symfony/web-server-bundle --dev And run the server php bin/console server:run

Mcilroy answered 16/12, 2019 at 3:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.