Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 with PHP 5.4 built-in server

Tags:

php

I'm trying to work with Symfony2 with the new PHP 5.4 and its built-in server. I downloaded Symfony2 and unziped it on my server and added this router.php file like mentioned here:

<?php

    if (isset($_SERVER['SCRIPT_FILENAME'])) {
        return false;
    } else {
        require 'Symfony/web/app.php';
    }

?>

The webserver itself works because if I replace router.php with something simple like phpinfo(); it outputs it correct but with the mentioned router.php script the site remains white/blank. If I open developer tools it returns 500 Server error.

I start the server like that:

/home/php54/php -S 0.0.0.0:88 router.php

On my shell I have no output of a error message.

like image 867
Poru Avatar asked Mar 02 '12 18:03

Poru


People also ask

What is PHP built in server?

Built-in web server ¶ This web server is designed to aid application development. It may also be useful for testing purposes or for application demonstrations that are run in controlled environments. It is not intended to be a full-featured web server.

How stop PHP built in server?

You will now see some feedback in your terminal letting you know that your PHP server is listening for traffic on http://mysite.local:8080. To stop the server simply hit Ctrl+C in your running terminal.

Does PHP have a Web server?

PHP server is a collection of fundamental tools that make it easy to host at local servers so you can develop or built Web Apps at your computer. If you're are doing development on web application, having a PHP server is perfect way, the most perfect way to start.


1 Answers

/home/php54/php -S 0.0.0.0:88 router.php

You are trying to run server on privileged port, so either change port or run this as privileged user (not recommended).

Also you have modified router script and I think you've messed up with file paths. You are not specifying docroot in your command, so your current directory is your docroot (so it should be your project's web/ directory). But then path to the front controller in router.php is wrong (Symfony/web/app.php).

You should really follow carefully instructions from my blog post. So:

  • change your current directory to your project's web/ directory,
  • download router script: wget https://raw.github.com/gist/1507820/b9583ab7f7f5e0e4e29806c38c6c361220b6468f/router.php,
  • run server: php -S 0.0.0.0:8000 router.php.

This should work.

You can also try patch from my pull request which adds simple command that just runs built-in PHP server.

like image 187
Michał Pipa Avatar answered Oct 09 '22 13:10

Michał Pipa