Social Icons

Pages

Featured Posts

Wednesday, June 8, 2016

How to install NodeJS on Ubuntu Linux

You can install Node.js on Ubuntu by using the apt package manager by merely running the command


sudo apt-get update
sudo apt-get install nodejs

Issue with this installation is that usually ubuntu repositories have bit older version of Node.js than current stable release.

If you need the latest versions of Node.js you can install it via a tool called nvm (Node.js version manager). To install nvm, C++ compiler needs to be installed. On Ubuntu build-essential and libssl-dev packages will do the work.



sudo apt-get update
sudo apt-get install build-essential libssl-dev
After installing C++ compiler you can proceed to install (or update) nvm by using cURL command or Wget command.


curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash

Install script will be downloaded and installed to ~/.nvm folder. If you like to install the nvm into a custom folder, say to /opt/nvm. Then modify the above command as to
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | NVM_DIR="/opt/nvm" bash
But if you use any custom directory for NVM_DIR property, please make sure you have the right privileges to access it. Otherwise it will give you a hard time. Personally I advice you to download it to the default location.

To use nvm functions you have to log out and log in. Or else you can sourceyour current session in order to let it know about the changes.
source ~/.profile

Availability of nvm can be checked by using the version command.
nvm --version

How to use NVM

You can check what are the available versions of NodeJS to download.
nvm ls-remote


At this moment latest version available is v6.0.0. To install any version
nvm install version_number

If you need to install multiple versions of node you can view all your versions using
nvm ls
In order set a default version
nvm alias default version_number
nvm use default

Friday, March 20, 2015

Configure CodeIgniter framework


Development Mode


Firstly we will look into configuring the development mode for the system. You can configure it in index.php file under Source Files. By default environment is set as development.
define('ENVIRONMENT', 'development');
When the system is implemented it can be changed into production environment. In production environment error reporting is disabled. Usually in production servers errors are disabled by default. But this configuration is worth to know.
define('ENVIRONMENT', 'production');

Mod rewriting

Mod rewriting is simply about redirecting the user to another file location without user realizing it. Advantage of it is that user would not be requested to remember hideous lengthy URLs. Instead user can use a shorter form which will be redirected to that lengthy URL. User may enter www.abc.com/welcome which really means www.abc.com/index.php/welcome. In mod rewriting, URL is rewritten at server level.
Mod rewriting can be done by defining mod rewriting rules in .htaccess file. These rules can be easily understood and written if you know regular expressions already. First a file should be created and named as .htaccess under Source Files. .htaccess file contains directives for Apache. Any directive in .htaccess file will be applied to the same directory it is saved and any sub directory. Thus these Mod Rewriting rules are written and saved in .htaccess file.
For this article series based on CodeIgniter I use below Mod Rewriting in my .htaccess file. If you wish to understand more you can read this article and many other articles around Internet.
In this code "RewriteBase" refers to the root folder of the project. You should change the RewriteBase according to your root folder name.

RewriteEngine On
RewriteBase /CodeIgniterTest

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
After that open application/config/config.php which is under Source Files. Change
$config['index_page'] = 'index.php';
$config['index_page'] = '';

To make this mod rewriting work, you have to turn on mod_rewrite module in Apache. To check the status of mod_rewrite module either you can follow given phpinfo() link in XAMPP or WAMP server. Otherwise write this simple coding <?php phpinfo(); ?> in a php file, save it in your apache root folder and view it through your web browser. If mod_rewrite module is enabled you will see
Otherwise simply enable it by editing httpd.conf file of Apache server. You just have to remove the "#" in front of the
LoadModule rewrite_module modules/mod_rewrite.so
save the file and restart the server. Your Mod Rewrite rules should be working now.

If you are working in a Linux environment you can simply enable the mod_rewrite module by using the following command

sudo a2enmod rewrite
Then restart the apache server. Your Mod Rewrite rules should be working now.

Set up CodeIgniter Framework Environment

CodeIgniter is one of the most powerful and popular php frameworks. You can view the popularity of php frameworks at phptrends.

What is CodeIgniter

CodeIgniter is an Application Development Framework - a toolkit - for people who build web sites using PHP. Its goal is to enable you to develop projects much faster than you could if you were writing code from scratch, by providing a rich set of libraries for commonly needed tasks, as well as a simple interface and logical structure to access these libraries. CodeIgniter lets you creatively focus on your project by minimizing the amount of code needed for a given task.




Tools I use for CodeIgniter

Install CodeIgniter

  • Firstly download CodeIgniter
  • Extract the downloaded zip file
  •  Copy extracted files into a folder created in htdocs folder of XAMPP or in www folder in case of WAMP
    ie : In my case I copied the files into
    XAMPP_installation_folder/htdocs/CodeIgniterTest/  
