Getting Slim Framework to work on the Google App Engine PHP Runtime

October 11th 2013

I've been playing round with the Google App Engine Runtime for PHP. In addition to this, I've been using Slim Framework for a lot of projects, both in work, and at home.

I figured I'd give deployment of a Slim Framework to Google App Engine a pop. Unfortunately, I hit a snag.

It seems that Slim checks for a key in the SERVER array called SERVER_PORT.

When you try to load it, you get this error message logged:

Text Snippet:
PHP Fatal error:  Uncaught exception 'ErrorException' with message 'Undefined index: SERVER_PORT' in /base/data/home/apps/s~dev-slim-test-001/1.849007093970901312/library/Slim/Environment.php:149
Stack trace:
#0 /base/data/home/apps/s~dev-slim-test-001/1.849007093970901312/library/Slim/Environment.php(149): Slim\Slim::handleErrors(8, 'Undefined index...', '/base/data/home...', 149, Array)
#1 /base/data/home/apps/s~dev-slim-test-001/1.849007093970901312/library/Slim/Environment.php(76): Slim\Environment->__construct()
#2 /base/data/home/apps/s~dev-slim-test-001/1.849007093970901312/library/Slim/Slim.php(154): Slim\Environment::getInstance()
#3 /base/data/home/apps/s~dev-slim-test-001/1.849007093970901312/library/Slim/Helper/Set.php(228): Slim\Slim->Slim\{closure}(Object(Slim\Helper\Set))
#4 /base/data/home/apps/s~dev-slim-test-001/1.849007093970901312/library/Slim/Helper/Set.php(88): Slim\Helper\Set->Slim\Helper\{closure}(Object(Slim\Helper\Set))
#5 /base/data/home/apps/s~dev-slim-test-001/1.849007093970901312/library/Slim/Helper/Set.php(185): Slim in /base/data/home/apps/s~dev-slim-test-001/1.849007093970901312/library/Slim/Environment.php on line 149

Fortunately, fixing this is kinda easy (yet a bit hackish).

Stick this at the top of your index file:

PHP Code:
<?php
$_SERVER
['SERVER_PORT'] = 80;

Granted, this isn't a long term fix, and when I figure out the ins and outs I'll report back, but for me, right not, this works.

Angelo commented on Oct 20th 2014

Thanks! Saved my day!