Tuesday, April 19, 2016

Deploying Django Project

Last couple of days, I am concentrating on python and giving some time in python related research. Initially, I found it really good for scripting, and later I noticed that it is really powerful language, can be used for desktop to web applications, from small testing applications to a big project.

Django is a framework developed in python and the web development using this framework makes the task simple, clear separation between view and controller. The view templates even can not insert custom codes, that is great, which separates coding from view(coding makes mess in html code)

So, creating a sample Django application and running through command is very easy which can be used for development purpose. And good thing is that, the changed code is reflected when browser is reloaded, that means we do not need to recompile the code. But what if I want to deploy to a dedicated server (I mean Apache2) ? It is not straight forward. Although there are many different possible configurations, I will focus on the basic configuration that make the website running.  Later we can extend it with more and more.

So, let us begin it.

1) Virtualenv

There might be other methods also, I will explain the methods which needs creation of virtualenv. So, first of all, we need python-pip which can be installed with

sudo apt-get install pip
sudo pip install virtualenv

I normally used Eclipse IDE and for a django project I have instally PyDev plugin which makes the task easier. With eclipse I create a Django project and after you have created it , you can directly test it(Thanks Eclipse, it creates everything for you).

Now we install virtualenv inside the directory so that we can deploy the whole directory to new server without worrying the server.

So, we run the following command from inside the project folder:

virtualenv ENV


activate it

source ENV/bin/activate

2) Install Django

We can now install django module using

pip install django

So, the basic project is ready to deploy.

3) Server Preparation

a) Module wsgi

My assumption is that we already installed apache2 . That is not enough, we need to install libapache2-mod-wsgi module also.

sudo apt-get install libapache2-mod-wsgi-py3
* py3 here means python 3
Now we provide the access definition for wsgi.py file in the project.

b) apache2.conf
We write the following line in /etc/apache2/apache2.conf

<Directory /Backup/workspace/java/misc/DjangoProject>
        <Files wsgi.py>
                Require all granted

c) Define site

Now, finally,  we define and enable site in /etc/apache2/sites-available. We create a file 0001-python.conf (for e.g.) with the following contents:

WSGIDaemonProcess sampleapp python-path=/Backup/workspace/java/misc/DjangoProject:/Backup/workspace/java/misc/DjangoProject/ENV/lib/python3.4/site-packages
WSGIProcessGroup sampleapp
WSGIScriptAlias /sampleapp /Backup/workspace/java/misc/DjangoProject/DjangoProject/wsgi.py

And enable this site :

sudo a2ensite 0001-python.conf

sudo apt-get apache2 restart

Now, check your Django application running with the following URL:


Enjoy , you have successfully deploy your first Django application.



Tuesday, April 12, 2016

Apache2 Server Subdomains

Apache2 Server configuration for multiple web applications is confusing for beginners. Since I have just started configuring apache server in my Ubuntu 14.04 system, I am going to share my experiences while installing and configuring Apache Server.

Basic Commands

Here are the basic commands need to learn:

1) Installation :
       sudo apt-get install apache2
2) Reload:
       sudo service apache2 reload
3) Restart:
       sudo service apache2 restart
4) Enable website:
       sudo a2ensite [WEBSITE_NAME]
5) Disable website:
       sudo a2dissite [WEBSITE_NAME]

Problem Scenario

So, the problem scenario is I have to install multiple web applications in the same host but with different URLs. And the web applications can be placed anywhere in the server. And I also discuss about defining sub-domains. 

For example, I have three web projects located in /home/frietec/www/redmine, /home/frietec/www/owncloud, /home/frietec/www/ldap and I want to access these projects with redmine.frietec.com, cloud.frietec.com, ldap.frietec.com.


The solution for this is not so difficult. We need to configure virtual host.  First of all, we have to define the virtual hosts in config file as below:

    DocumentRoot /home/kris/public_html
    ServerName myproject.localhost

    # Other directives here

    DocumentRoot /home/kris/public_html/myproject
    ServerName myotherproject.localhost
    # Other directives here

In this example, it is important that the defined sub-domains should point to the same local machine. So, we either place this information to a DNS server to publicly access. To test in local network, we modify the file /etc/hosts with the subdomains point to the same IP. This way removed the burgeon of remembering the ip-address of the system.

File: /etc/hosts      localhost      kpsharma   myproject.localhost   myotherproject.localhost 

Note: if we use IP address instead of domain-name, then it uses the topmost virtual host. In this case, the project "myproject.localhost" is called.

