Wednesday, September 12, 2018

Git and undo last commit

Updating a remote git repository would mean all other users having a same source code. Sometimes, a local commit may be done and its found that there are changes that should not be push to the remote. The solution, remove not needed files then move to the previous commit on the local machine.

The command is
$ git reset --hard HEAD~1

Unstage any other files with the command
$ git reset


Wednesday, September 5, 2018

Howto install mcrypt for PHP 7.2

PHP extensions have always utilised reuse of applications to provide extra functionality to developers. One such is the use of mycrypt. As of PHP 7.1, the mcrypt is deprecated and totally removed in PHP 7.2. Unfortunately for those with application that rely on mcrypt, this means the end of the road. In my case, development of a Laravel application had dependencies on mcrypt when doing an update with the command;

$ composer update

The mcrypt is a replacement of Unix/Linux crypt( ) that encrypt files. The PHP extension is php-mcrypt, and this is used to interface between PHP application and the mcrypt utility.

However, there is a solution that use mcrypt found in the PHP Extension Community Library (PECL). In this example, its tested on

CentOS 7.5 
Apache 2.4.6 (CentOS)
PHP 7.2.5 (sp.repo.webtatic.com)

Step 1. Install mcrypt utility.

$ pecl search mcrypt
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
Retrieving data...0%
.Matched packages, channel pecl.php.net:
=======================================
Package       Stable/(Latest)  Local
mcrypt        1.0.1 (snapshot)       Bindings for the libmcrypt library
mcrypt_filter 0.1.0 (beta)           Applies mcrypt symmetric encryption using stream filters



Install mcrypt and its development library then update the pecl.

$ sudo pecl channel-update pecl.php.net
$ sudo yum install libmcrypt
$ sudo yum install libmcrypt-devel


Step 2. Install php-devel (or php72w-devel if you use webtatic repo)

$ sudo yum install php72w-devel


Step 3. Install mcrypt extension

Either specify specifically a channel or use default
$ sudo /usr/bin/pecl install channel://pecl.php.net/mcrypt-1.0.1
or
$ sudo /usr/bin/pecl install mcrypt-1.0.1

Create the file /etc/php.d/mcrypt.ini with the contents
; Enable mcrypt extension module from pecl
extension=mcrypt.so


Restart Web server.

Note: If for some strange reason php still doesn't detect mcrypt extension, I would give a reboot.

Done.

Blog Archive