CodeIgniter is a PHP based MVC framework. It is the first PHP MVC framework I learnt while learning PHP. My like-minded friends and I developed a small application in CodeIgniter. We didn’t develop it with a goal to host it on App Engine. After we used this application we decided to host it on App Engine. The code as such worked for most part on App Engine without much changes. There were 3 areas where we faced issues. I am outlining these 3 issues.

Sessions

By default CodeIgniter uses files to store session details this will not work in App Engine since you know that any alteration to existing files in App Engine should be done by creating a new version of the app in the App Engine. Use the db script below to create the sessions table for CodeIgniter. The detailed documentation is available on CodeIgniter website.

 

CREATE TABLE IF NOT EXISTS `ci_sessions` (
        `id` varchar(128) NOT NULL,
        `ip_address` varchar(45) NOT NULL,
        `timestamp` int(10) unsigned DEFAULT 0 NOT NULL,
        `data` blob NOT NULL,
        KEY `ci_sessions_timestamp` (`timestamp`)
);

Modify the config.php to use database for sessions

$config['sess_driver'] = 'database';
$config['sess_save_path'] = 'ci_sessions';

Error Logging

You can use either Google Cloud error logging or log all errors in db using custom function in your CodeIgniter app. The default function to write to files will not work on App Engine.

 

Connecting to database

$db['default'] = array(
	'dsn'	=> 'mysql:unix_socket=/cloudsql/dbname:datacenter-region:dbusername;dbname=database_name',
	'username' => 'dbusername',
	'password' => 'dbpassword',
	'database' => 'database_name',
	'dbdriver' => 'pdo',

The db driver must be PDO other types of drivers required extensive troubleshooting and refactoring in the application.

If you follow these three tips you should be able to write a website in CodeIgniter that will be App Engine compatible.

If you need help or suggestions for your products you can get it touch with me here or you can post your question to my social accounts below.