Google App Engine has recently announced its support for PHP, and as a CodeIgniter developer I decided to test its functionality on this great platform.
I’ll be testing it with the newly launched native PHP support, and using the most interesting Google Cloud products for a PHP developer: Google Cloud SQL, Cloud Storage, Memcache and AppEngine PHP-SDK Libraries.
Installing AppEngine for PHP and CodeIgniter
The first steps will be to get a copy of the PHP SDK. It comes in different flavours: Linux, OS X and Windows. Check them out here. You will also get bundled a local python webserver, and an uploading tool.
Next, we’ll get the latest version of the CodeIgniter framework directly from GitHub (2.1.4 will be used for this post) Link here.
Putting everything together
To allow an application to run on AppEngine, we need to create app.yaml file in the root directory of the application.
application: codeigniter-dev version: 1 runtime: php api_version: 1 threadsafe: false handlers: - url: /favicon.ico static_files: /favicon.ico upload: /favicon.ico expiration: 30d # make the user_guide a static dir! # you dont need to include it in every project you make - url: /user_guide static_dir: user_guide - url: /.* script: index.php
codeigniter-dev is our application name and you’ll need to change it by the one you have chosen for your application before uploading it.
After this first configuration step, we can launch the application by using the Local Web server included in the App Engine SDK, or we could just use our preferred Web Server (In my case, I run a local LAMPP environment.
First upload to Google App Engine
If you don’t have done it before, we invite you to create an App Engine application (https://appengine.google.com/) and to subscribe to the App Engine for PHP beta program (https://gaeforphp.appspot.com/) in order to allow the upload of a PHP application to your App Engine instance. Indeed, the PHP runtime that has been announced at the last Google I/O conference is still in beta and Google authorizes progressively its roll out.
We then upload the application to the App Engine using the following command that you need to adapt to your environment:
../google_appengine/appcfg.py -R --oauth2 update ./
And the answer is:
11:26 AM Host: appengine.google.com 11:26 AM Application: codeigniter-dev; version: 1 11:26 AM Starting update of app: codeigniter-dev, version: 1 11:26 AM Getting current resource limits. 11:26 AM Scanning files on local disk. 11:26 AM Cloning 184 application files. 11:26 AM Uploading 184 files and blobs. 11:26 AM Uploaded 184 files and blobs 11:26 AM Compilation starting. 11:26 AM Compilation completed. 11:26 AM Starting deployment. 11:26 AM Checking if deployment succeeded. 11:26 AM Deployment successful. 11:26 AM Checking if updated app version is serving. 11:26 AM Completed update of app: codeigniter-dev, version: 1
We then try to access the application through the
codeigniter-dev.appspot.com url, and voilá, almost no hassles: Behold CodeIgniter natively working on Google AppEngine on http://codeigniter-dev.appspot.com/
Just a small PHP warning saying that php_sapi_name() function isn’t working. I did a quick Google search, and it’s indeed disabled by default by Google, and it can be enabled by uploading a custom php.ini file:
google_app_engine.enable_functions = "php_sapi_name"
So I create the file, add just that line, re-upload, re-fresh the screen and:
It’s working and I’ll leave it this way for now. My next goal, which I’ll cover in future posts will be to thoroughly test each and every function!