Running Magento in PHP 5.4's built-in web server

Whilst this isn't a good idea for a production store, if you want to just experiment or develop locally, this works just fine.

Instructions for Debian

cat >> /etc/apt/sources.lst <<EOF
deb squeeze-php54 all
deb-src squeeze-php54 all

wget -qO - | apt-key add -
apt-get update
apt-get install php5-cli php5-mysqlnd php5-mcrypt php5-common php-pear php5-dev php5-mysql php5-curl php5-mcrypt php5-gd php5-cli php5-xsl php5-imagick

Then make a simple router, that mimicked the rules in a stock Magento .htaccess.

Put this in router.php in your Magento base directory.


  if (preg_match('#^/api/rest#', $_SERVER["REQUEST_URI"])) {
      $_SERVER["REQUEST_URI"] = 'api.php?type=rest';
  } elseif (preg_match('#^/(media|skin|js)#', $_SERVER["REQUEST_URI"])) {
      return false;
  } elseif (file_exists(".".$_SERVER["REQUEST_URI"]))  {
      return false;
  } else {
      include_once 'index.php';


Then start the PHP server and point it at router.php (the file from above).

php -S router.php

That's it - now just point your web browser at your new PHP web server.

  • An interesting issue with this has cropped up - form data in request headers isn't being passed through the custom router.php file; a side-effect of this is invalid form key errors in admin. Any thoughts?

    • sonassi

      Hmmm. I'd have to have a look into it to see why. I would imagine it just being something pretty trivial. I assume `var_dump($_REQUEST)` yields nothing? How about `$_GET` or `$_POST`?


      • Form data is in the request header (according to Chrome). But there is no corresponding data in $_REQUEST:

        array(1) {
        ["isAjax"]=> string(4) "true"

        or in $_POST:

        array(0) {