Installing PHP7 mcrypt on Debian

I’ve run into this problem a few times when setting up development stacks for Laravel, OpenCart and some other frameworks – they require the mCrypt PHP extension, but it is not included in Debian 8.

After a few failed attempts and some Googling, this seems to work for me:

apt-get update
apt-get install mcrypt php7.0-mcrypt
apt-get upgrade
service apache2 restart

Of course, you need to be the root user to do this.