Just created a open repository for PHP Snippets on VScode

Tab-expanding snippets of VSCode is a useful feature for rapid coding. You can store common snippets that you use in your projects there, assign it a prefix & import it in your code whenever needed.

To take advantage of public contribution, I just created a small repository on Github that’s containing some starter PHP snippets. You may use it in your projects or add common snippets to it.

Here you can find the repo:


Take care!

Changing Apache’s PHP version in Ubuntu 16.04 (Xenial Xerus)

Maybe you’ve also encountered that php versions’ are not the same on Apache web server & Command line. Because of installing softwares/packages from command line in Linux, usually command line PHP gets updated, without affecting PHP module used by Apache.

Say, My machine in Linux mint which is built on Ubuntu 16.04 (Xenial Xerus) & we are about to change Apache’s php to version PHP7.0.

In such circumstances, you need to make sure of missing PHP module for Apache. To do so, jump into terminal & run:

ls -l /usr/lib/apache2/modules/ | grep libphp

If you couldn’t find sth like ‘libphp7.0.so’, it means you don’t have the required module. So, first install it using:

sudo apt-get install libapache2-mod-php7.0 --fix-missing

after installing the module, if you ls Apache modules directory, this time you’ll see that ‘libphp7.0.so’ is present.

Now that you have the required module, you should disable the existing php module version (e.g. php5.6) used by Apache:

sudo a2dismod php5.6

and enabling desired version:

sudo a2enmod php7.0

So far so good. What we’ve done so far, would suffice for websites & web apps without database(e.g. mysql) dependency. But what if your website uses a mysql database as its data storage? you have to install mysql connection library for PHP7.0. To do so, run following command & you’ll have databases connected to the new PHP interpreter again:

sudo apt-get install php7.0-mysql

Alright, everything is OK. Just one step to embrace php7.0! restart Apache:

sudo service apache2 restart

Well done! you can use phpinfo() to check for php version.

As final note, lets browse directory of PHP7.0 modules. Do you know Where it is? if you browse into /usr/lib/php, you’ll find a some folders named using a date. What are these weird folders? Each of them are representing a particular version of PHP & are called Internal API version:

PHP Version PHP Extension (Internal API version)
PHP 5.6 20131226
PHP 7.0 20151012

If you look into 20151012 folder, you’ll see some files with .so extensions, these are php extensions. Then for installing a php extension that you are not sure about its name, you may type `sudo apt-get install php7.0` & press tab key to see available modules to install. Just, don’t forget to restart Apache server or things won’t take effect until next system restart!

Alright, we’ve done with upgrading php version in Linux Mint(Ubuntu 16.4 – Xenial Xerus) &I hope you’re comfortable with your upgraded machine. Happy coding php7.0!

Bitcoin 51% Attack Cost

For those familiar with Bitcoin, one of the criticisms some illiterate people to Bitcoin make occasionally, is the famous 51% Attack ! Its also known as Majority Attack or Majority Hash Rate Attack.

I don’t want to go through this, because there are plenty of comprehensive resources/articles out there at your fingertips via Googling. I’m just here to share an interesting page, trying to convince people from a different POV.

Here it is from the GoBitcoin.io : Cost of a 51% Attack.

I guess it’d be helpful, specially for numbers-persons. Take a look at eye-watering amount of money one should invest in attacking Bitcoin network, & Guess what happens next? The price will experience a free fall down to $0 !

So the common sense simply says: No worries, It Won’t Happen 🙂