Tuesday, November 17, 2009

Set up a PDF Printer in your Linux box

Do you wish to take a pdf copy of the pages or convert a document into a .pdf file? or you do not have a printer and wish to print a web-page?

You can install a PDf printer in your linux machine, so that all you need (to convert a document into a pdf file) is to print the document and choose your PDF printer instead of your usual printer.

By default, CUPS-PDF is not installed, so grab it by using
$ sudo apt-get install cups-pdf
You should then be able to add a fake printer that will convert print jobs to PDF files.

Go to System -> Administration -> Printing to bring up the Printer configuration dialog. Select New Printer from the toolbar, and walk through the New Printer Wizard. You can give the printer pretty much any name you want. PDF seems like a logical choice. The Description and Location fields are optional.

On the next screen, when asked to select a connection, choose Virtual Printer, and leave the device URI as it is: cups-pdf:/. Next, on the screen where you can select a Printer from the database, choose Generic. On the next screen, choose PostScript as the Model and as the driver for the printer. Then you'll see a screen that says "Going to create a new printer PDF at cups-pdf:/." Click Apply and you should have a virtual PDF printer.

Now you should be able to create PDF files from most Linux apps by sending your print jobs to the PDF printer. When you send jobs to the printer, they'll be saved to a directory under your home directory that's named after the virtual printer -- so if you choose PDF as the name of your virtual printer, then the jobs will be sent to /home/yourusername/PDF.

Happy printing :)

Thursday, November 12, 2009

Install Google Chrome browser in Ubuntu Linux

Here is a way to run your favourite Google Chrome browser in your Ubuntu Linux desktop.

(Note: Athough there are other ways of installing Chrome on Wine, I have found that is not very efficient.)

So here is a quick and dirty way :)

Open apt sources file
$ sudo nano /etc/apt/sources.list
Add these lines at the end

deb http://ppa.launchpad.net/chromium-daily/ppa/ubuntu jaunty main
deb-src http://ppa.launchpad.net/chromium-daily/ppa/ubuntu jaunty main

Save (Ctrl+O) and Exit (Ctrl+X) nano.

Update apt
$ sudo apt-get update
Then install Chrome browser with the following command
$ sudo apt-get install chromium-browser
Enjoy ! ;)

___________________________________

Incase you get the following error (while running apt-get update):
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 5A9BF3BB4E5E17B5

(It means you need to import the key for "Launchpad PPA for chromium-daily")

Resolution: Run the following command
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 5A9BF3BB4E5E17B5

---------------------------------------

Installing Java in Ubuntu Linux

One of the reasons I love Ubuntu (Linux) is because it comes with a great number of packages.

Ubuntu has the following Java packages

sun-java6-bin – Contains the binaries
sun-java6-demo – Contains demos and examples
sun-java6-doc – Contains the documentation
sun-java6-fonts – Contains the Lucida TrueType fonts from the JRE
sun-java6-jdk – Contains the metapackage for the JDK
sun-java6-jre – Contains the metapackage for the JRE
sun-java6-plugin – Contains the plug-in for Mozilla-based browsers
sun-java6-source – Contains source files for the JDK

Here is a quick and dirty way to install Java in your Ubuntu desktop / server

Edit the sources list
$ sudo nano /etc/apt/sources.list
Insert the following lines at the end of the file

deb http://us.archive.ubuntu.com/ubuntu dapper main restricted
deb http://us.archive.ubuntu.com/ubuntu dapper universe multiverse

Save (Ctrl+O ) and Exit (Ctrl+X) the file.

Update apt
$ sudo apt-get update
Now in terminal run the command line
$ sudo apt-get install sun-java6-jre sun-java6-plugin sun-java6-fonts
Agree to the terms and java will install automatically.


Test that Java install is successful
Run command
$ java -version
You will get something like
java version “1.6.0″
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
________________________________________________________

For manually installing java, you may follow the instructions here
http://sites.google.com/site/easylinuxtipsproject/java#TOC-HOW-TO-FOR-32-BIT-UBUNTU
________________________________________________________

Monday, November 2, 2009

Hamachi gets killed in Ubuntu 9.10

Problem: Hamachi gets Killed after upgrading to Ubuntu 9.10

Cause: Hamachi's binary is compressed with upx. You just need to uncompress it.

Resolution:
Assuming /usr/bin is were hamachi's binary is in the computer, run the following commands

# sudo apt-get install upx-ucl
# cd /usr/bin    [Assuming /usr/bin is were hamachi's binary is]
# sudo upx -d hamachi
Ultimate Packer for eXecutables
Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007
UPX 3.01        Markus Oberhumer, Laszlo Molnar & John Reiser   Jul 31st 2007
File size         Ratio      Format      Name
--------------------   ------   -----------   -----------
830676 <-    331144   39.86%    linux/386    hamachi
Unpacked 1 file.

Try starting hamachi after that.

Thursday, October 29, 2009

Clone VirtualBox hard disk image

Since I am now testing VirtualBox performance, I need to clone existing guest image for multi-testing. This mini-HOWTO will guide you though the procedure for cloning a guest storage file for a new guest, under MS Windows host.

