Mar 18 10

Ten Step Guide to Install Redmine project management application

by Ali

Having tried several open source project management and bug tracking tools, such as dotProject, mantis  etc, Ruby based Redmine is a good solution.

Redmine is a flexible project management web application written using Ruby on Rails framework. It should run on most Unix, Linux, Mac and Windows systems as long as Ruby & Ruby on Rails and RubyGems are available on that platform.

Step 1

For setting up Redmine on your server, you need SSH access. Log into your shell using putty or any other tool, and create a folder for rails application inside your user account but outside your public root, for instance if you are using CPanel to manage your hosting account, create a folder “rails_apps” inside your “/home” folder beside “/public_html “ folder.

First of all, change your directory to “rails_apps” by typing:

cd /home/your-user-account/rails_apps/

Step 2

Once inside folder “rails_apps”, download and extract the Redmine archive. First get the Redmine files by typing following command at shell:

wget http://rubyforge.org/frs/download.php/69449/redmine-0.9.3.tar.gz

Please make sure that you get the latest version of Redmine. You can get the latest version file path from here http://rubyforge.org/frs/?group_id=1850

Type following command to uncompress the Redmine file:

tar zxvf redmine-0.9.3.tar.gz

It will uncompress and create the directory redmine-0.9.3.

Step 3

Now set up your MySQL Database/user for Redmine installation. After setting up your mysql db and db user, rename “config/database.yml.example” to “config/database.yml” and edit this file in order to configure your database settings for “production” environment. Add your DB information here.

Sample DB information for MySQL

production:
  adapter: mysql
  database: redmine
  host: localhost
  port: 3307
  username: redmine
  password: my_password

Step 4

Change your directory to Redmine by typing following command:

cd  /redmine-0.9.3

Step 5

Redmine stores session data in cookies by default, which requires a secret to be generated. This can be done by running following command but make sure you are under the application root directory:

RAILS_ENV=production rake config/initializers/session_store.rb

Step 6

Create the database structure, by running the following command to create tables and an administrator account under the application root directory:

RAILS_ENV=production rake db:migrate

Step 7

Insert default configuration data in database, by running the following command:

RAILS_ENV=production rake  redmine:load_default_data

This step is optional but highly recommended, as you can define your own configuration from scratch. It will load default roles, trackers, statuses, workflows and enumerations.

Step 8

Test the installation by running WEBrick web server:

ruby script/server webrick -e production -d

Once WEBrick has started, point your browser to http://yourdomain.com:3000/. You should now see the application welcome page. Take special care to run above WEBrick command with –d to detach otherwise when you close the shell window, application will also shut down.

Step 9

Use default administrator account to log in:

login: admin
password: admin

Step 10

To get email notifications, set up SMTP server configuration.

Rename “config/email.yml.example” to “config/email.yml “ and edit this file to adjust your SMTP or pop email settings.

#Outgoing email settings
production:
  delivery_method: :smtp
  smtp_settings:
  address: mail.yourdomain.com
  port: 25
  domain: yourdomain.com
  authentication: :login
  user_name: redmine@yourdomain.com
  password: redmine

Don’t forget to restart the application after any change.

Cheers!

  • Share/Bookmark
Mar 4 10

FBJS Quick Jump Menu for a FBML Facebook Platform App

by Ali

In a FBML Facebook App, your quick jump menu will require a little tweak to work in FBJS properly.
Just change your standard js jump menu from:

<select onchange="goto(this.options[this.selectedIndex].value)">
    <option value="page.php?id=1">Page1</option>
    <option value="page.php?id=2">Page2</option>
    <option value="page.php?id=3">Page3</option>
</select>

To this:

<select onchange="document.setLocation(this.getValue());">
   <option value="page.php?id=1">Page1</option>
   <option value="page.php?id=2">Page2</option>
   <option value="page.php?id=3">Page3</option>
</select>

Cheers.

  • Share/Bookmark
Feb 26 10

How to remove “setting session.bug_compat_42 or session.bug_compat_warn” Warning

by Ali

I was adding some features in one of my older website for a client and saw this warning:

Warning: Unknown: Your script  possibly relies on a 
session side-effect which existed until PHP 4.2.3.
Please  be advised that the session extension
 does not consider global variables as a 
source of data, unless register_globals is enabled.
You can disable this  functionality and 
this warning by setting session.bug_compat_42
 or  session.bug_compat_warn to off, respectively. 
in Unknown on line 0.

You can simply resolve this and make this warning disappear by avoiding using the same names for session variables and normal ones.

In my case, I just had to change the following code to:

$_SESSION['type'] = $type;

To this one:

$_SESSION['category_type'] =  $type;

That’s it!

Cheers.

  • Share/Bookmark
Feb 18 10

Copying files from remote server to another server through SSH

by Ali

For any webmaster, switching web server is a nightmare, especially when there is large number of files to move to a new server. After some bitter experiences, I have found out following methods to move your data files and database quickly and painlessly from one server to another. I’m sure these SSH commands will save your day.

These methods will copy/get that data files and database from your old server say Server A to new server say Server B without downloading anything to your PC. This way you will save some bandwidth and valuable time, and lot of anxious moments while your huge files are being uploaded when after lot of waiting and whining all you see is ‘script timed out’ message.

I’m assuming here that you have SSH access to your servers.

For data files, what I usually do is that I tar the files because file permissions are preserved and kept intact on the new server. First login through SSH to the Server A where your files are located.

Here are the commands:

cd /home/username-of-your-account/public_html
  tar -cvf backup-website.tar ./

Once it’s done, go to your new server say Server B and login through SSH:

Here are the commands:

  cd /home/ username-of-your-account /public_html
  wget your-old-domain.com/backup-website.tar
  tar -xvf backup-website.tar

That’s it. One caveat here for extraction of tar file if you are logged in as root user. If you have any cPanel or HSphere panel available, you should use that to extract the tar file.

So either log in with your account user name or If you do extract the tar file with the root user, you probably want to check and make sure the correct owner and group are on your files you just extracted. You can check to see what they are by typing:

ls -la

If the owner or group is wrong you can run this to change the owner:

chown -R owner.group ./

owner.group should be replaced with the owner name you want and the group name you want. This will recursively go through all your files and directories and changed them to the correct owner and group. One warning here, this command can change the owner and group for all of your files located on new server and can bring down your new server before even getting started. If the file permissions are not correct, you will see Forbidden error so only run this command “chown“ if you are really sure what you are doing. So be very careful for this command.

It would be far better and safer to extract the tar file using cPanel File Manager or logging in SSH with the hosting account name.

Hope that helps.

Cheers!

  • Share/Bookmark
Feb 1 10

How to fix broken Facebook sample application ‘footprints’

by Ali

So out of curiosity or some Facebook application development prospect forced you today to check on a Facebook application and which brought you here to this blog post.

After signing up for Facebook Apps and downloading facebook-platform.tar.gz, you find a sample application named ‘footprints’ inside it. Footprints App is kinda ‘Hello World’ of Facebook applications.

You uncompress the facebook-platform.tar.gz file and follow instructions available in the README file.You are required to do a number of steps before seeing your FB App ‘Hello World’:

  • Setup the DB information in the config.php file,
  • Create the required table in your DB as described by config.php
  • get the app registered on Develop Page,
  • Setup application name, get API Key and Secret key
  • Add these keys in the config.php file
  • Upload the whole directory on your online server,
  • Open your FB Developer’s page, select your demo application,  and click ‘Edit Settings’, add Canvas Page URL on Facebook for your application, and add Canvas Callback URL (where you uploaded your application) on Canvas page.

Now to view your application, you open this http://apps.facebook.com/your-footprints/ where your-footprints is what you defined in the Canvas Page URL.

Pretty cool, isn’t it? Yeah right as long as you don’t type in your friend’s name and click ‘step’.

This is the warning message on line 52 and a fatal error on line 58 as soon as you hit ‘step’

"Warning: Missing  argument 3 for FacebookRestClient::notifications_send()"
"Fatal error: Call to  undefined method FacebookRestClient::feed_publishActionOfUser"

To remove this warning and fatal error, follow these steps:

Just add a third argument (any string would do) in function notifications_send() call. Just add this on line 52 in lib.php.

 '<a href="http://apps.facebook.com/fc-footprints/">See all your Footprints</a>.','your_app_name');

In the same lib.php file, on line 58, replace function feed_publishActionOfUser with feed_publishUserAction which is defined in facebookapi_php5_restlib.php

And by the way, don't forget to change this URL http://apps.facebook.com/footprints/ in lib.php on several places to your own application's url e.g. http://apps.facebook.com/your-footprints/

I hope that helps.

Cheers!

  • Share/Bookmark
Jan 17 10

Parsing News Feed using PHP & MagpieRSS and making it scroll

by Ali

A while back I had to develop a news widget/ticker as part of my PHP website development project.

First part was to fetch news items regularly via RSS feed, cache the feed and parse it for displaying and for this I used MagpieRSS. Second part was to show the parsed news items as scrolling text or news ticker on a web page.

But first things first, check the demo of what we are talking about Demo MagpieRSS News Scroller.

Here is the PHP code for fetching and parsing the news items using MagpieRSS.

First of all, include the Magpie class:

require_once(MAGPIE_DIR.'/rss_fetch.php'); //where MAGPIE_DIR is the path to magpie dir

Provide the url and set number of items to be displayed (Ideally these should come from Database as I did in the said project managed via admin panel of CMS.):

$url = 'http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/business/rss.xml';
 
$num_of_items = 10; //set  $num_of_items = 'All' to show all items;

Now parse the feed and store all the data in the $rss_news_items variable to be displayed in the page later.

if ( $url ) {
 
  $rss = fetch_rss( $url );
 
  $rss_feed_name =  'Channel: ' . $rss->channel['title'] . ' Updated: '. $rss->channel['lastbuilddate'] ;
 
   if($num_of_items=='All') $num_of_items = sizeof($rss->items);
 
	if(sizeof($rss->items) < $num_of_items)  $num_of_items = sizeof($rss->items);
 
	$rss_news_items = '';
	for ($i=0; $i < $num_of_items; $i++) {
		$href = $rss->items[$i]['link'];
		$title = $rss->items[$i]['title'];
		$description = $rss->items[$i]['description'];
		$date = $rss->items[$i]['pubdate'];
 
		$rss_news_items .= '&nbsp;&nbsp;<span class="bgwithtext"><b>'.$title.'</b> - '.$date.'</span><span class="linkTextOnly">&nbsp;<b><a href="'.$href.'" target="_blank" rel="no-follow">'.$description.'</a></b></span>&nbsp;';
  }
 
}

Now having parsed the RSS feed, we need to make news items scroll on page and for this I used this Scrolling News Ticker by Mioplanet.

echo $rss_feed_name.'<br/>
<div id="TICKER" STYLE="overflow:hidden; width:520px">'.$rss_news_items.'</div>
<script type="text/javascript" src="webticker_lib.js" language="javascript"></script>';

Don’t forget to place “webticker_lib.js” from Mioplanet website in the same directory as your php page. You may also want to place following css class in your style sheet.

I selected Mioplanet js scroller due to its usefulness. You can set the ticker directon from left to right or otherwise, ticker speed and its styles easily.

.bgwithtext{ color:#000000; background-color: orange; padding: 5px; }

I have put together a working php script with all the dependent files in this zipped folder Download PHP MagpieRSS News Scroller script. Just make sure you have ‘/cache’ directory at the root of your website and it is writable by php script (with chmod permissions 777).

Hope that helps!

Cheers.

  • Share/Bookmark
Dec 14 09

Setting different cache age for different feeds using Magpie RSS – PHP RSS Parser

by Ali

MagpieRSS is a XML-based RSS parser in PHP. MagpieRSS supports most RSS versions including modules and namespaces. Magpie RSS also supports caching which is kind a must while parsing any feed because you don’t want to fetch the feed for every hit on your website and risk getting banned.

Although Magpie RSS is really useful and I’ve used it in many projects, one of the feature which is missing from Magpie is setting different cache ages. I had to setup few feeds in a website recently and set different caching age for different feeds. If you are facing similar problem, read on to check the solution.

I made few following changes in the code of function function fetch_rss inside ‘rss_fetch.php’ file.

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
 /*added 2nd parameter for setting different cache age and set existing MAGPIE_CACHE_AGE as default */
function fetch_rss ($url, $magpie_cache_age=MAGPIE_CACHE_AGE) {
    // initialize constants
    init();
 
    if ( !isset($url) ) {
        error("fetch_rss called without a url");
        return false;
    }
 
    // if cache is disabled
    if ( !MAGPIE_CACHE_ON ) {
        // fetch file, and parse it
        $resp = _fetch_remote_file( $url );
        if ( is_success( $resp->status ) ) {
            return _response_to_rss( $resp );
        }
        else {
            error("Failed to fetch $url and cache is off");
            return false;
        }
    } 
    // else cache is ON
    else {
        // Flow
        // 1. check cache
        // 2. if there is a hit, make sure its fresh
        // 3. if cached obj fails freshness check, fetch remote
        // 4. if remote fails, return stale object, or error
 
       //we are not using constant MAGPIE_CACHE_AGE rather using parameter age **added by parorrey**
	   $cache = new RSSCache( MAGPIE_CACHE_DIR, $magpie_cache_age );

And that was it. Now you can call the function fetch_rss with the cache age different than the default MagpisRSS cache age defined in constant MAGPIE_CACHE_AGE.

 
$rss = fetch_rss( $url , 3600 * 12 );  //3600 * 12 means 12 hours

You can call the function with one (default) parameter and it’ll still work just fine albeit caching the feed to default cache age.

 
$rss = fetch_rss( $url  );  //default cache age

Hopefully it’ll help someone setting different cache ages for different RSS feeds in MagpieRSS.

  • Share/Bookmark
Dec 8 09

Make your website faster with Google Page Speed Firefox/Firebug Add-on

by Ali

Installed Page Speed Firefox/Firebug Add-on and tested few of my websites  today with this Add-on. It gave some very good suggestions to remove commented js and css code that I had never cared to remove before. It also suggested images optimization which I think is very good thing. Most web designers & developers never bother to check the sizes of their images which are sometimes very large.

Let’s make the web better and faster by removing redundant and unused css/js!

  • Share/Bookmark