Things to Consider when application hosting on AppFog

You are viewing revision #6 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version.

next (#7) »

I faced many issues when hosted our company website on AppFog.

Problems:

  • Server load balancer IP instead of User's IP
  • All Logged in user's session outs automatically
  • Yii Assets Manager don't publishes every thing correctly, Some time for same files Apache/Yii reports 404
  • Database Username and Password changes automatically.

Your should consider these things to get up and running application without lack...

Get User IP Address

Fix: Server load balancer IP instead of User's IP

$user_ip_all = $user_ip = Yii::app()->getRequest()->getUserHostAddress();

// GETTING USER IP ADDRESS IF HOSTED ON AWS:AppFog Application sitting
// behind load balancer
// Getting User's all IP address because sometimes it comes like:
// 192.168.1.65, 182.74.58.28, 127.0.0.1
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])
        //
        && ($user_ip = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])) !== NULL
        //
        && count($user_ip) >= 2
) {
    // Removing Last one: 127.0.0.1
    $keys = array_keys($user_ip);
    unset($user_ip[end($keys)]);

    // Again joining to string except 127.0.0.1
    $user_ip_all = implode(',', $user_ip);
    //  Getting just the first one
    $user_ip = (string) $user_ip[0];
} elseif (is_array($user_ip)) {
    $user_ip = $user_ip[0];
} elseif (is_string($user_ip) && strpos($user_ip, ',') > 0) {
    $user_ip = explode(',', $user_ip);
    $user_ip = $user_ip[0];
}

Keep User sessions persist after application updates

Fix: All Logged in user's session outs automatically

Set a application id to config in file config/main.php. e.g:

return array(
    'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',
    'name' => 'People Matters',
    'id' => 'people_matters_media_pvt_ltd',  // <== YOU SHOULD ADD THIS
    // ...
);

This was suggested by AppFog support team

Set Appropriate permission on assets directory

Well this is more complicated. Till now I haven't found any better solution because AppFog doesn't provides SSH access to server. So, we can't fix it nor debug in better way.

For now I've just fixed for jquery.yiiactiveform.js. If server reports 404 for this file then some client side validation don't happens.

Find your jquery.yiiactiveform.js file inside /assets/* directory and copy it to /assets and add below script to template at POS_END where ever you have CActiveForm widget:

<script type="text/javascript">
    ;(function(d,s){
        if(typeof $.fn.yiiactiveform==='function')return;
        var j=d.createElement(s);j.type='text/javascript';
        j.src="<?php echo Yii::app()->homeUrl; ?>/assets/js/jquery.yiiactiveform.js";
        var p=d.getElementsByTagName('script')[0].parentNode.insertAfter(j, p);
    })(document, 'script');
</script>
Take care of Database Triggers

Database Username and Password changes automatically in a while. It's not necessary but some times it happens. In my case it got changed and server started giving error. Because I had created some Triggers for tables. Actually MySQL creates a definer for Triggers and Procedures. And that trigger can only executes when the definer(user) has logged in or you should give permissions to all user.

So, in that case you should re-create triggers and procedures again.

Error was reported to me:

CDbCommand failed to execute the SQL statement: SQLSTATE[HY000]: General error: 1449 The user specified as a definer ('xxx------xxx'@'%') does not exist. The SQL statement executed was: UPDATE `user` SET ...
All above fix/patch I've discovered during developing:  
[https://www.peoplematters.in](https://www.peoplematters.in)
1 0
1 follower
Viewed: 7 968 times
Version: Unknown (update)
Category: Tips
Written by: VINAY Kr. SHARMA
Last updated by: VINAY Kr. SHARMA
Created on: Feb 24, 2015
Last updated: 9 years ago
Update Article

Revisions

View all history