When following the official guideline and document, using VBoxManage clonehd command for disk clone, the result image is ALWAYS not functioning. Finally I figure out that a non-documented internal command is required: VBoxManage internalcommands sethduuid.

Within this artical, I am using the following system setup:

VirtualBox: v2.1.0

Host: MS Windows Vista Home Basic

Guest: Debian Lenny

Official procedure for cloning disk image (not function on MS Windows host)

Cloning an existing disk image for VirtualBox is much more than a simple copy command: it is because VirtualBox assigns a unique identity number (UUID) to each disk image, which also stored inside the image. VirtualBox will refuse to work with two image that use the same number. You need some extra handling.

According to official document, what you need is the console command VBoxManage clonehd, e.g. (host with MS Windows):

"C:\Program Files\Sun\xVM VirtualBox\VBoxManage.exe" clonehd hda.vdi hdb.vdi

or (host with Linux):

VBoxManage clonehd hda.vdi hdb.vdi

Therefore VirtualBox will copy your disk image, assign a new UUID for it, and import to its virtual media manager. You can now use it for your new guest system.

Alternative non-documented solution

As now you understand how the vboxmanage clonehd work around, what we needed is a new-and-unique UUID for our cloned disk image. There is a non-documented internal command which target for this procedure: VBoxManage.exe internalcommands sethduuid.

So what you needed for are:

(Optional) Shutdown your target guest before disk clone.

Manually copy the existing disk image, e.g.

copy hda.vdi hdb.vdi

Set a new UUID for the cloned disk, e.g.

"C:\Program Files\Sun\xVM VirtualBox\VBoxManage.exe" internalcommands sethduuid hdb.vdi

Manually add this newly cloned disk image though VirtualBox "Virtual Media Manager".

Create a new guest profile as old system, and point the primary harddisk to your newly cloned disk image.

