{"id":715,"date":"2017-05-03T11:49:53","date_gmt":"2017-05-03T16:49:53","guid":{"rendered":"http:\/\/beta.hthirukkumaran.com\/?p=715"},"modified":"2017-05-03T11:49:53","modified_gmt":"2017-05-03T16:49:53","slug":"hosting-codeigniter-on-google-app-engine","status":"publish","type":"post","link":"https:\/\/hthirukkumaran.com\/index.php\/hosting-codeigniter-on-google-app-engine\/","title":{"rendered":"Hosting CodeIgniter on Google App Engine"},"content":{"rendered":"<p>CodeIgniter is a PHP based MVC framework. It is the first PHP MVC framework I learnt while\u00a0learning PHP. My like-minded friends and I developed a small application in CodeIgniter. We didn&#8217;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.<\/p>\n<h2>Sessions<\/h2>\n<p>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.\u00a0Use the db script below to create the sessions table for CodeIgniter. The detailed documentation is available on <a href=\"https:\/\/codeigniter.com\/user_guide\/libraries\/sessions.html?highlight=ci_session#database-driver\" target=\"_blank\" rel=\"noopener\">CodeIgniter website<\/a>.<\/p>\n<p>&nbsp;<\/p>\n<div class=\"tag-box tag-box-v1 margin-bottom-40\">\n<pre>CREATE TABLE IF NOT EXISTS `ci_sessions` (\n        `id` varchar(128) NOT NULL,\n        `ip_address` varchar(45) NOT NULL,\n        `timestamp` int(10) unsigned DEFAULT 0 NOT NULL,\n        `data` blob NOT NULL,\n        KEY `ci_sessions_timestamp` (`timestamp`)\n);\n\n<\/pre>\n<\/div>\n<p>Modify the config.php to use database for sessions<\/p>\n<div class=\"tag-box tag-box-v1 margin-bottom-40\">\n<pre>$config['sess_driver'] = 'database';\n$config['sess_save_path'] = 'ci_sessions';\n<\/pre>\n<\/div>\n<h2>Error Logging<\/h2>\n<p>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.<\/p>\n<p>&nbsp;<\/p>\n<h2>Connecting to database<\/h2>\n<div class=\"tag-box tag-box-v1 margin-bottom-40\">\n<pre>$db['default'] = array(\n\t'dsn'\t=&gt; 'mysql:unix_socket=\/cloudsql\/dbname:datacenter-region:dbusername;dbname=database_name',\n\t'username' =&gt; 'dbusername',\n\t'password' =&gt; 'dbpassword',\n\t'database' =&gt; 'database_name',\n\t'dbdriver' =&gt; 'pdo',\n<\/pre>\n<\/div>\n<p>The db driver must be PDO other types of drivers required extensive troubleshooting and refactoring in the application.<\/p>\n<p>If you follow these three tips you should be able to write a website in CodeIgniter that will be App Engine compatible.<\/p>\n<p>If you need help or suggestions for your products you can get it touch with me <a href=\"..\/contact\">here<\/a> or you can post your question to my social accounts below.<\/p>\n<div class=\"panel panel-blue\">\n<div class=\"panel-heading\">\n<h3 class=\"panel-title\" style=\"color: white;\">Credits and References<\/h3>\n<\/div>\n<div class=\"panel-body\">\n<ul>\n<li><a href=\"https:\/\/twitter.com\/Vijayrajarath93\" target=\"_blank\" rel=\"noopener\">Vijay Rajarathinam<\/a>,\u00a0<a href=\"https:\/\/twitter.com\/RobinorRobby\" target=\"_blank\" rel=\"noopener\">Robert Robinson<\/a>,\u00a0<a href=\"https:\/\/twitter.com\/nelson900337744\" target=\"_blank\" rel=\"noopener\">Nelson Albert<\/a><\/li>\n<li><a href=\"https:\/\/codeigniter.com\/user_guide\/libraries\/sessions.html?highlight=ci_session#database-driver\" target=\"_blank\" rel=\"noopener\">CodeIgniter &#8211; Session DB Configuration<\/a><\/li>\n<\/ul>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>CodeIgniter is a PHP based MVC framework. It is the first PHP MVC framework I learnt while\u00a0learning PHP. My like-minded friends and I developed a small application in CodeIgniter. We didn&#8217;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. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":""},"categories":[4],"tags":[],"_links":{"self":[{"href":"https:\/\/hthirukkumaran.com\/index.php\/wp-json\/wp\/v2\/posts\/715"}],"collection":[{"href":"https:\/\/hthirukkumaran.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hthirukkumaran.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hthirukkumaran.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hthirukkumaran.com\/index.php\/wp-json\/wp\/v2\/comments?post=715"}],"version-history":[{"count":0,"href":"https:\/\/hthirukkumaran.com\/index.php\/wp-json\/wp\/v2\/posts\/715\/revisions"}],"wp:attachment":[{"href":"https:\/\/hthirukkumaran.com\/index.php\/wp-json\/wp\/v2\/media?parent=715"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hthirukkumaran.com\/index.php\/wp-json\/wp\/v2\/categories?post=715"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hthirukkumaran.com\/index.php\/wp-json\/wp\/v2\/tags?post=715"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}