Friday, April 8, 2016

General Purpose IDEs

Update: Recently, I got to notice that Microsoft has recently released their own light weight IDE called Visual Studio Code(VSCode). After a couple of hours research and testing, I found this IDE really fast, light and with great intelliscent support. I was really impressed by Visual Studio IDE which is really good IDE when I was using Windows. The installer is less than 50 MB and can be installed in Linux/ Windows/ OSX. So, we should not use Windows or specific operating system to use it. Its really great feature. The code auto-complete is really really cool and great, which out-wins Atom, and we can install hundreds of extensions according to our requirements. I already tested python, html, javascript, css and VSCode works exceptionally. 

The only downside, not really downside, is the compilation and execution. Although we can define it in tasks, but somehow not-used-to for normal users. But if just look at the file tasks.json, you will understand everything and you can make your own compiler and runner, really great if you need your own compiler or executer or any custom task.

IDE stands for Integrated Development Environment which supports development of software application. IDE actually makes the task of software development faster and easier for a programmer. Thats why IDEs are so popular. There are several IDEs available, and depending upon our needs , we choose one which is better for specific requirement.

In this article, I present some overview on the currently popular IDEs and will provide my experience on there IDES. First I will talk about my requirement, and then discuss about my research work carried out to get the better one for my requirement. May be you guys also have the similar problem, then this article will help you to some extent.

First, lets talk about my background. I basically develop software using java programming language. Previously, I used Netbeans, but later, because of serveral plugins available in eclipse, I chose Eclipse as my primary IDE. However, both the IDEs are very very popular, and ranked on the top. Eclipse is, with no doubt, the best IDE we can get which is open source. I have heard of IntellisJ IDE for Java, I guess, the current Android IDE(i.e. Android Studio) is using this IDE. But I am not so interested on this, firstly because it is not free, secondly, I found it a bit odd for Eclipse users. Netbeans is good , but there are not a lot of plugins available. 

By the way, this article is not talking about Eclipse, this is very good IDE and very popular. No need to write more about this because everybody know about it. My concern is if I wanted to write short programs/scripts or small website, then opening eclipse(everybody know that eclipse is bloated IDE) which needs a lot of resources to load, make the development task slower.Creating a project, creating files, and many more eclipse generated files make it confusing and somehow complicated. For example, I want to write a python program, which is no more than 100 lines, or if I want to create a website with a couple of pages, then opening eclipse , installing plugins, installing java(Eclipse requires that), is a very lengthy process. For Python project, I installed a Python Eclipse plugin (PyDev) where I could devlep python projects, but I could not feel comfortable with it. I wanted better support (like auto code complete, documentation). Since eclipse makes confusing by creating many other supplementry files, which makes the deployment processes complicated. However, Eclipse is best IDE for Java and Java related frameworks. 

So, I started doing some research work regarding which IDE best meets my requirement: fast, easy, light IDE, which helps to create normal everyday task (like creating small scripts(PHP or Python) , creating a couple of web pages in html, Javascript, css or any other programming languages. I have installed several IDEs and tested if it fits for my requirements. 

My another requirement is support of Linux and Windows operating systems. I basically use bothe operating systems, and IDE should work both systems, you know what I mean, IDE should be platform independent. 

My third requirement is it should be opensource, you know why opensource, we do not need to pay any bucks for these IDEs. And we can have chance to support the product if we have interest, but that is not my concern.  Here I have listed a bunch of IDEs I have been familiar with and I will tell you why I did not choose that IDE. 

1) Notepad ++

It is very nice IDE, but not full support for specific programming language, For example, if you develope a python script, it would not support code auto-completion. But Notepad++ is a general purpose text editor, which has capability of sytay highlighting for several progrmaming languages. There are plugins alos, but I found it not so interesting. Another disadvantage is we can not directly install Notepad++ in linux systems.

2) Vim

Vim is also good, support syntax highlighing for several programing languages, but not enough to do some advanced tasks.

3) Blue Fish

This is good IDE, I basically did not like the menu structure. They are not properly managed. And code highlighting was not good(for me).

4) Bracket

This is very nice IDE, I have tested it and worked like a charm. Support almost everything, and simple concise IDE and everything properly positioned. We could see live pages so that we do not need to run same page again and again. This is a nice feature. Many programmers recommended this for website development, and it is really good.

5) Sublime Text

I have tested this also, but it has the same impression like Blue Fish, menus are not proper, or unwanted, or not normally needed(sometimes confusing also) . I can not tell more about this, because I have not fully tested it.

6) Atom

Finally, I have stucked with this IDE. This IDE is really nice where we can install packages with our requirements. For this IDE, everything is package, that is good for me, because I can removed unwanted packages to make the IDE faster. Some users say this IDE is slow, but I have not noticed it. Actually, it is not noticed for small applications which this article is talking about. Code completion is perfect, syntax highlighting super, and files management is so simple, we do not need any extra files, just a folder is enough. And menus are so proper and concise, I really liked this IDE. The best part is there are thousands of packages available which we can install for our specific requirements.

Here is my scenerio:

1) I want to develop a simple website: For this requirement, I need HTML, Javascript, CSS. And there should be some mechanism to view the output(better if it is live like Brackets). Yes it has everyting. To view live, we instll a package called browser-plus which previews a page, the page could be made live. And if we need, we can debug also. It has CSS and Javascript auto-completion and code highlighting.  So, for web pages, it is not the problem, everything is fine.

package: autoclose-html

2)  I want to write a script(Python) and run it: This is challenging, but it is not that difficult. We just need to install atom-runner which runs  the script.

Package for python: language-python

Python should be installed before you install the packages.

And there are several packages which you can search and install according to your requirement.

You can see how many times the packages are already downloaded which can give you a hint how popular (stable) is the package.

There are some interesting packages which help program development:

>> minimap
>> pigments
>> autocomplete-plus
>> autocomplete-xml
>> autocomplete-paths
>> terminal-plus
>> autosave
>> highlight-selected

Wednesday, February 3, 2016

After Ubuntu Installation

Today, I freshly installed Ubuntu 15.10 which is the latest operating system available. Before this Ubuntu, I used 14.04 LTS, and unfortunately ,  it had problems while I tried to upgrade to newer "unstable" versions. Just finished installation, so far so good :)

This version used the linux kernel 4.2.0-27-generic, which is a major upgrade from previous versions. 

Here are some steps which I generally carry out after Ubuntu Installation(may be it will help you out also)

1)  Packages Update

Update(important) and upgrade(optional) packages.

2)  Fix VI bug

Fix Vi Problem, simply install the package vim.

    sudo apt-get install vim

3)  Extractor

Install 7zip, the built in extractor is not sufficient, so I install 7zip also.

       sudo apt-get install p7zip-full
      sudo apt-get install p7zip-rar

4) Browser

 Install chromium-browser 
    It is not required if you are okay with Mozilla browser, which comes with Ubuntu. But I use    google account, and android devices which make chromium-browser feel comfortable.

sudo apt-get install chromium-browser

Or you can directly go to google chrome page, and download stable debian installer for ubuntu. But I can not wait to test the new feature, so prefer unstable chromium-browser.

5)  Package Manager

Synaptic package manager

 There already comes Ubuntu software center which is quite enough to install and remove application, but I prefer to install synaptic package manager also, from where we can better manage packages.

sudo apt-get install synaptic

6) Access other drives

Mount other drives

If there are other drives in your computer, then you need to mount it to get accessed which Ubuntu automatically does. But I prefer to mount the other drives to specific folder, so I can easily access with path. It is not that complicated, I created a folder /Backup and then just changed the file /etc/fstab

sudo vi /etc/fstab

Then add this line.
/dev/sdb1 /Backup  ext4 errors=remont-ro    0     1

Change appropriately according to your configuration. e.g.  file system, mount location etc.

7) Install java

Java is needed everywhere, so it is good idea to install it before we get stuck while installing software which needs java. For developer needs openjdk-8-jdk, otherwise, lightweight openjdk-8-jre suffices.
Or you can install simply openjdk-7-jre.

sudo apt-get install openjdk-8-jdk
sudo apt-get install openjdk-7-jre 

8) Install Eclipse

If you are developer, you, of course, need eclipse to be installed. The eclipse program can be downloaded from eclipse.org. The extracted folder is copied somewhere in safe place (/opt for example).

9) Launcher

The ubuntu system does not come with Launcher, so I created it myself, it is not that hard though.

cd /usr/shar/applications
sudo vi eclipse_mars.desktop

Insert the following:

[Desktop Entry]
Name=Eclipse Mars

9)  Office software

Office software is needed everyday, and Ubuntu comes with pre-installed office software which is enough for normal users. For me, it is not enough, I need compatibility with Microsoft office. But WPS office is compatible with Microsoft office and its free for linux based system.