(Document is retrieved from Google cache http://209.85.229.132/search?q=cache:http://edin.no-ip.com/content/clone-virtualbox-disk-image-ms-windows-mini-howto )

Monday, October 19, 2009

Managing Disk space with OpenVZ

You can increase the limit from the host system (VE0) only. This is how:

1. Get the current values for disk quota:

# vzquota stat 123
resource usage softlimit hardlimit grace
1k-blocks 327664 1048576 1153434
inodes 18857 200000 220000

2. To increase the disk space quota, use vzctl set --diskspace. For example, we want to increase it by a factor of 2:

vzctl set 123 --diskspace $(( 1048576*2 )):$(( 1153434*2 )) --save

3. To increase the disk inodes quota, use vzctl set --diskinodes. For example, we want to increase it by a factor of 3:

vzctl set 123 --diskinodes $(( 200000*3 )):$(( 220000*3 )) --save

Note: shell does not support floating-point arithmetics, i.e. you can not use expressions like $(( 220000*1.5 )). To use floating point, try bc instead, something like this: $(echo 220000*1.5 | bc).

Disk space and inodes are different things. Inodes identify the physical location on a disk where a file resides in unix filesystems. The inode count reflects the number of files on the server, not the amount of space used. This allows for multiple paths (hard links) to point to a single file.

A guide to running OpenVZ

By Joe 'Zonker' Brockmeier

One of the many virtualization options for Linux is OpenVZ, the free software component of SWsoft's Virtuozzo. OpenVZ, and Virtuozzo, are OS-level virtualization solutions that allow you to partition servers into multiple virtual private servers (VPS). Plowing through the OpenVZ documentation can be a bit intimidating, so let's walk through the easy way of getting started with OpenVZ on a Debian Etch system.
Last year, I reviewed Virtuozzo 3.0 for Linux, and I'd had some hands-on experience with prior versions of Virtuozzo from my days working with a hosting company in Denver. My budget doesn't have room for the Virtuozzo licensing, but OpenVZ fits my pocketbook just fine.
When would you want to use OpenVZ rather than VMware Server or Xen? It depends on the situation. For tasks where you don't want to run multiple OSes, but rather just multiple guests, in order to make the most of hardware or provide separation between services (for instance, separating your Web server from your file and print server) with minimal overhead, OpenVZ is a good choice. However, when you want to run non-Linux operating systems (such as FreeBSD or Windows Server) on top of a Linux host, you'd want to go with VMware rather than OpenVZ (or its commercial and proprietary big brother, Virtuozzo), since OpenVZ doesn't offer the ability to run multiple OSes.
OpenVZ also supports more processor platforms than the alternatives. VMware Server and Xen are available for x86 and AMD64, while OpenVZ is available for x86, AMD64, Itanium (IA64), PowerPC, and UltraSPARC.
Note that there are no pre-built PowerPC kernels for Debian at the moment, but OpenVZ is supported on PowerPC.
Installing OpenVZ
You can run OpenVZ guests on any host system. I'm running my guests on a Debian system, but you can use Ubuntu, Fedora Core, Gentoo, or any other distro that has an OS template. The OS template is the set of packages used to populate a VPS, AKA virtual environment (VE) in OpenVZ lingo.
Debian kernels for OpenVZ guests are available from the OpenVZ repository, but only for Etch. Grab the most recent kernel and linux-headers package from the OpenVZ repository, and install them using

dpkg -i linux-image-2.6.18-openvz-686_02_i386.deb

and

dpkg -i linux-headers-2.6.18-openvz-686_02_i386.deb .
Replace the package name with the name of the file that you download, of course. When I installed the packages, dpkg complained about two symlinks pointing to missing directories, but I haven't seen any problems while using OpenVZ, so as far as I can tell this isn't a problem.
Once you've installed the kernel and the headers, you'll want to add a few parameters (found on the the OpenVZ wiki) to /etc/sysctl.conf to prep the system for running OpenVZ. For example, you need to tell the system to enable IP forwarding so that the VPSes can have networking as well. Just add these lines to sysct.conf if they're not already present, or make sure they match:

net.ipv4.ip_forward = 1
net.ipv4.conf.default.proxy_arp = 0
net.ipv4.conf.all.rp_filter = 1
kernel.sysrq = 1
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0

After installing the kernel and making these changes, you'll need to reboot the system. The OpenVZ kernel should be set to the default kernel in the GRUB menu already, so just rebooting should do the trick.
Next, you'll need to grab the OpenVZ utilities, using apt-get install vzctl. This will install the vzctl and vzquota packages, which include the utlities (like vzctl) that you need to use to manage OpenVZ.
OpenVZ will be set to start up at boot after you install these utilities, but if you want to start playing right away, you need to start up OpenVZ manually this time (or reboot). Start up OpenVZ by running the init script:
/etc/init.d/vz start

Setting up a guest system
So far so good. Now it's time to grab a few templates and set up a guest operating system. You can find precreated templates on the OpenVZ download site, including several versions of Fedora Core, Debian Sarge and Debian Etch, CentOS, Gentoo, Mandriva, and openSUSE. Note that templates are processor-specific, so be careful not to download the AMD64 or UltraSPARC version of a template if you're going to be running it on a x86 system.
You'll also notice that there's a contrib directory with OS templates from the OpenVZ community. These aren't "official" templates, but if you want to run Ubuntu, Slackware, AltLinux, or another distro not found with the OpenVZ templates, look here.
If you want to run a distro that doesn't have a template, see the OpenVZ wiki for documentation on creating OS templates. This is one area where OpenVZ is at a disadvantage to VMware and some of the other virtualization technologies. Installing a Linux distro in VMware Server or VMware Workstation is usually as simple as running through that distro's installation procedure. In OpenVZ it's much more complicated, and you'll need to learn a lot more about OpenVZ than you might want to just to run a couple of guest instances.
Downloaded OS templates need to be stored in /var/lib/vz/template/cache. The templates are tarred and gzipped when you download them, and you want to leave them that way -- don't uncompress them.
To set up a system, use the vzctl utlity. The bad news is that the vzctl utility is nowhere near as easy to use as the GUI tools that come with Virtuozzo. The good news is that vzctl isn't that difficult to use, it's scriptable, and it's free in every sense of the word. If you manage a lot of OpenVZ systems, you'll have the syntax down in no time, and if you don't create or muck with your OpenVZ guest systems very often, it shouldn't be too time-consuming to whip out the vzctl utlity man page and figure out the options you want. Let's take a look at the most common commands.
The syntax for creating a guest system is vzctl create vpsid --ostemplate ostemplatename . The vpsid is the number assigned to the new system. OpenVZ reserves IDs below 100 for internal use, so I usually start assigning IDs at 1001. So, for instance, if you download the Debian Sarge OS template for x86, you'd run:
vzctl create 1001 --ostemplate debian-3.1-i386-minimal
Once a guest host is set up, you can find its filesystem under /var/lib/vz/root/vpsid, and its private area under /var/lib/vz/private/vpsid -- unless you change the defaults using the --root or --private options. The private directory contains files specific to the virtual environment (VE).
So, if you created the guest as vz number 1001, its root filesystem would be under /var/lib/vz/root/1001. This may come in handy if you ever need to access the files directly for some reason -- for example, if the guest's admin has made a configuration that prevents the guest from booting normally -- or for backup purposes.

Now, let's set up networking. Again, this isn't terribly difficult:

vzctl set --ipadd ipaddr --nameserver nameserverIP --hostname hostname --save

The --ipadd parameter assigns the IP address to the first venet interface in the guest OS, the --hostname assigns the VPS its hostname, and the --nameserver paramter provides the first nameserver. The venet interface provided to OpenVZ guest systems by default does not have a MAC address, which means that (among other things) you cannot grab an address via DHCP for an interface.

However, the OpenVZ folks have added a new type of interface called a veth, which can provide a MAC address. The veth device also allows users to set up a DHCP server within the guest OS, and users can set their own network settings -- which is not possible using the venet devices. Whether this is desirable is another question. If you'd like to provide veth interfaces rather than venet interfaces, see the OpenVZ wiki for setup instructions.


Managing OpenVZ
Once the VPS is set up, go ahead and start the guest by running vzctl start vpsid , where vpsid is the ID that you assigned to the guest when you created it.
You should see a few messages logged to the console about starting the VPS, ending with "VPS start in progress..." You can see what VPSes are running with the vzlist command. After running vzlist, you should see something like this:

VPSID       NPROC         STATUS   IP_ADDR     HOSTNAME
1002              4                running     10.0.1.34   vroomfondle

Use the -a option to display all VPSes, whether they are running or not. You might also want to see what resources are being consumed by a VPS. To see how much memory is being used by a VPS, run
vzcalc -v vpsid
You should see something like this:

Resource    Current(%)        Promised(%)          Max(%)
Low Mem        0.13                   1.20                        1.20
Total RAM      0.55                   n/a                          n/a
Mem + Swap  0.36                  1.83                         n/a
Alloc. Mem     0.67                 1.83                         13.82
Num. Proc      0.06                  n/a                          0.40
--------------------------------------------------------------
Memory          0.67                   1.83                        13.82

This will show you how much memory is being used by the VPS, how much is allocated to the VPS, and what it can grow to.

You can also see other VPS parameters using the -o option. See the vzcalc man page for more information.
By default, VPSes will not be started up when you boot the system. In most situations, though, you probably do want VPSes to load after a system has restarted. You can change this setting using vzctl:
vzctl set vpsid --onboot yes --save
The vzctl utility is also used to set system parameters, including the amount of memory, CPU resources, access to iptables modules, and more. Let's look at a few examples.
One of the things that is frustrating about OpenVZ is that it's not straightforward to say "give a VPS 256MB of RAM"; instead, you have to adjust a couple of parameters and read through some fairly technical docs to try to make sense of the way that OpenVZ deals with memory.

To make things a bit simpler, let's look at setting a VPS with a minimum of 256MB of RAM, and up to 1GB. To do that, set the vmguarpages (that's the memory that's guaranteed to the VPS) and privvmpages (that's the maximum amount of memory that will be granted) parameters:

vzctl set vpsid --vmguarpages 65536 --save
vzctl set vpsid --privvmpages 262144 --save
I found another way to do this that is much more intuitive than calculating the amount of RAM by "pages" on the SWsoft forum. Just multiply the amount of RAM that you want by 256 as an easy way to arrive at the right amount of RAM:
vzctl set vpsid --vmguarpages $((256 * 256)) --save
vzctl set vpsid --privvmpages $((256 * 1024)) --save
Read the vzctl man page, as well as the OpenVZ wiki and other documentation, for more information.
As you set parameters for each VPS, the configuration settings are stored in /etc/vz/conf/vpsid.conf. If you make any changes to this file manually, you can use the vzcfgvalidate utility to make sure that the configuration file is correct.
Often, in hosting situations, you need to get into a system where the admin has changed the root password. With physical systems, you need to reboot the system and enter single-user mode to get root access to handle administrative tasks. With OpenVZ, all you need to do is log into the hardware node and use vzctl to log in:
vzctl enter vpid
That will log you into the VPS as root. After you've finished whatever admin tasks you need to perform, just type exit and you'll be returned to the session on the host system. Or, if you want to reset a password for a user, you can just use the --userpasswd option:
vzctl set vpsid --userpasswd user:passwd
If the user does not exist, it will be created.
If you'd like to run a command in a VPS without actually entering the VPS, you can use the exec parameter for vzctl to run a command as root. For example, if you want to run a quick upgrade inside a Debian VPS:
vzctl exec vpsid apt-get upgrade
This will run apt-get upgrade within the VPS itself.
To shut down a VPS, run vzctl stop vpsid, which will execute a clean shutdown within the VPS.
Running vzctl restart vpsid will restart the VPS. VPSes can also be shut down or rebooted normally from within the VPS.
So long, goodbye
So, your guest system has had a good run, but it's time to pack it in. For whatever reason, if you have a VPS that you'd like to get rid of, use the destroy command with vzctl:
vzctl destroy veid
A note of caution here: the vzctl utility does not ask for confirmation before destroying the VPS. As soon as you press Enter, that's all she wrote -- the VPS will be removed, its private data directories removed, and if you don't have a backup, you are up a creek without a paddle if you need to retrieve the data.

First openVZ installation with yum

So in short after having my bare bones install here is my quick and dirty easy to follow steps
from Scott's article:
1. cd /etc/yum.repos.d
2. wget http://download.openvz.org/openvz.repo
3. yum install ovzkernel
4. nano -w /etc/sysctl.conf with these changes:

______________________
# On Hardware Node we generally need
# packet forwarding enabled and proxy arp disabled
net.ipv4.ip_forward = 1
net.ipv4.conf.default.proxy_arp = 0
# Enables source route verification
net.ipv4.conf.all.rp_filter = 1
# Enables the magic-sysrq key
kernel.sysrq = 1
# TCP Explict Congestion Notification
# net.ipv4.tcp_ecn = 0
# we do not want all our interfaces to send redirects
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0

_____________________

