Month: September 2017

  • Top 3 ways to debug your code while programming

    Top 3 ways to debug your code while programming

    If you do programming, you will definitely face problems with your code and stuck somewhere. That situation is pretty frustrating for beginners. Lets know how to deal with these situations and get the answers of the problem.

    1. Debug your code

    • Check for error messages in the trace log. You will most probably get the line number where the problem is, like missing semicolon, or braces are not closed properly. Most probably you will get something useful piece of information to fix the code.
    • Delete the lines and add one by one until the problem started coming.
    • Print the custom logs on log files and do check them.

    By this time at-least you will know where the problem is.

    2. Find solutions Online in Google or StackOverFlow

    • Paste the error code in Google along with the programming language. You will get the answer in top 5 links provided by google.
    • Make Google your friend – If you don’t know how to do a specific thing, you can always search in Google or StackOverFlow like How to do loop in Java or C.

    3. Ask questions in IRC

    If the Google Searches or StackOverFlow doesn’t solve your problem. Ask the problem in Internet Relay Chat ie. in Freenode.
    Make sure you ask right question with some lines of code pasted on Pastebin, so that others can look into that. Be Thankful to people who helped you while fixing the code.

    If you want to know, how to ask questions smartly follow the below mentioned guide.

     This is how you can fix your problems effectively while doing code. Happy Coding!
  • Linux – Increase / Resize the Disk Storage in AWS EC2 EBS without reboot

    Linux – Increase / Resize the Disk Storage in AWS EC2 EBS without reboot

    From 13th Feb 2017, there is no need to reboot the EC2 instance for increasing the EBS disk storage.

    Amazon Web Services has announced –

    Amazon EBS Update — New Elastic Volumes Change Everything

    The good news is, EBS modification process is also applicable for root volumes as well. Let’s learn how to do that.

    How to increase the Linux AWS EC2 EBS storage without rebooting?

    • Login to AWS web console
    • Search for EC2 Service in the Console and click on that.

    AWS EC2 Search

    • Click on the EBS on the left menu and search for the volume you wish to modify.
    • Right click on the EBS Volume and click on Resize > Modify Volume

    ebs_modify_size

    • Click on “Modify” button and it will ask for confirmation.

    • Click on “Yes” Button and it will give the confirmation that volume has been modified or not.

    ebs_modification_succeded

    use lsblk to identify the volume information.

    [surya ~]$ lsblk
    NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    xvda    202:0    0  30G  0 disk
    └─xvda1 202:1    0  30G  0 part /
    xvdf    202:80   0  20G  0 disk /mnt
    └─xvdf1 202:81   0   10G  0 part

    Now you can see that xvdf has been increased to 20 GB

    now use file system specific commands to increase the volume size on the server.

    for Linux ext2, ext3, or ext4 file system use below commands to increase the volume

    # install "cloud-guest-utils" if it is not installed
    surya:~$ sudo apt install cloud-guest-utils
    
    surya:~$ sudo growpart /dev/xvdf 1
    CHANGED: disk=/dev/xvdf partition=1: start=4096 old: size=16773086,end=16777182 new: size=73396190,end=73400286

    Note: growpart command used when we want to increase a partition within disk. If there is no partition within the disk then use below command to resize the disk.

    resize2fs /dev/xvdf

    Now run lsblk command again to confirm

    [surya ~]$ lsblk
    NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    xvda    202:0    0  30G  0 disk
    └─xvda1 202:1    0  30G  0 part /
    xvdf    202:80   0  20G  0 disk /mnt
    └─xvdf1 202:81   0   20G  0 part

    Now run df -h to check the space

    surya:~$  df -h
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/xvda1             70G  951M   69G   2% /
    tmpfs                 1.9G     0  1.9G   0% /dev/shm
    /dev/xvdf             20G   45M  20G   1% /mnt

    This is how you can increase the size of the EBS volume without rebooting the Linux machine.

    For more information please visit AWS Documentation.

  • Linux – How to set default version of PHP in Ubuntu 16.04

    Linux – How to set default version of PHP in Ubuntu 16.04

    It might be possible you have installed multiple version of PHP in you server or system. First you should list all the php version and check which version is set to default. After that set the preferred PHP version.

    How to list number of Php version in the system?

    To list PHP version use sudo update-alternatives --display php

    surya@x:$ sudo update-alternatives --display php
    php - manual mode
      link best version is /usr/bin/php7.1
      link currently points to /usr/bin/php5.5
      link php is /usr/bin/php
      slave php.1.gz is /usr/share/man/man1/php.1.gz
    /usr/bin/php5.5 - priority 55
      slave php.1.gz: /usr/share/man/man1/php5.5.1.gz
    /usr/bin/php5.6 - priority 56
      slave php.1.gz: /usr/share/man/man1/php5.6.1.gz
    /usr/bin/php7.0 - priority 70
      slave php.1.gz: /usr/share/man/man1/php7.0.1.gz
    /usr/bin/php7.1 - priority 71
      slave php.1.gz: /usr/share/man/man1/php7.1.1.gz
    

    How to check current default Php version in server?

    To check current default version use command php -v

    surya@x:$ php -v
    PHP 5.5.38-4+deb.sury.org~xenial+1 (cli) 
    Copyright (c) 1997-2015 The PHP Group
    Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
        with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
    

    How to set default Php version in server?

    To set default version of PHP use sudo update-alternatives --config php

    surya@x:$ sudo update-alternatives --config php
    There are 4 choices for the alternative php (providing /usr/bin/php).
    
      Selection    Path             Priority   Status
    ------------------------------------------------------------
      0            /usr/bin/php7.1   71        auto mode
    * 1            /usr/bin/php5.5   55        manual mode
      2            /usr/bin/php5.6   56        manual mode
      3            /usr/bin/php7.0   70        manual mode
      4            /usr/bin/php7.1   71        manual mode
    
    Press <enter> to keep the current choice[*], or type selection number: 2       
    update-alternatives: using /usr/bin/php5.6 to provide /usr/bin/php (php) in manual mode
    
    
    surya@OMDELPDNEOUBU:/etc/nginx/sites-available$ php -v
    PHP 5.6.31-4+ubuntu16.04.1+deb.sury.org+4 (cli) 
    Copyright (c) 1997-2016 The PHP Group
    Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
        with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
    

    This is how, you can set your preferred version of Php to the system.