6

I just created a new Symfony 3.4 application. Per Symfony's docs, I can server my application using PHP's built-in web-server by running

php bin/console server:start

However -- this appears to run the application in development mode. This means exception printing is on, the developer toolbar shows up, etc.

Is there a way to use the built-in web server with Symfony's production mode? This isn't to serve an application to the public (which wouldn't be a good idea) but instead because I want to test an issue that may only crop up in production mode.

6
  • How about php bin/console server:start --env=prod? Commented Feb 17, 2018 at 0:20
  • 2
    You can manually edit app_dev.php to switch it to PROD. Comment out Debug::enable() and change it to prod, e.g., $kernel = new AppKernel('prod', false); Commented Feb 17, 2018 at 0:20
  • Thank you for the suggestion @revo -- however, that led to a There are no commands defined in the "server" namespace exception, and the server did not start. Which is a weird error message, but [shoulder shrug emoji guy] Commented Feb 17, 2018 at 0:25
  • Ok what if you change the order php bin/console --env=prod server:start? Commented Feb 17, 2018 at 0:27
  • 1
    Just for info, the webserver bundle is only enabled for dev. You can see that in AppKernel.php or bundles.php. So specifying the environment is basically a dead end. So you can fool around with app.php but what you really should do to get a proper test is to go ahead and configure an apache or nginx server for production testing. Commented Feb 17, 2018 at 1:00

4 Answers 4

8

Instead of symfony's server command you can run PHP's built-in web-server directly with the following command:

php -S localhost:8000 -t web/ app.php

This assumes that you are currently in your project directory and that the web/ directory hosts your app.php file.

-t denotes the document root. In this example that is web/.

app.php is specified as the router script and will handle your request.

More info on PHP's built-in web server command

Now when you go to localhost:8000 it will be serving your Symfony project in Production mode.

This doesn't run the server in the background, but you can easily search google for how to do that.

Sign up to request clarification or add additional context in comments.

1 Comment

for me this one works: php -S localhost:8000 -t web/ web/app.php
5

If you are using Symfony 4 you need to enable the server bundle for all environments in the bundles.php file. By default it's only turned on for dev.

<?php

return [
    // ...
    Symfony\Bundle\WebServerBundle\WebServerBundle::class => ['all' => true],
];

Comments

2
php -S localhost:8000 -t web/ web/app.php

This worked for me. Otherwise,this error will be thrown: PHP Fatal error: Unknown: Failed opening required 'app.php' (include_path='.:/usr/local/lib/php') in Unknown on line 0

2 Comments

I don't really see how your answer differ from the one accepted and answered two years ago. If you have something valuable to bring in to an existing answer, you'll have the privilege to comment on posts with when you have a little more réputation.
@β.εηοιτ.βε None of the other answers actually have the correct answer. hcoat's answer is almost correct, but the real answer is within Pavel Alazankin's comment to that answer. This answer is the real working solution.
1

Yea, you specify the app.php on the url you enter in the browser, so something like this

mysite.dev/app.php/login

Or

localhost:8000/app.php/login

By default it will automatically use app_dev.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.