5. Set the default kernel in grub to the new one
6. Reboot using the new kernel
7. yum install vzctl vzquota
8. service vz start
9. yum install vzpkg vzyum vzrpm43-python vzrpm44-python
10. yum install vztmpl-centos-4
11. nano -w /vz/template/centos/4/i386/config/default.list appending this:
yum
mc
links
system-config-date
nano
12. vzpkgcache -f centos-4
13. vzctl create 101 --ostemplate centos-4 --config vps.basic
14. vzctl set 101 --ipadd 192.168.0.101 --save
15. vzctl set 101 --hostname vps101 --save
16. vzctl set 101 --nameserver 192.168.0.1 --nameserver 192.168.0.2 --save
17. vzctl set 101 --userpasswd root:areallycoolpassword
18. vzctl set 101 --onboot yes --save
19. vzctl start 101
20. vzctl enter 101

Okay so that is it in a nutshell. Then this is where I start getting into trouble with my wild
ideas. I mentioned wanting to make this my backup server and I normally use Dirvish, but this
time I want to try out BackupPC. Now I also have a nice 300GB drive I have used for my
time I want to try out BackupPC. Now I also have a nice 300GB drive I have used for my
backups and I planned on just mounting it inside this new VPS.

Problem is I couldn't figure out
how to give it enough diskspace quota. The most it would give was from my 40GB drive and
that was a 34GB quota. So I called Scott and pretty much just decided to do LVM (logical
volume management) and merge the drives together to make it look like one big drive. This
however entailed starting from scratch again as I'm pretty lazy when it comes to trying to
figure out installing something like this after the fact.
So I find my single CentOS CD and attempt to boot it but my crappy old Dell has an abused
CD-R drive. So I borrow the one out of another Dell and off we go. So when I get back to the
point I was last, I run this:

vzctl set 101 --diskspace 315621376:315621376 --save

This gives me 301GB disk space to work with in my VPS. Problem is I was told by Scott there is
an rpm for BackupPC but currently there are no rpm's for CentOS. So this brings me to another
task... create another VPS with a distribution that includes rpm package management for
BackupPC. I found out the hard way that these guys are yet another that uses caps in their
package name and caused me a bit of headache searching for it.
I picked FC-5 for the new VPS as it seems to be the latest to carry BackupPC. To do this I
needed to build the template similar to building the CentOS template above.
yum install vztmpl-fedora-core-5
The rest was pretty much as stated above. Of course I forgot to edit the default.list and had to
later go back and update the cache after already creating the VPS with FC5. So I needed yum
installed on this to fill in the blanks and Scott to the rescue again; I could install this from the
host with:
vzyum 102 install yum
This is it for now. I have yet to configure BackupPC. I will have to blog about it later.

Friday, October 9, 2009

Configuring Static ip address in Linux (ubuntu/debian)

Like most desktops, mine was connecting to network using DHCP. While it is nice and automatic, it is often clumsy as the ip address (of the Desktop) usually changes after every reboot.

If you have only command-line access, here is a simple way to assign a static ip address (in my case it is 192.168.1.3) to your desktop. Make sure you consult your site administrator before doing that, as ip address and gateway ip address may vary.

There are two files that must be configured /etc/network/interfaces and /etc/resolv.conf.

Open /etc/network/interfaces in your favorite editor (mine being nano).? What you will most likely see is this:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet dhcp

The last line is what you need to edit (and add to.) To configure eth0 (your network device) for a static IP address that last line should resemble:

iface eth0 inet static
address 192.168.1.3
netmask 255.255.255.0
gateway 192.168.1.1


Naturally you will need to change the last three lines to reflect your own networking setup.

Once that file has been edited you can restart your network connection with the command:

sudo /etc/init.d/networking restart

Now Configuring DNS

That file is /etc/resolv.conf. This file is in charge of holding your DNS server addresses. Open this file up in your editor. What you need are two lines:

nameserver 208.67.220.220

nameserver 208.67.222.222

Thursday, October 1, 2009

Configuring Apache to handle PSP (python server pages)

Note: You will need Python and mod_python installed in your server. If you have not done that, please follow the python install instructions

Configuring Apache HTTP Server to Handle PSP


After mod_python installation you must make Apache aware of it. For this purpose open APACHE_HOME/conf/httpd.conf for editing(for default Linux location of httpd.conf, consult your system documentation) and append the following lines at the end:
LoadModule python_module modules/mod_python.so
AddHandler mod_python .psp .psp_
PythonHandler mod_python.psp
PythonDebug On

The first line loads mod_python into Apache. The actual path of mod_python.so may vary but the installer should give you the proper path upon finishing. (On Linux most likely it would be libexec/mod_python.so.) The second line informs Apache which files should be handled by PythonHandler, specified on the third line (more about .psp_ usage in the section below). The last directive switches mod_python into debugging mode; when PythonDebug directive is set to On, it will dump traces for the first unhandled exception in the running application. Setting this flag is highly recommended for development purposes, but make sure you turn it off on production environments so as to not expose certain system internals to visitors.

If you would like mod_python pages to be used as default index pages, locate in httpd.conf the following line and change it from
DirectoryIndex index.html index.html.var

to
DirectoryIndex index.html index.psp index.html.var