So, just download debian installer from the official wps site(https://www.wps.com/linux) and it is yours.

10) OpenSSH Server

SSH client will be pre-installed, but in case if you want to make your computer as a ssh server, then it is necessary.  Just type the following command in terminal:

sudo apt-get install openssh-server

11)  Virtualisation

Virtual Box: Although virtual box can be installed from Ubuntu repository, I faced some problems, so I prefer to download debian and install.

12) Cloud storage

Dropbox: Similar to 11, I preferred downloading debian and install it.

13)  Databases

Postgresql :

sudo apt-get install postgresql-9.4

Do not miss out this administration tool, this is really cool:

sudo apt-get install pgadmin

14) Subversion client

sudo apt-add-repository universe
sudo apt-get update
sudo apt-get install rabbitvcs-nautilus
Provide user to access
sudo chown -R krishna:krishna ~/.config/rabbitvcs
Restart nautilus
nautilus -q

15) Repository clean

 Execute the following commands:

   sudo apt-get autoremove sudo apt-get autoclean sudo apt-get clean

16) Disks Management

sudo apt-get install gparted

17) Image and Graphics 

Gimp & Inkscape

sudo apt-get install gimp
sudo apt-get install inkscape

18) Design


sudo apt-get install dia

19) Bootable USB

It is quite necessary to have a working USB creator tool which can create bootable usb. 

multibootusb is there and it works like a charm.
check this out: www.multibootusb.org

20) Resources Utilisation

Like TaskManager in Windows System, Ubuntu has a cool console dipslay programm which displays how resources are being utilised.

sudo apt-get install htop

21) OpenVpn Installation

For OpenVPN connection, ubuntu requires installation of some packages: openvpn, network-manager, network-manager-openvpn-gnome.

All packages can be installed via terminal as:

sudo apt-get install openvpn network-manager-openvpn network-manager-openvpn-gnome

Saturday, January 16, 2016

Cyanogenmod Android

What is Cynogenmod?

It is a kind of mobile operating system and works on the top of well-known Android. Android is very popular operating system and most of the devices today run Android. Android is Unix based operating system and is open source. Due to its availability of source code, the users of android can test different varieties.

Basically, CM is developed after Google, who actually controls the Android development, releases the source code. The new Android version, google adds new features, and then releases them on their nexus devices. But we know there are millions of devices that run by Android, and the google stock android may not be capable of handling all different devices, so CM basically tweaks, adds and makes it better and more easier.

Why Cynagenmod ?

There are some reasons why somebody wants to install CM version of Android. I try to list out some reasons which came in my mind.

1) To get or test latest Android features: 

I own Nexus 4 device, and I used to get each and every updates google made in android from Android 4.2 to 5.1. It is very nice to be among the first to test the current version of Android. That did not last longer until google released Android 6.0 and I did not get the update, Initially, I thought to download and install manually using root, but it is problematic. Anyhow I want to test the latest version of android, I heard alot about the battery improvements in version 6.0. Then I got Cynagenmod website, where I could fulfill my desire of installing the latest Android. I already have installed it in my nexus 4 and its working like a charm. And good news is that they update very frequently, every week.

2)  Low Resource Devices

I own an Android device with very low RAM, space, and weak processor. It has Android 4.0.4
preloaded with a lot of bulky applications included which I could not even remove. A lot of backgrond applications and services which I never use, never need, they just consume memory, and drain battery. That device was running very slow and I even could not use that for any purpose. Luckily, CM has an image for this device, and successfully could flash the image into my device. That also ran without any problem and very fast. At least I can use this device as a camera,a nativator,remote mouse,radio,music player.

3)  Very Nice Wiki

The CM website is very nice and informative. Each device has their own wiki, and the instllation manual and procedure is so clear that even a normal person can do this. I think they have utilised a lot of resources for that to test for every device, I also heard they have colleced a huge amount of money for this project.

4) Easy to Reinstall

Most of the when we install new version of android, there are chances we got stuck somewhere, or even we could get out of it, that mean the device will never be usable. But the story is totally different with Cynagenmod flash. The recovery image basically runs without any problem and very easy to use. Even it was possible to use touch in recovery console. I just copied some installer to the device and everything else done by recoverer. If there are some problems or incompatabilities, they we can easily replace with another installer.

Finally, it was nice experience for me to flash Android device, and install with total new Cyanogenmod and its new features, Initially I thought I could not succeed, it was not that difficult, rather very intersting. I see some bright future for this operating system if it goes this way. I highly recommend at least to test this new mobile operating system.