Everytime when I try to install php using this command, it shows me "E: Package 'php5-mcrypt' has no installation candidate".
Here is the command below what I used for installing php-
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
I'm going to guess that you are using an old version of Ubuntu that is no longer supported or you are following a tutorial that is outdated. Php and by extension php-mcrypt are now at version 7.
sudo apt-get install ... php7.0-mcrypt