Now restart Apache. On Windows you usually do that with the Apache Monitor in the system tray or by running net stop apache2 and then net start apache2; on Linux it's as simple as apachectl restart.

Using mod_python


PSP are plain text files that include Python code surrounded with <% and %> tags. Python expressions are enclosed within <%= and %> tags. Directives enable inclusion of other PSP pages; they are wrapped by <%@ and %> tags. The least frequently used tags are <%-- and --%> which, as you might guess, are simply comments that are never rendered to the resulting code.

Let's start with the simple Hello Python example. Under APACHE_HOME/htdocs create a file hello.psp with the following content:
<html>
<%
import sys
%>
Hello! You have <%=len(sys.modules)%> Python modules at your command.
</html>

Now go to http://127.0.0.1/hello.psp with your web browser. You will see how many Python modules are installed on your system. Of course, this information is trivial to us. Mod_python doesn't offer a function equivalent to PHP's phpinfo(), which gives detailed information about the interpreter. In the next step, we'll write one for PSP ourselves.

Under APACHE_HOME/htdocs (usually /var/www), create a file pspinfo.psp with the following content:
<%
req.content_type = 'text/plain'

import mod_python
import pprint
import sys
%>

PYTHON <%=sys.version %>
MOD_PYTHON <%=mod_python.version %>

PATH = <%=pprint.pformat(sys.path)%>

AVAILABLE MODULES
<%=pprint.pformat(sys.modules)%>

Now open http://127.0.0.1/pspinfo.psp and you should see a page as below:

_____________________________________________________________________
PYTHON 2.6.2 (release26-maint, Apr 19 2009, 02:11:59) 
[GCC 4.3.3]
MOD_PYTHON 3.3.1

PATH = ['/usr/lib/python2.6',
'/usr/lib/python2.6/plat-linux2',
'/usr/lib/python2.6/lib-tk',
'/usr/lib/python2.6/lib-old',
'/usr/lib/python2.6/lib-dynload',
'/usr/lib/python2.6/dist-packages',
'/usr/local/lib/python2.6/dist-packages']

