Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 879
Fradé Avatar asked Dec 04 '19 11:12

Fradé


People also ask

How to start local server with Symfony 5?

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:// . Inside the terminal, move into your project directory and run symfony serve . A local webserver will start; by default on https://localhost:8000/ .

How do I know what version of Symfony I have?

If you have file system access to the project Look inside the file for a line like: const VERSION = '5.0. 4'; that's the Symfony version number.

What is Symfony server?

The Symfony server traverses the directory structure up to the root directory, so you can create a . php-version file in some parent directory to set the same PHP version for a group of projects under that directory. Run the command below if you don't remember all the PHP versions installed on your computer: 1 2 3 4 5.


2 Answers

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.

like image 186
yivi Avatar answered Nov 02 '22 23:11

yivi


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.

like image 33
Dirk J. Faber Avatar answered Nov 03 '22 00:11

Dirk J. Faber