There are 3 folders and 2 files in the installation folder. Among them user_guide folder can be removed if you like to save some space as long as the content of that folder is accessible on line. System folder is the core of CodeIgniter. Application folder is the place where the real development is going to be happened.

Create CodeIgniter NetBeans Project

  • Create new project in NetBeans under PHP category and project type PHP Application with Existing Sources and click Next
  • Select CodeIgniter installation folder (folder which the CodeIgniter files are stored) as Sources folder
  • Give a relevant name to the project
  • Select any PHP version and click Finish

After a little bit tweaking and configuring You are Ready to Go!


Wednesday, October 1, 2014

How to install Linux using an USB drive

This is a very common question in many linux related forums and groups. There are different tools available to create a linux live USB.

For whom?

Many users are requesting for dual boot of linux alongside with windows. The tool I will be explaining is the best option for such users. This tool can only be installed on Windows. Nevertheless it supports numerous Linux distributions.

Not for whom?

Please note that this tool does not support ISO files of BSD varients, Windows XP or Mac OSX

Linux Live USB Creator - LiLi

The tool I will be explaining about is Linux Live USB Creator (or cutely LiLi). I have been successfully using this small yet very useful tool for a long time for different Linux distributions by myself. Most important thing about this tool is that it is updated always to suit for latest releases of various linux distributions.
LiLi also provides fascinating features such as persistence.

How to create a bootable USB drive?

Instal LiLi and run it. Interface of LiLi is divided into sub parts according to what they are responsible for.

Step 01

Select Drive
Select Drive
Select USB drive you prefer. If it is performed correctly green light on the right bottom corner is lit.




Step 02 

Chose Linux Source
 Choose the source of linux to be installed. Source could be either
        • ISO image file
        • From Optical Drive
        • Downloadable location

Step 03

Size of Persistence
Define size of persistence space. If you don't need persistence, it is okay to leave it as 0MB.





Step 04

LiLi Options
  1.  Will hide all the files copied into USB drive. If you hope to copy some other files into the  drive later this option can be useful as very large number of files are created on drive.
  2.  Will format in FAT32. It is important when you need to clean up drive or it is formatted in NTFS.
  3.  VirtualBox (Portable Version) software is downloaded into drive and allow Linux version to be run inside a virtual box. If this option is selected you can simply run Linux inside windows using 'Virtualize_This_Key.exe' located in the VirtualBox folder on your USB key.

Step 05 

Create Live Key
Using option button here you can force LiLi to use parameters of a particular linux distribution by selecting it in the drop down menu, if you know what distribution it is. Else you can leave it up to LiLi to decide!
Other Options

Just click lightning icon. Your live linux usb key will be ready in few moments!

Saturday, September 27, 2014

Ubuntu apt-get update error

Recently I had to reinstall Ubuntu. When I was trying to install bind9 (bind9 installing and configuring are further discussed here) on my fresh installation, I came across an error.
It was not a problem with bind9 installation. When I tried sudo apt-get update it comes up with the same error!

W:Failed to fetch http://archive.ubuntu.com/ubuntu/dists/precise/Release.gpg  Unable to connect to archive.ubuntu.com:http:
Same error message was repeated for multiple lines. Special feature of all the error messages was that it was prone to occur from same resource http://archive.ubuntu.com. To be precise, this error is not limited to above mentioned server. By searching google I have found out that many people had come across the same error in different servers.
W: Failed to fetch http://extras.ubuntu.com/ubuntu/dists/precise/Release.gpg  Unable to connect to extras.ubuntu.com:http:
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/precise-security/Release.gpg  Unable to connect to security.ubuntu.com:http: [IP: 91.189.92.190 80]

A solution for apt-get error

This error can be easily corrected by changing the sources list of ubuntu.
/etc/apt/sources.list
Follow the below steps in order
  1. Go to Ubuntu Sources List Generator
  2. Select your country and Ubuntu release
  3. ubuntu sources list generaor
    Select country and ubuntu version

  4. Select required sources. First 12 sources are recommended.
  5. ubuntu sources list generaor
    Select required sources
  6. Hit Generate List Button
  7. Copy generated list

  8. apt-get sources list
    My sources list. Yours can be different.
  9. Backup the old sources list
  10. sudo mv /etc/apt/sources.list /etc/apt/sources.list.old
  11. Create new source list
  12. sudo vi /etc/apt/sources.list
    If you prefer graphical text editor
    sudo gedit /etc/apt/sources.list
  13. Paste newly generated sources list and save
  14. Retry sudo apt-get update or any other apt-get command
Voila! should be working perfectly
 
Blogger Templates