AVAILABLE MODULES
{'StringIO': <module 'StringIO' from '/usr/lib/python2.6/StringIO.pyc'>,
'UserDict': <module 'UserDict' from '/usr/lib/python2.6/UserDict.pyc'>,
'__builtin__': <module '__builtin__' (built-in)>,
'__future__': <module '__future__' from '/usr/lib/python2.6/__future__.pyc'>,
'__main__': <module '__main__' (built-in)>,
'_abcoll': <module '_abcoll' from '/usr/lib/python2.6/_abcoll.pyc'>,
'_apache': <module '_apache' (built-in)>,
'_bisect': <module '_bisect' (built-in)>,
'_bsddb': <module '_bsddb' from '/usr/lib/python2.6/lib-dynload/_bsddb.so'>,
'_codecs': <module '_codecs' (built-in)>,
'_collections': <module '_collections' (built-in)>,
'_functools': <module '_functools' (built-in)>,
'_hashlib': <module '_hashlib' from '/usr/lib/python2.6/lib-dynload/_hashlib.so'>,
................
.............
..........
________________________________________________________________________________________

'_locale': <module '_locale' (built-in)>,

perl: warning: Setting locale failed

Error Message:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory

Resolution: Run the commands

#locale-gen en_US.UTF-8 (or whatever locale you want)
#dpkg-reconfigure locales

Installing python and django

python (not the snake :P) has been around for quite sometime. But lately after Google's announcement of App Engine I developed a growing interest in it. One major benefit of python is the code size. Compared to Java, the code size of python is considerable less. More of comparisons later, I will use this post to install python and django in a fresh linux box.

I start with a CentOS box with apache and yum installed.

Now for installing python

#yum install python

Normally mod_python would install, but if it is not installed already, run

#yum install mod_python
In Debian/Ubuntu it would be
#apt-get install libapache2-mod-python


To test python installation, run the command

# python

You should get something like
___________________________________
Python 2.4.3 (#1, Jan 21 2009, 01:10:13)
[GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
____________________________________

Python has been successfully installed. Press Ctrl+D to exit the python shell.

django is not found in repository, so I would install from svn (subversion)
First install subversion

#yum install subversion

Now,

Change directory to /var/www
#cd /var/www

create a directory for django
#mkdir django-src
Change to the django directory
#cd django-src
Download django from svn
#svn co http://code.djangoproject.com/svn/django/trunk/
django source would be downloaded into a sub-folder trunk. Change to the trunk folder
#cd trunk
install django
#python setup.py install

For debian and ubuntu it is a single command
#apt-get install python-django python-mysqldb


Install and start mysql server

#yum install mysql-server
#/etc/init.d/mysqld start


Now to install MySQL-python
(Normally mysql-python installed with yum is an old version, to install the latest follow this)

Installing the necessary tools
#yum install python-devel mysql-devel gcc
Download MySQL-python from http://sourceforge.net/project/showfiles.php?group_id=22307
Extract the compressed file
#tar zxvf <filename of MySQLdb tarball>
Change to the extracted folder
#cd <name of newly created directory by the tar command>
Build and Install from the MySQL-python source
#python setup.py build
#python setup.py install


MySQL-python is installed as .egg file in your site-packages directory.

To run your django application
#python manage.py runserver 127.0.0.1:8000


To additionally install Python Imaging Library
#yum install python-imaging

Saturday, September 26, 2009

Install Virtual Box in your Linux machine

Here is a quick way to install VirtualBox in your linux PC.

The Preparation

Before you begin installing, I would suggest upgrading your PC

Fedora/RHEL/CentOS users can run
yum update -y

For Debian/Ubuntu sudo apt-get upgrade

Next, Install build-essential, Linux headers

For Ubuntu/Debian
sudo apt-get install build-essential linux-headers-generic

Fedora/RHEL/CentOS may need the following packages:
    binutils gcc make patch libgomp glibc-headers glibc-devel kernel-headers kernel-devel

You may install then all with yum
sudo yum install binutils gcc make patch libgomp glibc-headers glibc-devel kernel-headers kernel-devel

Installation

Now install virtualbox from the repository

Fedora/RHEL/CentOS users
yum install virtualbox

Debian/Ubuntu users
sudo apt-get install virtualbox

If all goes well, you would be able to run Virtual Box now.

Common Error Messages

Error! Your kernel source for kernel -server cannot be found at /lib/modules/server/build or /lib/modules/server/source.

Starting VirtualBox kernel module...                                  [fail]

Possible causes: Correct version of linux headers are not installed

Resolution:

Install the correct headers

RHEL/Fedora/CentOS users
yum install linux-headers-$(uname -r)

Debian / Ubuntu  users
sudo apt-get install linux-headers-$(uname -r)

Remove and reinstall virtualbox again

RHEL/Fedora/CentOS users
yum remove virtualbox
yum install virtualbox


Debian / Ubuntu  users
sudo apt-get remove virtualbox
sudo apt-get install virtualbox

Sunday, September 20, 2009

Data Recovery from crashed Hard disk free

TestDisk is OpenSource software and is licensed under the terms of the GNU Public License (GPL).

TestDisk is a powerful free data recovery software! It was primarily designed to help recover lost partitions and/or make non-booting disks bootable again when these symptoms are caused by faulty software, certain types of viruses or human error (such as accidentally deleting a Partition Table). Partition table recovery using TestDisk is really easy.

TestDisk can
  • Fix partition table, recover deleted partition
  • Recover FAT32 boot sector from its backup
  • Rebuild FAT12/FAT16/FAT32 boot sector
  • Fix FAT tables
  • Rebuild NTFS boot sector
  • Recover NTFS boot sector from its backup
  • Fix MFT using MFT mirror
  • Locate ext2/ext3 Backup SuperBlock
  • Undelete files from FAT, NTFS and ext2 filesystem
  • Copy files from deleted FAT, NTFS and ext2/ext3 partitions.

TestDisk has features for both novices and experts. For those who know little or nothing about data recovery techniques, TestDisk can be used to collect detailed information about a non-booting drive which can then be sent to a tech for further analysis. Those more familiar with such procedures should find TestDisk a handy tool in performing onsite recovery.

testdisk

Operating systems


TestDisk can run under
  • DOS (either real or in a Windows 9x DOS-box),
  • Windows (NT4, 2000, XP, 2003, Vista),
  • Linux,
  • FreeBSD, NetBSD, OpenBSD,
  • SunOS and
  • MacOS

Source files and precompiled binary executables are available for DOS, Win32, MacOSX and Linux from the download page


Filesystems


TestDisk can find lost partitions for all of these file systems:
  • BeFS ( BeOS )
  • BSD disklabel ( FreeBSD/OpenBSD/NetBSD )
  • CramFS, Compressed File System
  • DOS/Windows FAT12, FAT16 and FAT32
  • Windows exFAT
  • HFS, HFS+ and HFSX, Hierarchical File System
  • JFS, IBM's Journaled File System
  • Linux ext2 and ext3
  • Linux LUKS encrypted partition
  • Linux RAID md 0.9/1.0/1.1/1.2

    • RAID 1: mirroring
    • RAID 4: striped array with parity device
    • RAID 5: striped array with distributed parity information
    • RAID 6: striped array with distributed dual redundancy information

  • Linux Swap (versions 1 and 2)
  • LVM and LVM2, Linux Logical Volume Manager
  • Mac partition map
  • Novell Storage Services NSS
  • NTFS ( Windows NT/2000/XP/2003/Vista/2008 )
  • ReiserFS 3.5, 3.6 and 4
  • Sun Solaris i386 disklabel
  • Unix File System UFS and UFS2 (Sun/BSD/...)
  • XFS, SGI's Journaled File System


Documentation


How to get TestDisk
  • Download - Binary executables and source files are available for DOS, Win32, MacOSX and Linux.

Accessing WebDAV Filespace from Linux

First, you must install the WebDAV Linux file system driver on your Linux computer. It is recommended to use a fairly new version of davfs2 (e.g., 1.1.4 or later). Early versions have severe security problems.
Download and Installation
First check whether your Linux distribution comes with a precompiled version of davfs2. If it does, simply install the package and your are done with the installation. If your Linux distribution does not contain a davfs2 package, it is not difficult to compile the driver yourself:
  • First get the source code from the WedDAV download site and download the latest version available (at the time of writing this was 1.1.4). Save the tar file at a suitable location, e.g., /tmp.
  • Make sure that you have the neon and neon-devel packages installed.
  • Untar the downloaded tarball at a suitable location (I prefer /usr/local/src), change to the directory (e.g., cd /usr/local/src/davfs2-1.1.4) and run the following commands: "./configure", "make", "make install" (you must become root before running the "make install" command). This will install the driver in the /usr/local/directory tree, e.g., the mount.davfs command will get installed in /usr/local/sbin.

Mounting WebDAV Directories

First you must create the mount point for your WebDAV directories, i.e., an empty directory that will after the mount hold your WebDAV files. I prefer to create a directory "webdav" in the home directory on my Linux computer and create within that directory suitably named subdirectories that will serve as mount points for your webdav directories. Then you can mount your webdav file space by typing something like
su
mount.davfs -ouid=partha,gid=users https://webdav.url.com/files/personal/partha /home/patha/backup
exit

where the first argument, -ouid=partha,gid=users specifies your username and group on your own Linux computer, i.e., replace "partha" with your own username and replace "users" with your group (execute the command "id -n -g" to find your group, if you are not sure). The second argument, https://webdav.url.com/files/personal/partha

in this example, specifies the location of your webdav file space on the WebDAV server. The last argument is the mount point that you created before, i.e., the name of the directory that is going to hold your WebDAV files. The mount.davfs (in CentOS I had to do /sbin/mount.davfs in place of mount.davfs) command is going to ask you for a username and password. These are your SFU username and password - not the username and password that you are using for your Linux computer.

If everything goes well, you now can access your WebDAV files in the directory that you chose as the mount point.

TroubleShooting:

_____________________

Incase you get
/sbin/mount.davfs: Mounting failed.
401 Unauthorized

the webdav server may be Windows and you need to enable Basic Authentication through IIS in the server

______________________________________

______________________________________

Incase you get the error

/sbin/mount.davfs: can’t open fuse device
/sbin/mount.davfs: trying coda kernel file system
/sbin/mount.davfs: no free coda device to mount

You may need to install
fuse fuse-ntfs-3g dkms dkms-fuse

In CentOS box I simply did

yum install fuse fuse-ntfs-3g dkms dkms-fuse


Saturday, September 12, 2009

Installing java in Ubuntu Linux

On Debian/Ubuntu Linux for example all you need to do is make sure that your apt-get is pointed at the right place. In your /etc/apt/sources.list add in the following (and make sure you are okay with adding in stuff that is not in the default environment).

deb http://us.archive.ubuntu.com/ubuntu dapper main restricted
deb http://us.archive.ubuntu.com/ubuntu dapper universe multiverse

After this have apt updates its repository

sudo apt-get update

And finally, just tell it to install java :)

sudo apt-get install sun-java5-jdk

After this the rest of the process will display a dialog that will require you to accept the license agreement. When you do, the rest of the setup will happen on its own.

When you're on the command prompt type

javac -version

or

java -version
_____________
Edit: There is an Update to this post

Thursday, July 2, 2009

Installing Java Runtime Envoriment in Linux - Fedora, RedHat, CentOS distros.

This is actually meant for Fedora, RedHat, CentOS distros.

(1.)log into your root user.

(2.)Go to this link ( http://java.sun.com/j2se/1.5.0/download.jsp ) and download the Linux self-extracting file (jre-1_5_0_07-linux-i586.bin) NOT THE RPM!

(3.)Move jre-1_5_0_07-linux-i586.bin to your /opt/ folder.

(4.)Open the terminal and type "cd /opt/" without the ".

(5.)[root@localhost opt]# sh ./jre-1_5_0_06-linux-i586.bin
(type 'yes')

(6.)[root@localhost opt]# mv -f jre1.5* /opt/jre1.5

(7.)[root@localhost opt]# ln -s /opt/jre1.5/plugin/i386/ns7/libjavaplugin_oji.so /usr/lib/mozilla plugins/libjavaplugin_oji.so

Now we will install the JRE package into Mozilla through 'alternatives'. When Mozilla runs 'java' command, FC5 will always choose the default "GNU Java" for Mozilla to choose Sun's java do the following.

(1)[root@localhost opt]# /usr/sbin/alternatives --install /usr/bin/java java /opt/jre1.5/bin/java 2
(2.)[root@localhost opt]# echo 2 | alternatives --config java
"It will ask to choose which one, Type "Echo 2" then go to number (3.) below"

(3.)[root@localhost opt]# java -version
When you enter this, It will tell you the version of the java that you just installed. IF it doesn't show anything or gives you an error, Delete the jre1.5 folder in /opt/ start over.

This is what it should look like (see below) if you done it right.

[root@localhost opt]# java -version
java version "1.5.0_19"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_19-b02)
Java HotSpot(TM) Client VM (build 1.5.0_19-b02, mixed mode, sharing)