Skip to content

Conversation

grigoryvp
Copy link
Contributor

Phabricator requires mod_rewrite rule to emulate "routing"
interface between web server and PHP aplication. Since PHP 5.4 where
is built-in web server that can be invoked with
"PHP -S 127.0.0.1:8000", but since it's very simple it don't have
mod_rewrite functionality. But it have routing functionality if .php
file is given via command-line - so this simple fix allows to
use PHP 5.4+ built-in web server to start Phabricator. Useful for
hacking, developing and testing. Use like this:

"php -S 127.0.0.1:8000 ~/Documents/phabricator/webroot/ ~/Documents/phabricator/webroot/index.php"

Phabricator requires mod_rewrite rule to emulate "routing"
interface between web server and PHP aplication. Since PHP 5.4 where
is built-in web server that can be invoked with
"PHP -S 127.0.0.1:8000", but since it's very simple it don't have
mod_rewrite functionality. But it have routing functionality if .php
file is given via command-line - so this simple fix allows to
use PHP 5.4+ built-in web server to start Phabricator. Useful for
hacking, developing and testing. Use like this:

"php -S 127.0.0.1:8000 ~/Documents/phabricator/webroot/ ~/Documents/phabricator/webroot/index.php"
@epriestley
Copy link
Member

The f()['idx'] syntax will break versions of PHP prior to 5.4, can you remove that? We currently support versions from PHP 5.2 forward, at least theoretically.

(And, for consistency, also remove the inner space in parens and brackets -- see the style guide here: http://www.phabricator.com/docs/phabricator/article/PHP_Coding_Standards.html)

Looks good otherwise. Thanks!

(You can detect some of these problems automatically, and sometimes fix them automatically, by running "arc lint". Here's the current output for this patch:)

$ arc lint --never-apply-patches 
>>> Lint for webroot/index.php:


   Warning  (XHP25) Spaces Inside Parentheses
    Parentheses should hug their contents.

              57 if (!isset($_REQUEST['__path__'])) {
              58   if (php_sapi_name() == 'cli-server') {
              59     // Compatibility with PHP 5.4+ built-in web server.
    >>> -     60     $_REQUEST['__path__'] = parse_url( $_SERVER['REQUEST_URI'] )[ 'path' ];
        +            $_REQUEST['__path__'] = parse_url($_SERVER['REQUEST_URI'] )[ 'path' ];
              61   } else {
              62     phabricator_fatal_config_error(
              63       "__path__ is not set. Your rewrite rules are not configured correctly.");

   Warning  (XHP25) Spaces Inside Parentheses
    Parentheses should hug their contents.

              57 if (!isset($_REQUEST['__path__'])) {
              58   if (php_sapi_name() == 'cli-server') {
              59     // Compatibility with PHP 5.4+ built-in web server.
    >>> -     60     $_REQUEST['__path__'] = parse_url( $_SERVER['REQUEST_URI'] )[ 'path' ];
        +            $_REQUEST['__path__'] = parse_url( $_SERVER['REQUEST_URI'])[ 'path' ];
              61   } else {
              62     phabricator_fatal_config_error(
              63       "__path__ is not set. Your rewrite rules are not configured correctly.");

@grigoryvp
Copy link
Contributor Author

Fixed both PHP compatibility and code style.

@epriestley
Copy link
Member

Thanks!

epriestley pushed a commit that referenced this pull request Jul 25, 2012
Added compatibility with PHP 5.4+ built-in web server.
@epriestley epriestley merged commit 28618b3 into phacility:master Jul 25, 2012
@tokiloki
Copy link

tokiloki commented Sep 6, 2012

After running

php -S localhost:8000 facebook/phabricator/webroot/ facebook/phabricator/webroot/index.php

opening localhost:8000 in browser gives me error

[Thu Sep  6 12:54:42 2012] PHP Warning:  Unknown: failed to open stream: No such file or directory in     Unknown on line 0
[Thu Sep  6 12:54:42 2012] PHP Fatal error:  Unknown: Failed opening required 'facebook/phabricator/webroot/' (include_path='.:/usr/share/pear:/usr/share/php') in Unknown on line 0

What am I doing wrong?

@grigoryvp
Copy link
Contributor Author

Ah, my bad in comment: webroot is defined via "-t" command-line arg, so it must be:
php -S localhost:8000 -t facebook/phabricator/webroot/ facebook/phabricator/webroot/index.php

Also, make sure that paths are correct. I'm not sure that relative paths (that dn't start with "/") are correct :)

@tokiloki
Copy link

tokiloki commented Sep 6, 2012

Thanks. It is working great with "-t".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants