Friday, 25 February 2011

Getting Started with WordPress 3

This article will guide you through the process of setting up WordPress and customizing its basic features. You can choose between a couple of options regarding where your WordPress installation will live. Keep in mind that WordPress is relatively small (under 10 MB), easy to install, and easy to administer.

In this article, you will learn how to:

* Create a free blog on WordPress.com
* Install WordPress manually on your web host


WordPress is available in easily downloadable formats from its website, http://wordpress.org/download/. WordPress is a free, open source application, and is released under GNU General Public License (GPL). This means that anyone who produces a modified version of software released under the GPL is required to keep those same freedoms, that people buying or using the software may also modify and redistribute, attached to his or her modified version. This way, WordPress and other software released under GPL are kept open source.

Where to build your WordPress website

The first decision you have to make is where your blog is going to live. You have two basic options for the location where you will create your site. You can:
  • Use WordPress.com
  • Install on a server (hosted or your own)
Let's look at some of the advantages and disadvantages of each of these two choices.
The advantage of using WordPress.com is that they take care of all of the technical details for you. The software is already installed; they'll upgrade it for you whenever there's an upgrade; and you're not responsible for anything else. Just manage your content! The big disadvantage is that you lose almost all of the theme and plugin control you'd have otherwise. WordPress.com will not let you upload or edit your own theme, though it will let you (for a fee) edit the CSS of any theme you use. WordPress.com will not let you upload or manage plugins at all. Some plugins are installed by default (most notably Akismet, for spam blocking, and a fancy statistics plugin), but you can neither uninstall them nor install others. Additional features are available for a fee as well.
The following table is a brief overview of the essential differences between using WordPress.com versus installing WordPress on your own server:

WordPress.com Your own server
Installation You don't have to install anything, just sign up Install WordPress yourself, either manually or via your host's control panel (if offered)
Themes Use any theme made available by WordPress.com Use any theme available anywhere, written by anyone (including yourself)
Plugins No ability to choose or add plugins Use any plugin available anywhere, written by anyone (including yourself)
Upgrades WordPress.com provides automatic upgrades You have to upgrade it yourself when upgrades are available
Widgets Widget availability depends on available themes You can widgetize any theme yourself
Maintenance You don't have to do any maintenance You're responsible for the maintenance of your site
Advertising No advertising allowed Advertise anything

Using WordPress.com

WordPress.com (http://wordpress.com) is a free service provided by the WordPress developers, where you can register a blog or non-blog website easily and quickly with no hassle. However, because it is a hosted service, your control over some things will be more limited than it would be if you hosted your own WordPress website. As mentioned before, WordPress.com will not let you edit or upload your own themes or plugins. Aside from this, WordPress.com is a great place to maintain your personal site if you don't need to do anything fancy with a theme. To get started, go to http://wordpress.com, which will look something like the following:
WordPress 3 Complete
To register your free website, click on the loud orange-and-white Sign up now button. You will be taken to the signup page. In the following screenshot, I've entered my username (what I'll sign in with) and a password (note that the password measurement tool will tell you if your password is strong or weak), as well as my e-mail address. Be sure to check the Legal flotsam box and leave the Gimme a blog! radio button checked. Without it, you won't get a website.
WordPress 3 Complete
After providing this information and clicking on the Next button, WordPress will ask for other choices (Blog Domain, Blog Title, Language, and Privacy), as shown in following screenshot. You can also check if it's a private blog or not. Note that you cannot change the blog domain later! So be sure it's right.
WordPress 3 Complete
After providing this information and clicking on Signup, you will be sent to a page where you can enter some basic profile information. This page will also tell you that your account is set up, but your e-mail ID needs to be verified. Be sure to check your inbox for the e-mail with the link, and click on it. Then, you'll be truly done with the installation.

Installing WordPress manually

The WordPress application files can be downloaded for free if you want to do a manual installation. If you've got a website host, this process is extremely easy and requires no previous programming skills or advanced blog user experience.
Some web hosts offer automatic installation through the host's online control panel. However, be a little wary of this because some hosts offer automatic installation, but they do it in a way that makes updating your WordPress difficult or awkward, or restricts your ability to have free rein with your installation in the future.

Preparing the environment

A good first step is to make sure you have an environment setup that is ready for WordPress. This means two things: making sure that you verify that the server meets the minimum requirements, and making sure that your database is ready.
For WordPress to work, your web host must provide you with a server that does the following two things:
  • Support PHP, which must be at least Version 4.3.
  • Provide you with write access to a MySQL database. MySQL has to be at least Version 4.1.2.
You can find out if your host meets these two requirements by contacting your web host. If your web server meets these two basic requirements, you're ready to move on to the next step.
As far as web servers go, Apache is the best. However, WordPress will also run on a server running the Microsoft IIS server (though using permalinks will be difficult, if possible at all).
Enabling mod_rewrite to use pretty permalinks
If you want to use permalinks, your server must be running Unix, and Apache's mod_rewrite option must be enabled. Apache's mod_rewrite is enabled by default in most web hosting accounts. If you are hosting your own account, you can enable mod_rewrite by modifying the Apache web server configuration file. You can check the URL http://www.tutorio.com/tutorial/enable-mod-rewrite-on-apache to learn how to enable mod_rewrite on your web server. If you are running on shared hosting, then ask your system administrator to install it for you. However, it is more likely that you already have it installed on your hosting account.

Downloading WordPress

Once you have checked out your environment, you need to download WordPress from http://wordpress.org/download/. Take a look at the following screenshot in which the download links are available on the right side:
WordPress 3 Complete
The .zip file is shown as a big blue button because that'll be the most useful format for the most people. If you are using Windows, Mac, or Linux operating systems, your computer will be able to unzip that downloaded file automatically. (The .tar.gz file is provided because some Unix users prefer it.)
A further note on location We're going to cover installing WordPress remotely. However, if you plan to develop themes or plugins, I suggest that you also install WordPress locally on your own computer's server. Testing and deploying themes and plugins directly to the remote server will be much more time-consuming than working locally. If you look at the screenshots I will be taking of my own WordPress installation, you'll notice that I'm working locally (for example, http://wpbook:8888/ is a local URL).
After you download the WordPress .zip file, extract the files, and you'll get a folder called wordpress. It will look like the following screenshot:

WordPress 3 Complete

Uploading the files

Now, we need to upload all these files to our web server using any FTP client (or simply put them in our local server directory on our local computer). FTP stands for File Transfer Protocol. There are several FTP clients available on the Internet, which are either freeware (no cost) or as shareware (a small fee). If you don't already have an FTP client, try one of these:
You can also use the popular web-based FTP application net2ftp at http://www.net2ftp.com. These services are useful if you don't want to install a desktop application on your computer. You can also check if your host provides browser-based FTP software.
In my screenshots you'll see that I'm using Transmit, which is the professional FTP software I use on my Mac. It works the same way as the examples above.
A note about security: whenever possible, you should use Secure FTP (called sFTP) rather than regular FTP. If you're using sFTP, all of the data sent and received are encrypted, whereas with FTP, data are sent in plain text and can be easily nabbed by hackers. Check both your FTP software and your hosting options, and select sFTP if it's available.
Using your FTP client or service, connect to your FTP server using the server address, username, and password provided to you by your host. Next, open the folder where you want WordPress to live. You may want to install WordPress in your root folder, which will mean that visitors will see your WordPress website's home page when they go to your main URL—for example, http://yoursite.com. Alternatively, you may want to install WordPress in a subfolder; for example: http://yoursite.com/blog/.
On the left side, you will see the files from your local folder, and on the right side you will see your remote folder. (Note: the FTP client you are using may have a slightly different layout, but this is the general idea):
(Move the mouse over the image to enlarge.)
Now select all of the WordPress files on your local machine from the left pane, and drag all of them to the right pane. You can watch as your FTP client uploads the files one at a time and they appear in the right panel. This could take a few minutes, so be patient!
If you're installing WordPress on your local server, just be sure to place the WordPress files in the correct webroot directory on your computer.
Once all of the files are done uploading, you're ready to do the installation.

Installing WordPress

Now it's time to install WordPress. For example, I will be working on my local server and just put brand-new WordPress files at http://wpbook:8888/. So, this is going to be the URL of my WordPress website. If you access your WordPress URL via your browser, it will look like the following:
WordPress 3 Complete
It says that you need to create a file named wp-config.php before proceeding further. WordPress (and I) recommend that you do this manually, rather than using the Create a Configuration File link. If you do choose to use the config creator, you'll need the information below as well (though there will be no opportunity for the security phrases).
Open the wordpress folder and find the file named wp-config-sample.php. Make a copy of this file and name it wp-config.php. We'll modify this file together. Don't worry; you need not be a PHP programmer. Just open this file with a simple editor such as Notepad. The following is the copied text from the original wp-config.php file. Note that I've removed most of the comments, so that we can focus on the items we need to change.
/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');

/** MySQL database username */
define('DB_USER', 'username_here');

/** MySQL database password */
define('DB_PASSWORD', 'password_here');

/** MySQL hostname */
define('DB_HOST', 'localhost');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

define('AUTH_KEY',                     'put your unique phrase here');
define('SECURE_AUTH_KEY',   'put your unique phrase here');
define('LOGGED_IN_KEY',         'put your unique phrase here');
define('NONCE_KEY',                 'put your unique phrase here');
define('AUTH_SALT',                   'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT',       'put your unique phrase here');
define('NONCE_SALT',               'put your unique phrase here');

$table_prefix = 'wp_';
?>
One thing to know about PHP is that any text that comes after a double slash (//), or between a slash-star and star-slash (/* */), is a comment. It's not actual PHP code. Its purpose is to inform you what that line or that section is about.
As you can see from the previous code, there are a number of settings that you can insert here. Let's walk through the most important ones.
As I mentioned in an earlier section, you need to have write access to a database. Most large web hosts offer you a way to create your own databases, with usernames and passwords, via an online control panel. If you're not sure how to do this, just e-mail or call your hosting provider for this information. You'll need four pieces of information about your database for the WordPress configuration file. They are:
  • Database server—for example, localhost
  • Username—for example, localdbuser
  • Password—for example, 62dcx0hnm
  • Database name—for example, wpbookdb
Your database server might not be localhost. If it's not, you can ask your hosting provider, or take a look at this handy cheat sheet: http://codex.wordpress.org/Editing_wp-config.php#Possible_DB_HOST_values.
Once you have those four things, you can fill them into your wp-config.php file. For example, see how mine is filled out here:
// ** MySQL settings ** //
define('DB_NAME', 'wpbookdb');
define('DB_USER', 'localdbuser');
define('DB_PASSWORD', '62dcx0hnm');
define('DB_HOST', 'localhost');
Next, for security purposes, you really should put some unique phrases into the unique keys. The secret keys are used by WordPress to add random elements to your passwords and are also used in some other situations. This will help to keep your WordPress installation uniquely protected. No one else is likely to choose the same unique keys that you chose, and therefore, breaking or hacking into your site will be more difficult. You can get some secret keys generated by going to https://api.wordpress.org/secret-key/1.1/salt/. Once I did that, I got the following, which I can paste directly over the default code in wp-config.php:
define('AUTH_KEY', 'uu|6#00Pc/3h?Pg5:Zc#:S=;<3mdw-ai');
define('SECURE_AUTH_KEY', 'vy1.@Nr@Zb^G|0Vfz-|TH5&W');
define('LOGGED_IN_KEY', 'sryMVd`jVpiMWWQqx~!v XE5@fJMTt2[Z');
define('NONCE_KEY', 'i,+UPpMR>Mj3o}(B**^
define('AUTH_SALT', 'n.8Li=9OjV+_p|}e5yN2k
define('SECURE_AUTH_SALT', 'I#2vPT^u[5vLX|`MzPg/J*y]RTfr');
define('LOGGED_IN_SALT', 'gR%QP^c*jfFUy,iQ}-0g_%;%H)pN0B5');
define('NONCE_SALT', '&L);.IH`v{]zYLO2:h_t#J0D-p)cvyc');
The only other thing you may want to consider is the table prefix. I strongly recommend using a prefix. If you want to install WordPress more than once, you'll need to use different prefixes in your different installations. If you are using this same database for other things, it'll be handy if the tables are grouped based on what they're being used for. So either leave the following line as it is, or choose another prefix:
$table_prefix = 'wpbook_';
Learning more: The WordPress codex has a long and detailed page that describes everything about editing your wp-config.php file: http://codex.wordpress.org/Editing_wp-config.php.
Now, go back to your browser and reload the page that's pointing to your WordPress installation. If your configuration file makes sense to WordPress, you'll be taken directly to the installation page.
WordPress 3 Complete
(If you've ever installed an earlier version of WordPress, you'll notice some differences, like the ability to choose your first username and password!) Now, fill out the installation form (you will be able to change all of these later, so don't be too worried about getting locked into your choices):
  • Site title: Fill in the name of your blog (in my case it's 'Daily Cooking').
  • Username: Note that the default username is 'admin', but for security purposes, you're better off picking another username. If someone ever tries to hack your blog, they will be halfway there if they already know your username. I've chosen 'ahsilver'.
  • Password: Choose a secure password, one that has both upper and lowercase letters, a number or two, and even a few punctuation marks.
  • Your E-Mail: Double-check that this is correct, because this is the e-mail address WordPress will use to contact you about the blog, comments, and so on. If you do not get an e-mail from your WordPress site shortly after installing, check your spam folder.
Now, click on Install WordPress. You're done with the install!
WordPress 3 Complete
You can click on Log In to get to the login page. Or you can always enter your WordPress Admin panel (also known as the WP Admin) by pointing your browser to http://yoursite.com/wp-admin. If you're not already logged in, this URL will redirect you to the login page.

Learning more

If you'd like to see an even more detailed step-by-step guide for manual installation, take a look at this page in the WordPress Codex: http://codex.wordpress.org/Installing_WordPress.
Also, you can find more detailed installation instructions—as well as specifics on changing file permissions, using FTP, using languages, importing from other blogging engines, and more—in the WordPress Codex here: http://codex.wordpress.org/Getting_Started_with_WordPress#Installation.

Summary

In this article we took a look at how to create a blog on WordPress.com and install WordPress on a remote server.

Product Management with Compiere 3

Products are an integral part of the ERP transactional process, and thus require a detailed explanation in the setup process, not only from the master data point of view but also for transactional processes.

We will therefore describe how Compiere handles Product. In this article we shall learn:

* Give you an overview of the concept of a product
* Show you how to set up price lists and discount schemas

The product definition

The concept of a product in Compiere is that it is something that you buy or sell and has a price. It would include:
  • Inventory items (items that you store and track)
  • Non-stock items (still items, but you do not store or track them)
  • Services
  • Resources
  • Expense types
In addition to a product, Compiere allows for charges (account aliases), as well as customer assets on transactional lines.
When to use a charge and not a product: It's logical to use charges where a mere account entry is required and the many descriptions that a product requires are not required for the transaction. An example would be marketing or an admin expense.
When to use a customer asset and not a product: Customer assets are extended instances of a Compiere product. An example would be where a Desktop PC is sold or purchased and becomes an asset or equipment type that need to be tracked.Customer assets are therefore used for asset or equipment related business process information.
Products allow for many descriptive attributes in its master setup.

Describing a product

Product information and features can be extended and described in Compiere in the following manner:
  • Basic Product Information: Basic product information includes search key values, Descriptions, Unit of Measure, UPC, EAN. Critical for basic product information are Product categories, which group products into related products.
  • Product BOM (Bill of Material): More advanced products would include BOM kits that are made up of other products (referred to as BOM components).
  • Substitute / Related Products: This refers to products that may be related to the product being searched for.
  • Product Replenishment: This describes the rules of how a product would be replenished. This would, for instance, include minimum and maximum quantities to hold in stock.
  • Product Purchasing information: This refers to the set-up around how a product is purchased—for instance the default vendor and the vendor's product code.
  • Product Locator: Where products are currently located in the warehouse.
  • Product Business Partner: This describes additional information used when products are purchased.
  • Product Price: A product may have multiple price lists attached to it, and depending on the Business Partner or transactional document this can be defaulted as required.
  • Product Accounting: This describes which standard account elements are to be used for a transactional document. Usually, similar products have the same accounting rules and as such the accounting for Product Categories would be setup and maintained, rather than individual product categories.
  • Product Unit of Measure conversions: Where applicable, products may have conversions applicable to them—for instance converting a 6-pack quantity sold to an, each, quantity during purchasing.
  • Product Attributes: Attribute sets allow you to further extend the product information into, for example, instance sets such as lots and serial numbers.Non-instance sets are also catered for, such as colour or size sets that can be used for searching the products.

Setting up a Product

Prior to setting up a product, you should make sure that the following is set up:
  • Warehouse and Locators: The system logic here is that a Product must be sold/delivered from somewhere within the organization. Make sure that you set up your warehouse and Locators first. Use virtual warehouse and locators where they are not physical.
  • Units of Measure: Review the system standard units of measure and add your own units of measure if applicable.
  • Product Categories: Define your groupings prior to setting up products since it will reduce data maintenance time.
  • Tax Categories: Pre-define the applicable tax categories if they are product specific.
  • Price lists: In order to use a product it must have a price which is set up through Price Lists (it includes sales and/or purchase price lists).
The above set-up is performed through the Product Setup menu items, which are grouped as follows in the main menu:
You start entering a product through the Product window:
The additional Product Descriptions (listed above) are added through the following tabs in the Product window:

Price Lists

In order for products to be used in the sales or purchasing cycle, they must have prices. A product can have the following three line prices set up:
  • List Price: The list price before discounts of a product.
  • Standard Price: The standard price of a product.
  • Limit Price: The lowest price at which a product can be sold or purchased.Usually used by management as a pricing control limit for sales reps.
The product price information (in the context of the price list version) is accessed through the Product Price| window:

Pricing logic flow

Price lists determine the price to be used in the context of the transaction(sales / purchase) and the chosen Business Partner. The basic logic for determining the price is as follows:
  • A price list has a version, and the latest version of a price list is used during sales or purchasing (or both).
  • If a Business Partner (customer or vendor) is assigned a Price list, then this Price List is used to determine the price for the transaction.
  • If a Business Partner is not assigned a price list, then the Business Partner Group's defined price lists is used.
  • If the Business Partner Groups' price list is not defined, then the default sales or purchase price list is used (this is indicated throught the isDefault checkbox in the price list window header).
  • If a product is not assigned the relevant price list, an error is given and the user cannot continue.
  • The system also considers that a price list is Tenant and Organization specific.
In terms of price discounting, a product can be assigned to a Discount Schema. In such a case, the following discount schema options are available:
  • Price lists: This is the normal type of discount calculation, and is based on the price list-that is—a discount off the list price based on a distributor or reseller price list.
  • Flat Percentage: This refers to a flat percentage discount arrangement.
  • Quantity Discount Breaks: This discount schema refers to quantity breaks, where items purchased at different quantity levels attract more discount-for example,—100/10% or 1000/20%.

Setting Up a Price List and version

As mentioned, a price list can have one or more versions, which are time based. This is set up as follows:
  1. Enter a price list through the Price List window. Here, we enter a sales pricelist as follows:
  2. A price list may be set up to be inclusive of tax. In this case the accounts posting on the document is adjusted to reflect the inclusive tax accounting. Enforcing price limits ensures that the end-user cannot enter a price lower that the price lists, limit price for the product.
  3. Create one or many price list versions through the Price List | Version tab, with the following options:
    • Dicscount Schema: This specifies the discount rules to be applied when creating or updating the price list.
    • Base Price List: This indicates a price list upon which to base the discount schema rules.
    • Valid from date: The price list will be used for new order or invoice transactions from this date. Transactions prior to this date will not be affected.
A price list is either imported, manually entered, or updated based on another price list, through the discount schema.

Illustrating a price list increase

To illustrate the process of a applying a price list increase, we will create a new price list version with a 10 percent increase on the existing version.
  1. One enters the discount schema detail through the Discount Schema window. We will select a PriceList discount type, as the calculation will be based on the price list values:
    How to Handle Products using Compiere 3
  2. The next step is to create the Price List line calculation paramaters for the discount schema:
    How to Handle Products using Compiere 3
  3. The pricing discount line for the increase is entered as follows:
    1. Select the Price Base: This defines which price base is affected (List, /Standard / Limit).
    2. Enter the List price Discount: A discount is normally entered as a positive, but because we are performing a price increase we enter a negative amount.
    3. List Price Rounding option: Compiere allows different rounding methods, and as illustrated we selected the Rounding to the nearest Ten (10,20,30) option, for pricing policy reasons.
    How to Handle Products using Compiere 3
  4. Finally, we run the increase for the Price List version illustrated as follows:
    How to Handle Products using Compiere 3

Discount Breaks

Discount breaks are trade discounts applied through different quantity or value breaks/levels. Setting up a Discount Schema for discounts break based on a quantity sliding scale is entered through the Discount Schema window, as follows:
In a sliding scale discount break, Compiere applies the first discount break that meets the discount criteria, therefore for the example above, an order of 1000 or above would have a 40% discount, 500-999 would have 20% discount, an order of between 10 to 499 would have 4% discount, and 0-9 would have 0% discount

Pricing Decimal Precisions

Compiere allows for different pricing decimal precisions, which may be a requirement in the enterprise during different transaction types:
  • Unit of measure: You can define pricing decimal precisions for accounting and cost calculation separately
  • Currency: You can define pricing decimal precisions for accounting and cost calculation separately
  • Price List: You can define the price precision

Managing Products as Services

Service items are not treated as stock and are usually not purchased. Service items are managed as non-stocked items and have different accounting entry implications,by default. Service items are set up through the Product window as follows:

Summary

We covered the following in this article:
  • The basic characteristics of a product, and how to set up a product item
  • How to set up and use price lists and discount schemas

Developing a Simple Workflow within SugarCRM

Workflow is about getting the right work to the right people at the right time, repeatedly—and knowing you have done so. Workflow is human-centric. First and foremost, workflow is a human activity that is made by and for those who use it: workflow is something that can easily be handled and understood by human beings.
UK Enterprise Workflow National e-Government Project—Workflow from a Business Perspective
Well, that sounds good, but the problems start to occur when you ask people to consider workflow in their organization, and there are usually a few main issues to deal with:
  • You'll find that people are normally experts in their own fields—there are often very few people who have an overview of the whole process that you're trying to map.
  • Sections of a large organization will often have different ways of carrying out the same overall process.
  • People don't really like to be told how to do their jobs—they especially don't like to have any extra processes imposed on them for now obvious reason—well, would you?
  • Talk of 'improved utilization of resources', 'improved performance monitoring', and such like can soon alienate the staff who are going to be using the system. They'll soon start using terms such as 'Big Brother'.
How you are able to deal with these will depend on your organization and the people that are available to you. At least once you've read this article by Dr. Mark Alexander Bain, you'll know that, once you've overcome those problems, the workflow itself will be easy.

A Very Simple Workflow

In our simple workflow we'll assume that each task is carried out by one person at a time, and that all tasks are done sequentially (i.e. none are done in parallel). So, we'll look at the PPI Preliminary Investigation which, as you remember, maps to the standard SugarCRM Opportunity. Also, in this example, we're going to have a different person carrying out each one of the Investigation stages.

Setting up the Process Stages

If you look at SugarCRM then you'll see that by default none of the stages are related to investigations—they're all named using standard CRM terms:
Developing a Simple Workflow within SugarCRM
Obviously the first thing to do is to decide what the preliminary investigation stages actually are, and then map these to the SugarCRM stages. You'll realize that you'll need to edit the custom/include/langauge/en_us.lang.php file:
$app_list_strings['sales_stage_dom']=array (
  'Prospecting' => 'Fact Gathering',
  'Qualification' => 'Witness and Subject Location',
  'Needs Analysis' => 'Witness and Subject Interviews',
  'Value Proposition' => 'Scene Investigation',
  'Id. Decision Makers' => 'Financial and background Investigation',
  'Perception Analysis' => 'Document and evidence retrieval',
  'Proposal/Price Quote' => 'Covert Camera surveillance',
  'Negotiation/Review' => 'Wiretapping',
  'Closed Won' => 'Full Investigation required',
  'Closed Lost' => 'Insufficient Evidence',
);
Don't forget that you can also do this via Studio. However, once you've added your mapping into custom/include/langauge/en_us.lang.php file, and refresh your browser, then you'll see the new stages:
Developing a Simple Workflow within SugarCRM
Now that our stages are set up we need to know who'll be carrying out each one.

Deciding Who Does What

In our simple workflow there may not be the need to do anything further. Each person just needs to know who does what next:
For example, once Kurt finishes the 'Covert Camera surveillance' stage then he just needs to update the Preliminary Investigation so that the stage is set to 'Wiretapping' and the assigned user as 'dobbsm'.
However, things are rarely as simple as that. It's much more likely that:
  • Investigations may be based on geographical locations, so that the above table may only apply to investigations based in London. Investigations based in New York follow the same process but with a different set of staff.
  • On Mondays Fran does 'Witness and Subject Location' and William does 'Fact Gathering'.
This means, of course, that we need to be using some businesses rules.

Introducing Business Rules

There are six 'triggers' that will cause the logic hooks to fire:
  • after_retrieve
  • before_save
  • before_delete
  • after_delete
  • before_undelete
  • after_undelete
And the logic hooks are stored in custom/modules//logic_hook.php, so for 'Preliminary Inquiries' this will be custom/modules/Opportunities/logic_hook.php. You'll also remember, of course, that the logic hook file needs to contain:
  • The priority of the business rule
  • The name of the businesses rule
  • The file containing the business rule
  • The business rule class
  • The business rule function
So, custom/modules/Opportunities/logic_hook.php needs to contain something like:
#As always ensure that the file can only be accessed through SugarCRM
if(!defined('sugarEntry') || !sugarEntry) die(
     'Not A Valid Entry Point');
$hook_array = Array(); #Create an array

$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(1, 'ppi_workflow',
  'custom/include/ppi_workflow.php',
  'ppi_workflow', 'ppi_workflow');
?>
Next we'll need the file that logic hook will be calling, but to start with this can be very basic—so, custom/include/ppi_workflow.php just needs to contain something like:
#Define the entry point
if(!defined('sugarEntry') || !sugarEntry) die(
     'Not A Valid Entry Point');
#Load any required files
require_once('data/SugarBean.php');
require_once('modules/Opportunities/Opportunity.php');

#Define the class
class ppi_workflow
{
  function ppi_workflow (&$bean, $event, $arguments)
  {

  }
}
?>
With those two files set up as above nothing obvious will change in the operation of SugarCRM—the logic hook will fire, but we haven't told it to do anything, and so that what we'll do now.
When the logic hook does run (i.e. when any Primary Investigation is saved) we would want it to:
  • Check to see what stage we're now at
  • Define the assigned user accordingly
All of the relevant information (i.e. the new stage) is passed to the logic hook by means of the $bean object, and we can obtain the stage from $bean->sales_stage. Now all we have to do is combine this with PHP's switch statement into the ppi_workflow function:
switch ($bean->sales_stage)
{
    case "Prospecting":
      $assigned_user = "varadyf";
      break;
    case "Qualification":
      $assigned_user = "monkw";
      break;
    case "Needs Analysis":
      $assigned_user = "pittc";
      break;
    case "Value Proposition":
      $assigned_user = "brockd";
      break;
    case "Id. Decision Makers":
      $assigned_user = "brunettig";
      break;
    case "Perception Analysis":
      $assigned_user = "thanetl";
      break;
    case "Proposal/Price Quote":
      $assigned_user = "wallanderk";
      break;
    case "Negotiation/Review":
      $assigned_user = "dobbsm";
      break;
    case "Closed Won":
      $assigned_user = "bluek";
      break;
    case "Closed Lost":
      $assigned_user = "bluek";
      break;
}
You'll notice from the code that we must use the original SugarCRM sales stage terms and not our new mapping—that only appears on the screen.
Next we'll have to add the code to update $bean->assigned_user_id with the ID of our new user:
global $db;

$sql =
  "select id from users where user_name = '" . $assigned_user ."'";
$result = $db->query($sql);
$bean->assigned_user_id = mysql_result($result,0,0);
With the code in place, if you now change the Investigation (or Sales) stage, and then save the Preliminary Investigation (or Opportunity) then you'll see that the assigned user is automatically updated for you.
However, this is still only a semi-automatic process—the correct person for the stage is selected correctly, but only if the stage is selected manually. The process running correctly still depends on someone telling SugarCRM what that next stage is. Obviously the next step is to move from stage to stage automatically.

Completing the Automated Workflow

At the moment we're relying on a user telling the application which stage to move to next. However, it would be much better for the user to tell SugarCRM that the current stage has been completed, and then for the business rules to decide which stage should be carried out next. We want to keep it simple and therefore an 'Investigation Stage Complete' checkbox will do the job.
If you look at the edit view for any of the existing Opportunities then you'll see that there's nothing that can really be renamed to represent our 'Investigation Stage Complete':
Developing a Simple Workflow within SugarCRM
We can use the SugarCRM Studio to add the field that we're going to need:
Developing a Simple Workflow within SugarCRM
After adding the custom field itself we'll need to add text for the field label into custom/modules/Opportunities/language/en_us.lang.php:
And then we're ready to see the new edit view:
$mod_strings['lbl_chk_complete_c_10'] = "Investigation Stage 
Completed";
Developing a Simple Workflow within SugarCRM
We can now go back to our code (in custom/include/ppi_workflow.php), and we can place all of our functionality within an if statement:
if ( $bean->chk_complete_c == 1 )
{
  switch ($bean->sales_stage)
  {
    /* etc, etc, etc */
  }
}
Our logic hook will, of course, fire every time a save is made—but our business rule will only be implemented if the Investigation Stage Completed box is ticked. So now we need the code that will define the process itself, and you would need to place this before the code for deciding who the assigned user is:
switch ($bean->sales_stage)
{
  case "Prospecting":
    $bean->sales_stage = "Qualification";
    break;
  case "Qualification":
    $bean->sales_stage = "Needs Analysis";
    break;
  case "Needs Analysis":
    $bean->sales_stage = "Value Proposition";
    break;
  case "Value Proposition":
    $bean->sales_stage = "Id. Decision Makers";
    break;
  case "Id. Decision Makers":
    $bean->sales_stage = "Perception Analysis";
    break;
  case "Perception Analysis":
    $bean->sales_stage = "Proposal/Price Quote";
    break;
  case "Proposal/Price Quote":
    $bean->sales_stage = "Negotiation/Review";
    break;
  case "Negotiation/Review":
    $bean->sales_stage = "Closed Won";
    break;
}
//Now decide who the assigned user is...
And finally we need to reset the completed status back to 0:
$bean->chk_complete_c = 0;
You'll notice that we've not taken the process all the way to the final stage—this is because the final two stages are 'Closed won' or 'Closed lost' (in PPI speak—'Full Investigation required' and 'Insufficient Evidence'). Korora will need to make that decision herself.
However, the important thing is that you can see just how easy it is to set up a simple process (not that any process is ever simple).

Summary

Before you start work on your workflow, ensure that: the people who understand the processes in the organization are available to you; both managers and staff agree that the process plan is correct; staff don't feel that the process is being enforced on them; and that this isn't another case of 'Big Brother'.
When you do start building the work flow ensure that you've correctly mapped your organization's stages onto the SugarCRM stages and that you have a complete listing of who does what and when.
Business rules are created by making use of SugarCRM's logic hooks. The logic hook file contains the priority of the business rule, the name of the businesses rule, the file containing the business rule, the business rule class, and the business rule function.

Introduction to Developing Facebook Applications

In this article we will:
  • Learn what the big deal is about Facebook, and why you should be interested in developing an application for it
  • Get you set up with a web host, which you'll need for developing any online Facebook application
  • Establish how much AS3 you need to know already, and what to do if you don't
  • Find out how to deal with the debugging complications that arise when developing a "browser-only" application like this
So let's get on with it...

What's so great about Facebook?

Seems like everyone's on Facebook these days—people are on it to socialize; businesses are on it to try to attract those people's attention. But the same is true for other older social networks such as LinkedIn, Friendster, and MySpace. Facebook's reach goes far beyond these; my small town's high street car park proudly displays a "Like Us On Facebook" sign.
More and more Flash games and Rich Internet Applications (RIAs) are allowing users to log in using their Facebook account—it's a safe assumption that most users will have one. Companies are asking freelancers for deeper Facebook integration in their projects. It's practically a buzzword.
But why the big fuss?

It's popular

  • Facebook benefits from the snowball effect: it's big, so it gets bigger.
  • People sign up because most of their friends are already on it, which is generally not the case for, say, Twitter. Businesses sign up because they can reach so many people. It's a virtuous circle.
  • There's a low barrier to entry, too; it's not just for techies, or even people who are "pretty good with computers;" even old people and luddites use Facebook. In February 2010, the technology blog ReadWriteWeb published an article called "Facebook Wants to Be Your One True Login," about Facebook's attempts to become the de facto login system throughout the Web. Within minutes, the comments filled up with posts from confused Facebook users:
    Introduction to Developing Facebook Applications
    • Evidently, the ReadWriteWeb article had temporarily become the top search result for Facebook Login, leading hundreds of Facebook users, equating Google or Bing with the Internet, to believe that this blog post was actually a redesigned Facebook.com. The comment form, fittingly, had a Sign in with Facebook button that could be used instead of manually typing in a name and e-mail address to sign a comment—and of course, the Facebook users misinterpreted this as the new Log in button.
    • And yet… all of those people manage to use Facebook, keenly enough to throw a fit when it apparently became impossible to use. It's not just a site for geeks and students; it has serious mass market appeal.
  • Even "The Social Network"—a movie based on the creation of Facebook—held this level of appeal: it opened at #1 and remained there for its second weekend.

Numbers

  • According to Facebook's statistics page (http://www.facebook.com/press/info.php?statistics), over 500 million people log in to Facebook in any given month (as of November 2010). For perspective, the population of the entire world is just under 7,000 million.
  • Twitter is estimated to have 95 million monthly active users (according to the eMarketer.com September 2010 report), as is MySpace. FarmVille, the biggest game based on the Facebook platform, has over 50 million: more than half the population of either competing social network.
  • FarmVille has been reported to be hugely profitable, with some outsider reports claiming that its parent company, Zynga, has generated twice as much profit as Facebook itself (though take this with a grain of salt). Now, of course, not every Facebook game or application can be that successful, and FarmVille does benefit from the same snowball effect as Facebook itself, making it hard to compete with—but that almost doesn't matter; these numbers validate Facebook as a platform on which a money-making business can be built.

It's everywhere

As the aforementioned ReadWriteWeb article explained, Facebook has become a standard login across many websites. Why add yet another username/password combination to your browser's list (or your memory) if you can replace them all with one Facebook login?
This isn't restricted to posting blog comments. UK TV broadcaster, Channel 4, allows viewers to access their entire TV lineup on demand, with no need to sign up for a specific Channel 4 account:
Introduction to Developing Facebook Applications
Again, Facebook benefits from that snowball effect: as more sites enable a Facebook login, it becomes more of a standard, and yet more sites decide to add a Facebook login in order to keep up with everyone else.
Besides login capabilities, many sites also allow users to share their content via Facebook. Another UK TV broadcaster, the BBC, lets users post links for their recommended TV programs straight to Facebook:
Introduction to Developing Facebook Applications
Blogs—or, indeed, many websites with articles—allow readers to Like a post, publishing this fact on Facebook and on the site itself:
Introduction to Developing Facebook Applications
So half a billion people use the Facebook website every month, and at the same time, Facebook spreads further and further across the Internet—and even beyond. "Facebook Messages" stores user's entire conversational histories, across e-mail, SMS, chat, and Facebook itself; "Facebook Places" lets users check into a physical location, letting friends know that they're there.
No other network has this reach.

It's interesting to develop for

With all this expansion, it's difficult for a developer to keep up with the Facebook platform. And sometimes there are bugs, and undocumented areas, and periods of downtime, all of which can make development harder still.
But the underlying system—the Graph API, introduced in April 2010—is fascinating. The previous API had become bloated and cumbersome over its four years; the Graph API feels well-designed with plenty of room for expansion.

Have a go hero – get on Facebook

If you're not on Facebook already, sign up now (for free) at http://facebook.com. You'll need an account in order to develop applications that use it. Spend some time getting used to it:
  • Set up a personal profile.
  • Post messages to your friends on their Walls.
  • See what all the FarmVille fuss is about at http://apps.facebook.com/onthefarm.
  • Check in to a location using Facebook Places.
  • Log in to some blogs using your Facebook account.
  • Share some YouTube videos on your own Wall from the YouTube website.
  • "Like" something.
    Go native!

Web hosts

If you've already got a publicly accessible web server or are signed up to a web host to which you can upload SWFs and HTML pages via FTP, skip to the How much AS3 knowledge is required? section.

What's a web host?

I'll assume that you roughly know how the Internet works: when you type a URL into a web browser on your computer and hit Go, it retrieves all the pages and images it needs from another computer, the web server, and displays them. The exact methods it uses to find the web server and the protocols for how the information gets back to your computer aren't relevant here.
You could go out and buy a computer, install some server software, and hook it up to your Internet connection, and you'd have a functional web server. But you'd have to maintain it and keep it secure, and your ISP probably wouldn't be very happy about you sending all those pages and images to other people's browsers. A better option is to pay another company to take care of all of that for you—a web host.

Why do you need one?

  • In order to build an online SWF-based application or game that allows users to log in with their Facebook account (with the SWF being able to access their profile, list of friends, Wall, and so on), you will require control over a web page.
  • Technically, you could probably come up with some hack that would allow you to get around this—perhaps by hosting everything on Google sites and MegaSWF—but in the long run it's not going to be worth it. Splash out on a web host for the sake of learning; you will definitely need access to one if you do professional Facebook application development in the future.

How do you choose one?

  • There are a huge number of web hosts to choose from, and an even bigger number of configurable options between them. How much disk space do you need? How much bandwidth per month? How much processing power? Some hosts will give you a server all to yourself, while others will put your files on the same computer as other customers. And of course, you have to wonder how good the customer service is and how reliable the company is at keeping their servers online. Throw in a few terms such as "cloud hosting" and it's enough to make your head spin.
  • All you need is a host that allows you to upload HTML files and SWFs.
  • Want to just get started without wasting time comparing hosts? Go with Media Temple. The code was all tested using a Media Temple Grid Service account, available at http://mediatemple.net/webhosting/gs/. It provides much more than what you'll need for completing the projects, granted, and at $20/month. It's not the cheapest option available, but the extra service and features will definitely come in handy as you build your own Facebook applications and games.

Useful software

You'll need an HTML editor for editing web pages. FlashDevelop and Flash Builder both do good jobs at this; otherwise, try:
And in order to transfer your files from your computer to your web host, you'll probably need an FTP client. Check out FileZilla (it's free and available for both Windows and Mac) at http://filezilla-project.org/. Documentation for this is available at http://wiki.filezilla-project.org/Documentation, and your web host will almost certainly provide instructions on connecting to it via FTP (Media Temple's instructions can be found at http://kb.mediatemple.net/questions/131/Using+FTP+and+SFTP)

What about domain names?

Web hosts will generally assign you a very generic address, such as http://michaeljw.awesomewebhost2000.com/ or http://sites.awesomewebhost2000.com/michaeljw. If you want to have a more condensed personal address such as http://michaeljw.com/, you'll need to pay for it. This is called a domain name—in this specific example, michaeljw.com is the domain name.
Media Temple allows you to buy a domain name for $5/year at the point where you sign up to their web hosting package. If you go with another host, you may need to buy a domain name elsewhere; for this, you can use http://www.moniker.com/.

Have a go hero – get a web host, upload to it, test

Pick a web host, get your credit card out, and sign up for one of their packages.
  1. Create a new directory called /test/ in the public path of your web host.
  2. Create a new plain text file on your hard drive called index.html. (It's a good idea to create a new folder on your computer to store all your work, too.) Open this file in your HTML editor.
  3. Copy the HTML below into the file:
    Test
     
     
       

    Hello!

  4. Hopefully, you know enough HTML to understand that this just writes Hello! in big letters.
  5. Transfer index.html to the /text/ directory on your host. Again, you'll probably need to use an FTP client for this.
  6. Open a web browser and type http://host.com/test/index.html into the URL bar. Of course, you should replace http://host.com/ with the path to your public directory, as given to you by your web host. You should see Hello! appear in a glorious default font:
    Introduction to Developing Facebook Applications
  7. If not, check the documentation and support for your host.

How much AS3 knowledge is required?

Powered by…

In September 2010, Adobe released an official Adobe ActionScript 3 SDK for the Facebook Platform Graph API, which will remain fully supported by Adobe and Facebook. Read more about it at http://www.adobe.com/devnet/facebook.html.
Besides the Adobe AS3 SDK for Facebook Platform, two other code libraries are used heavily:

Debugging

There are a few tools that will help:

Watch out for caching

When you run a SWF using Flash Player on your desktop, it loads and runs the SWF. Well, of course, why wouldn't it?
When you run a SWF in a browser, this isn't always the case, though. Sometimes, browsers cache SWFs, meaning that they save a copy locally and then load that copy—rather than the online version—the next time you request it. In normal browsing, this is a great idea—it saves bandwidth and reduces loading times. You can lose huge amounts of time trying to figure out why your new code isn't working, only to finally realize that the new code isn't being run at all because you were seeing only a cached copy of your SWF.
Different browsers require different solutions. It's usually possible to disable caching for one browsing session, and it's always possible to delete some or all of the cache.
In Google Chrome, you can do this by clicking on [Spanner] | Tools | Clear Browsing Data…, selecting Empty the cache, and choosing an appropriate time period:
Introduction to Developing Facebook Applications
Introduction to Developing Facebook Applications
You should easily be able to find the equivalent option for your browser by searching Google for «browser name» delete cache.

Summary

Facebook's developers are always tweaking the platform. This can make it exciting to develop on because new features are being added all the time, but it can also make it very frustrating to develop on because old features can be removed, or their implementations changed; anything could be altered at any time.
The new Platform API (the Graph API) is a strong foundation, and looks likely to be around for a while—remember, the previous Platform API lasted four years. But it's modular, and individual pieces might change, or even be removed.

Friday, 9 July 2010

Creating Your First Virtual Machine: Ubuntu Linux (Part 2)

Running your Ubuntu Linux VM

This is going to be the most entertaining section of the article: you'll get to play with your brand-new Ubuntu Linux virtual machine! If you haven't used Linux before, I'd definitely recommend that you browse through the Ubuntu documentation at https://help.ubuntu.com/9.10/index.html.

Time for action – running Ubuntu Linux

The best way to test your new virtual machine is experimenting, so let's get on with it!
  1. Open VirtualBox (in case you closed it after the last section's exercise), select your UbuntuVB virtual machine, and click on Start to turn it on:
    VirtualBox 3.1: Beginner's Guide
  2. Ubuntu will start to boot in your virtual machine. Eventually, the Ubuntu logo will show up along with the progress bar and, after a few seconds (or minutes, depending on your hardware), the Ubuntu login screen will show up. Click inside the virtual machine screen to capture the mouse and keyboard, type the username you assigned in the installation process, and hit Enter to continue.
  3. Now type the password for your username, and hit Enter again. Ubuntu will start to load. When finished, you'll see the Ubuntu GNOME Desktop screen:
    VirtualBox 3.1: Beginner's Guide
  4. One of the first things you'll notice is the Update Manager dialog. This dialog shows up when your Ubuntu system needs software updates. Click on Install Updates to start the updating process. Normally, the Update Manager will ask for your administrator password. Type it, press Enter, or click on OK and then wait for the Update Manager to finish its job so you can work with your Ubuntu system fully updated.
  5. If the Update Manager asks you to restart your Ubuntu system after updating, click on the Restart Now button, and wait for your Ubuntu virtual machine to reboot.

What just happened?

Isn't it cool to have a little Ubuntu system running inside your real PC? Just like a pregnant mother feeling her baby's first movements! Well, not as touching, but you get the point, right?
Ubuntu is one of the friendliest Linux distributions available. That's why I decided to use it for this article's exercises. Now let's go and test the Internet connection on your new Ubuntu virtual machine!

Web browsing with Mozilla Firefox

One of the best things about the Ubuntu Desktop edition is that you can use Mozilla Firefox out of the box. And the Ubuntu Update Manager keeps it updated automatically for you!

Time for action – web browsing in your Ubuntu VM

You have your virtual machine installed. What's next? Let's surf the web! After all, what could be more important than that?
  1. Open the Applications menu on your Ubuntu virtual machine, and select Internet | Firefox Web Browser from the menu:
    VirtualBox 3.1: Beginner's Guide
  2. The Mozilla Firefox window will show the Ubuntu Start Page. Type virtualbox.org on the address bar and press Enter:
    VirtualBox 3.1: Beginner's Guide
  3. The VirtualBox homepage should appear as an indication that you have Internet access in your virtual machine. You can close Mozilla Firefox now.
If you cannot connect to Internet from your virtual machine, check your host's network settings. If you can connect from your host, try using another virtual network adapter type in your virtual machine to see if the problem disappears.

What just happened?

Well, this exercise is not really hard, right? But this is a cool way to test if your new virtual machine has Internet enabled by default. Later on, we'll talk about the different settings related to virtual network interfaces and VirtualBox. You can also know if your virtual machine can connect to Internet through the Ubuntu Update Manager because it will issue a warning if it cannot access the Ubuntu software sources. For now, it's good to know we can surf the web! Now let's see how you can do some real work inside your Ubuntu VM…

Using OpenOffice.org in your virtual machine

Ok, we have Internet enabled on our Ubuntu virtual machine; what else could we ask for? How about some word processing, a spreadsheet, and some presentations, for starters? I know it's boring, but some of us also use VirtualBox to work!

Time for action – using OpenOffice.org

Ubuntu comes with OpenOffice.org, the open source productivity suite that has proven to be an effective alternative to MS Office for Linux users. Now let's try it out on your new Ubuntu virtual machine...
  1. Open the Applications menu on your Ubuntu virtual machine, and select Office | OpenOffice.org Word Processor from the menu:
    VirtualBox 3.1: Beginner's Guide
  2. The Untitled 1 – OpenOffice.org Writer window will appear. You can use OpenOffice Writer as if you were on a real machine:
    VirtualBox 3.1: Beginner's Guide
  3. Now go to the Applications menu again, and this time select the Office | OpenOffice.org Spreadsheet option.
  4. The Untitiled 2 – OpenOffice.org Calc window will show up, overlapping the Writer window. You can also work with it as in a real PC:
    VirtualBox 3.1: Beginner's Guide
  5. And now, go back to the Application menu, and select the Office | OpenOffice.org Presentation option.
  6. The Presentation Wizard screen will show up. Select the Empty Presentation option, click on Next twice, and then click on Create to continue. The Untitled 3 – OpenOffice.org Impress window will show up, overlapping the other two windows:
    VirtualBox 3.1: Beginner's Guide
  7. Now you can close all the application windows inside your virtual machine.

What just happened?

How about that? A complete office productivity suite inside your main PC! And Internet access too! So, if you always wanted to learn about Linux or any other operating system but were afraid of messing up your main PC, VirtualBox has come to your rescue!
Now let's see how to turn off your virtual machine…

Have a go hero – trying out Ubuntu One: your personal cloud

Now that you have an Ubuntu virtual machine, you would likely benefit from trying out the Ubuntu One service, where you can back up, store, sync, and share your data with other Ubuntu One users. And the best of all, it's free! To open an account, select Applications | Internet | Ubuntu One, and follow the instructions on screen.

Have a go hero – sharing information between your VM and your host PC

Use your Ubuntu One account to transfer some files between your virtual machine and your host PC. If you're using Windows, you can work with the Ubuntu One web interface at http://one.ubuntu.com.

Shutting down your virtual machine

I know you're thinking, "Geez, I can't believe this guy! He's actually going to spend an entire subsection of this article just to show us how to shutdown a virtual machine! Aw, come on!"
Now it's my turn: Remember we're talking about a virtual machine here, not a real PC! You need to consider several things before shutting this baby down!

Time for action – shutting down your VM

Now it's time to stop whining and start learning how to shut down your virtual machine...
  1. Make sure you close all the applications inside your virtual machine, open the Mozilla Firefox Web browser, 'uncapture' your keyboard and mouse so that you can move to the VirtualBox main menu, and select the Machine | Close option.
  2. The Close Virtual Machine dialog will show up with three choices for shutting down your virtual machine. Select the Save the machine state option, and click on OK to continue:
    VirtualBox 3.1: Beginner's Guide
  3. VirtualBox will show the following dialog before shutting down the virtual machine:
    VirtualBox 3.1: Beginner's Guide
  4. Once your virtual machine's state is saved, it will shut down automatically, and you'll be returned to the VirtualBox main screen. Also, your UbuntuVB virtual machine status indicator will change from Powered Off to Saved. If you start it again, it will continue exactly where it was left off, with the Mozilla Firefox web browser window open.
  5. Start your UbuntuVB virtual machine again, leave the Mozilla Firefox window open, and select the Machine | Close menu option from the VirtualBox main menu again to open the Close Virtual Machine dialog.
  6. This time select the Send the shutdown signal option, and click on OK to continue. This has the same effect as if you had pressed the power off button on a real PC. The Shutdown the computer dialog from Ubuntu will show up:
    VirtualBox 3.1: Beginner's Guide
  7. Click on the Shut Down button to continue. Your Ubuntu virtual machine will shutdown without saving its state. This is the same as using the regular shutdown process in Ubuntu: you select the Shut Down… option from the pull-down menu in the upper right corner of your Ubuntu virtual machine. If you later start it again, the Mozilla Firefox window won't open.

What just happened?

Well, it was pretty much just a simple 'shutdown your virtual machine' exercise, don't you agree? In VirtualBox, you have three choices when shutting down your virtual machines. We already saw the first choice –Save the machine state –in action. It's kind of like suspending or hibernating a laptop computer. Your virtual machine's state 'freezes' and stays that way until you later start it again. Then, it resumes normal operation as if nothing happened. All the applications you left open will still be there.
The second choice, Send the shutdown signal, acts as if you pushed the power button on a real machine. Most modern operating systems will try to use a proper shutdown mechanism.
The third choice, Power off the machine, is like pulling the power plug on a real PC, so be careful! You could lose sensitive data if you use it carelessly! I only use this option when a virtual machine crashes and I can't shut it down with the other two choices...
Always try to use the guest operating system interface first to shutdown the virtual machine. If that fails, you can use the Send the shutdown signal option instead, but it's better to treat your virtual machine as if it were a real PC, don't forget it.
Remember that the Send the shutdown signal option only works if your guest operating system supports ACPI events. For example, this option is useless when your virtual machine is showing up the Ubuntu GRUB loader boot screen.

Have a go hero – experimenting with a KUbuntu virtual machine

There's another Ubuntu-derived distribution around called KUbuntu. Why the K? Well, the primary difference between Ubuntu and KUbuntu is that Ubuntu uses the GNOME window manager (http://www.gnome.org), and KUbuntu uses the KDE window manager (http://www.kde.org/). And which one is better? Well, that's what you need to try out for yourself...
Go and grab a copy of KUbuntu from http://www.kubuntu.org, create a virtual machine named KUbuntuVB or something like that, and install KUbuntu on it. If possible, try to run your Ubuntu and KUbuntu virtual machines at the same time to compare them, so you can decide which one is better!
And if you're feeling reckless, you should definitely try out other Linux distributions, for example: SuSE, Red Hat, Slackware, or Fedora. Come on, I know you can do it!

Summary

I hope you enjoyed the exercises in this article, especially if you've never used Ubuntu Linux before (or any other Linux distro whatsoever). Here you learned about the basic settings needed to create a virtual machine, installed the Ubuntu operating system, ran the virtual machine, and shut it down appropriately.
Specifically, we covered:
  • How to download the Ubuntu Linux Desktop Live CD
  • How to configure a new virtual machine in VirtualBox
  • How to adjust your virtual machine's basic settings to install Ubuntu on it
  • How to install the Ubuntu Linux Desktop operating system on your VM
  • How to use the VirtualBox host key and to 'capture'/'uncapture' the mouse and keyboard in your virtual machine
  • How to run your Ubuntu virtual machine and test some basic functions such as Internet access and OpenOffice.org applications
  • The different choices available when shutting down your virtual machine

Thursday, 24 June 2010

Creating Your First Virtual Machine: Ubuntu Linux (Part 1)

In this two-part article you shall:
  • Create your first virtual machine in VirtualBox, using Ubuntu Linux
  • Learn about your virtual machine's basic configuration
  • Download and install Ubuntu Linux on your virtual machine
  • Learn how to start and stop your virtual machine
So let's get on with it...

Getting started

In this article, you'll need to download the Ubuntu Linux Desktop Live CD. It's a pretty big download (700 MB approximately), so I'd recommend you to start downloading it as soon as possible. With a 4 Mbps Internet connection, you'd need approximately 1 hour to download a copy of Ubuntu Linux Desktop.
That's why I decided to change the order of some sections in this article. After all, action is what we're looking for, right?

Downloading the Ubuntu Linux Live CD

After finishing the exercise in this section, you can jump straight ahead into the next section while waiting for your Ubuntu Live CD to download. That way, you'll have to wait for less time, and your virtual machine will be ready for some action!

Time for action – downloading the Ubuntu Desktop Live CD

In the following exercise I'll show you how to download the Ubuntu Linux Desktop Edition from the official Ubuntu website.
  1. Open your web browser, and type http://www.ubuntu.com in the address bar. The Ubuntu Home Page will appear. Click on the Ubuntu Desktop Download link to continue:



    VirtualBox 3.1: Beginner's Guide

  2. The Download Ubuntu page will show up next. Ubuntu's most recent version will be selected by default (Ubuntu Desktop 9.10, at the time of this writing). Select a location near you, and click on the Begin download button to continue.


    The Ubuntu Download page lets you download the 32-bit version automatically. If you want the 64-bit version of Ubuntu 9.10, you'll need to click on the Alternative download options link below the Download locations list box. The exercises in this article use the 32-bit version.
  3. You'll be taken to the download page. After a few seconds, your download will start automatically. Select the Save File option in your browser, and click on OK to continue.
  4. Now you just have to wait until the download process finishes.

What just happened?

I think the exercise pretty much explains itself, so I just want to add that you can also order a free Ubuntu CD or buy one from Ubuntu's website. Just click on the Get Ubuntu link at the front page and follow the instructions. I ordered mine when writing this article to see how long it takes to arrive at my front door. I hope it arrives before I finish the book!

Have a go hero – doing more with the thing

You can try downloading other Ubuntu versions, like Ubuntu 8.10 Hardy Heron. Just click on the Alternative download options link below the Download locations list box, and explore the other options available for download.

Creating your Ubuntu Linux VM

Now that you installed VirtualBox, it's time to learn how to work with it. I've used other virtualization products such as VMware besides VirtualBox, and in my humble opinion, the user interface in VirtualBox is a delight to work with.

Time for action – creating a virtual machine

At last you have the chance to use Windows and Linux side by side! This is one of the best features VirtualBox has to offer when you want the best of both worlds!
  1. Open VirtualBox, and click on the New button (or press Ctrl+N) to create a new virtual machine:



    VirtualBox 3.1: Beginner's Guide
  2. The Welcome to the New Virtual Machine Wizard! dialog will show up. Click on Next to continue. Type UbuntuVB in the Name field, select Linux as the Operating System and Ubuntu as the Version in the VM Name and OS Type dialog.
  3. Click on Next to continue. You can leave the default 384 MB value in the Memory dialog box or choose a greater amount of RAM, depending on your hardware resources.
  4. Click on Next to continue. Leave the default values in the Virtual Hard Disk dialog, and click on Next twice to enter the Create New Virtual Disk wizard. Leave the default Dynamically Expanding Storage option in the Hard Disk Storage Type dialog, and click on Next to continue.
  5. Leave the default values chosen by VirtualBox for your Ubuntu Linux machine in the Virtual Disk Location and Size dialog (UbuntuVB and 8.00 GB), and click on Next to continue.
  6. A Summary dialog will appear, showing all the parameters you chose for your new virtual hard disk. Click on Finish to exit the Create New Virtual Hard Disk wizard. Now another Summary dialog will appear to show the parameters you chose for your new virtual machine. Click on Finish to exit the wizard and return to the VirtualBox main window:



    VirtualBox 3.1: Beginner's Guide
  7. Your new UbuntuVB virtual machine will appear on the VirtualBox main screen, showing all its parameters in the Details tab.

What just happened?

Now your Ubuntu Linux virtual machine is ready to run! In this exercise, you created a virtual machine with all the parameters required for a typical Ubuntu Linux distribution. The first parameter to configure was the base memory or RAM. As you saw in step 3, the recommended size for a typical Ubuntu Linux installation is 384 MB.

Exercise caution when selecting the RAM size for your virtual machine. The golden rule of thumb dictates that, if you have less than 1 GB of RAM, you can't assign more than one half of your physical RAM to a virtual machine because you'll get into trouble! Your host PC (the one that runs VirtualBox) will start to behave erratically and could crash!

With 2 GB, for example, you can easily assign 1 GB to your virtual machine and 1 GB to your physical PC without any problems. Or you could even have three virtual machines with 512 MB of RAM each and leave 512 MB for your host PC. The best way to find out the best combination of RAM is to do some experimenting yourself and to know the minimum RAM requirements for your host and guest operating systems.

Don't assume that assigning lots of RAM to your virtual machine will increase its performance. If, for example, you have 2 GB of RAM on your host and you assign 1 GB to an Ubuntu virtual machine, it's very unlikely there will be a bigger performance increase than if you were assigning only 512 MB to the same Ubuntu virtual machine. On the contrary, your host PC will work better if you only assign 512 MB to the Ubuntu virtual machine because it will use some of the extra RAM for disk caching, instead of recurring to the physical hard disk. However, it all depends on the guest operating system you plan to use and what applications you need to run.

If you look closely at the Base Memory Size setting in the Memory dialog when creating a virtual machine, you'll notice that there are three memory areas below the slider control: the green-colored area indicates the amount of memory range you can safely choose for your virtual machine; the yellow-colored area indicates a dangerous memory range that you can choose, but nobody knows if your virtual machine and your host will be able to run without any problems; and the red-colored area indicates the memory range that your virtual machine can't use. It's wise to stick with the default values when creating a new virtual machine. Later on, if you need to run a memory-intensive application, you can add more RAM through the Settings button, as we'll see in the following section.

Another setting to consider (besides memory) when creating a virtual machine is the virtual hard drive. Basically, a virtual hard disk is represented as a special file on your host computer's physical hard disk, and it's commonly known as a disk image file. This means that your host computer sees it as a 'large' file on its system, but your virtual machine sees it as a 'real' hard disk connected to it. Since virtual hard drives are completely independent from each other, there is no risk of accidental overwriting, and they can't be larger than the free space available on your real computer's physical hard drive. This is the most common way to handle virtual storage in VirtualBox; later on, we'll see more details about disk image files and the different formats available.

VirtualBox assigns a default value based on the guest operating system you plan to install in your virtual machine. For Ubuntu Linux, the default value is 8 GB. That's enough space to experiment with Ubuntu and learn to use it, but if you really want to do some serious work —desktop publishing or movie production, for example—you should consider assigning your virtual machine more of your hard disk space.
You can even get two hard drives on your physical machine, and assign one for your host system and the other one for your virtual machine! Or you can also create a new virtual hard disk image and add it as if it were a second hard drive!

Before going to the next section, I'd like to talk about the two virtual hard disk storage types available in VirtualBox: dynamically expanding storage and fixed-size storage. The Hard Disk Storage Type dialog you saw in step 4 of the previous exercise contains a brief description for both types of storage. At first, the dynamically expanding option might seem more attractive because you don't see the space reduction in your hard drive immediately.

When using dynamically expanding storage, VirtualBox needs to expand the storage size continuously, and that could mean a slight decrease in speed when compared to a fixed-size disk, but most of the time this is unnoticeable. Anyway, when the virtual hard disk is fully expanded, the differences between both types of storage disappear.

Most people agree that a dynamically expanding disk represents a better choice than a fixed one, since it doesn't take up unnecessary space from your host's hard disk until needed. Personally, when experimenting with a new virtual machine, I use the dynamically expanding option, but when doing some real work, I like to set apart my virtual machine's hard disk space from the beginning, so I choose the fixed-size storage option in these cases.

Have a go hero – experimenting with memory and hard disk storage types

When creating a virtual machine, you can specify the amount of RAM to assign to it instead of using the default values suggested by VirtualBox. Create another virtual machine named UbuntuVB2, and try to assign the entire RAM available to it. You won't be able to continue until you select a lower value because the Next button will be grayed out, which means you're in the red-colored memory range. Now move back the slider until the Next button is active again; you'll probably be in the yellow-colored memory range. See if your virtual machine can start with that amount of memory and if you can use both your host PC and your VM without any problems. In case you encounter any difficulties, keep moving back the memory range until all problems disappear.

Once you're done experimenting with the memory setting, use the UbuntuVB2 virtual machine with the same exact settings as the one you created in the previous exercise, but this time use a fixed-size hard drive. Just take into account that since VirtualBox must prepare all the storage space at once, this process may take a long time depending on the storage size you selected and the performance of your physical hard disk. Now go and try out different storage sizes with both types of disks: dynamically expanding and fixed size.

Configuring basic settings for your Ubuntu Linux VM

All right, you created your Ubuntu virtual machine and downloaded a copy of Ubuntu Desktop Live CD. Can you start installing Ubuntu now? I know you'll hate me, but nope, you can't. We need to tell your virtual machine where to boot the Live CD from, as if we were using a real PC. Follow me, and I'll show you the basic configuration settings for your VM, so you can start the Ubuntu installation ASAP!

Time for action –basic configuration for your VM

In this exercise you'll learn how to adjust some settings for your virtual machine, so you can install Ubuntu Linux on it.
  1. Open VirtualBox, select your UbuntuVB virtual machine, and click on the Settings button:



    VirtualBox 3.1: Beginner's Guide
  2. The UbuntuVB – Settings dialog will appear, showing all the settings in the General tab.
  3. Click on the Storage category from the list in the left panel. Then select the Empty slot located just below the UbuntuVB.vdi hard disk image, under the IDE Controller element inside the Storage Tree panel, and click on the Invoke Virtual Media Manager button:


    VirtualBox 3.1: Beginner's Guide
  4. The Virtual Media Manager dialog will appear next. Click on the Add button to add the Ubuntu Linux Live CD ISO image:


    VirtualBox 3.1: Beginner's Guide
  5. The Select a CD/DVD-ROM disk image file dialog will show up next. Navigate to the directory where you downloaded the Ubuntu Desktop ISO image, select it, and click on the Open button to continue.
  6. The Ubuntu Desktop ISO image will appear selected in the CD/DVD Images tab from the Virtual Media Manager dialog. Click on the Select button to attach the Ubuntu ISO image to your virtual machine's CD/DVD drive.
  7. Next, the Ubuntu ISO image file will appear selected on the ISO Image File setting from the UbuntuVB – Settings dialog. Click on OK to continue.
  8. Now you're ready to start your virtual machine and install Ubuntu!

What just happened?

As you can see from the previous exercise, your virtual machine is just like a real PC. You need to 'insert' a bootable CD so that the VM can boot and start installing Ubuntu. In this case, we used an ISO image of Ubuntu Desktop instead of having to insert a real bootable CD. That's one of the benefits of VirtualBox: you can forget about having to burn a CD to test the new Ubuntu version or any other operating system! You just need to download the ISO image and configure your virtual machine to act as if there was a real CD inserted in the CDROM drive!

You can also go the traditional way, in case you have a DVD or CD ready to install your Ubuntu Desktop system. Just insert your DVD/CD, click on your virtual machine's Settings button, go to the CD/DVD-ROM category, and select the Host CD/DVD drive option instead of ISO Image File.
Whichever option you choose, your virtual machine will start to boot like a real physical PC! In the following section you'll get to see it with your own eyes...

Installing Ubuntu Linux on your VM

Now everything's ready to start installing Ubuntu! At last you're about to see this wonderful piece of software in action...

Time for action – installing Ubuntu Desktop on your VM

Ok, it's time to try out our new toy! Get ready for the ride of your life...
  1. Click on the Start button to start your virtual machine:



    VirtualBox 3.1: Beginner's Guide
  2. An Information dialog will appear to tell you that the Auto capture keyboard option is turned on. Enable the Do not show this message again option, and click on OK to continue.
  3. Another Information dialog will show up to tell you about the color depth of your virtual machine. Enable the Do not show this message again option, and click on OK to continue.
  4. The Ubuntu menu screen will show up, along with a pop-up menu where you can select the language of installation. Click anywhere inside the virtual machine screen, and the following information dialog will pop up:


    VirtualBox 3.1: Beginner's Guide
  5. Enable the Do not show this message again, and click on Capture to continue. The mouse pointer will disappear, and you will be able to move along the language menu. Select the English option, and press Enter to continue.
  6. Remember you can press Right-Ctrl, the default host key, at any time to uncapture the keyboard and mouse so you can move your mouse pointer out of the virtual machine screen.
  7. Now select the Install Ubuntu option on the Ubuntu start-up menu, and press Enter:



    VirtualBox 3.1: Beginner's Guide
  8. Ubuntu will start to boot and, depending on your hardware, it will take some time to boot up completely. A red bar below the Ubuntu logo will appear to show the progress of the booting process (the bar should turn completely yellow when it's finished).
  9. At the end of the Ubuntu booting process, the Welcome screen will appear, as shown below:



    VirtualBox 3.1: Beginner's Guide
  10. Select the language you want to use for the installation process (in this exercise, we'll stick with English). Click on Forward to continue. Select your Region and City in the Where are you? screen, and click on Forward to continue.
  11. The Keyboard layout screen will appear next. You can leave the default option if you're using a typical QWERTY keyboard or choose an appropriate layout for your keyboard. To be sure the layout you chose works with your keyboard, type something into the test box. Click on Forward when you're ready to continue the installation process.
  12. The Prepare disk space Use the entire disk) to let Ubuntu prepare the disk for you. Click on Forward to continue.
  13. Remember you're using a virtual hard disk and not the physical hard drive of your real PC; it's perfectly ok to use the entire virtual hard disk for your Ubuntu guest operating system; the rest of the files in your real hard drive won't be affected.
  14. On the next screen (Who are you?), you need to fill in your name, username, password, and your computer's name. You can also choose to login automatically or require a password to login. Use the following screenshot as a guide, but remember to replace my personal info with yours! Click on Forward when you're ready to continue:



    VirtualBox 3.1: Beginner's Guide
  15. The Ready to Install screen will show up next with a summary of all the settings you chose for the Ubuntu installation. Click on Install when you're ready to begin the installation process.
  16. Ubuntu will start to install in your virtual machine. An Installing System dialog will show you the installation progress:



    VirtualBox 3.1: Beginner's Guide
  17. After some time (depending on your hardware speed), the Installation Complete dialog will appear. Click on Restart Now to exit the installer.
  18. Eventually, the Ubuntu logo will show up. In a real PC, you would have to remove the installation disc and press Enter. In this case, you need to shutdown the virtual machine and change the CD-DVD Rom drive setting. Hit the Right-Ctrl key to uncapture the mouse so you can move it to select the Machine | Close option from the VirtualBox main menu:



    VirtualBox 3.1: Beginner's Guide
  19. The Close Virtual Machine dialog will appear next. Select the Power off the machine option, and click on OK to continue.
  20. VirtualBox will shutdown the virtual machine, and you'll return to the main screen. Now click on the Settings button to open the UbuntuVB – Settings dialog, go to the Storage category, select the ubuntu-9.10-desktop-i386. iso image in the Storage Tree panel; then click on the CD/DVD Device list box, and select the Empty option to remove the Ubuntu ISO image:



    VirtualBox 3.1: Beginner's Guide
    Click on OK to close the UbuntuVB – Settings dialog. Your virtual machine is now ready to start Ubuntu Linux for the first time!

What just happened?

Ok, you mixed up all the ingredients, baked the mix, and now the cake is ready to eat! Sorry about the analogy, but I was hungry at the time I wrote this!

Personally, I think this is one of the coolest things I've seen in the last few years... Installing a completely standalone guest operating system inside a host operating system with just a few clicks... Whew! Now we'll really start to squeeze all the juice out of our hardware! But before jumping to the next exercise, there are a few things I want to talk about.

Every time you start a virtual machine in VirtualBox, it has to share the keyboard and the mouse with your real PC. The Auto capture keyboard feature lets your virtual machine 'capture' all the keyboard action automatically every time you activate its window, and it's enabled by default on every new virtual machine. As you saw in step 2, an information dialog shows up when starting a virtual machine for the first time to tell you about this feature.

Also, if you click with your mouse inside the virtual machine's window, it will 'capture' all your mouse movements, as the information dialog in step 4 indicates. And how can we 'uncapture' the keyboard and the mouse to use it outside the virtual machine again? VirtualBox uses a special key, called the Host Key, for this purpose. By default, the host key is Right Ctrl.

To redefine the host key, you need to go to the VirtualBox main screen and select File | Preferences in the main menu:
VirtualBox 3.1: Beginner's Guide
Then you need to select the Input category in the VirtualBox – Settings dialog, click on the Host Key field, and then hit the key you want to use as the new host key. Finally, you just need to click on the OK button to apply the changes.

Once you define the key you want to use as the host key, you can use it to 'capture' and 'uncapture' the keyboard and the mouse in your virtual machine. Every VM shows the actual state of the host key at the bottom-right part of its main window:
VirtualBox 3.1: Beginner's Guide
In short, to use your virtual machine, you need to move your mouse inside its main window and click on it. You can also select the virtual machine's window and hit the host key to 'capture' the keyboard and the mouse. Then, if you want to exit your virtual machine and use something on your host PC, you just hit the host key, and you can move your mouse out of the virtual machine's window, along with your keyboard. Simple enough, right?

The last thing I want to mention is the color depth of your virtual machine's screen. In step 3 of the previous exercise, an information dialog appeared on your virtual machine to tell you about this. Now let's just try out your new Ubuntu virtual machine!