Upload File Using cPanel API

cPanel is a web hosting control panel which is using for various aspects of website and server administration with a nice graphical interface. cPanel also has well-documented APIs to manage all kinds cPanel activities through API. Here I have shared a code snipped to uploading files using cPanel API. (Fileman::upload_files)

Parsing XML With Multiple Namespaces Using PHP

Yesterday, I had a very ugly XML data which had to parse. It has multiple namespaces and namespaces are irrelevant with DOM – I just wasn’t getting the nodeValue from the Element. It was parsing partially not all nodeValues due to namespaces are irrelevant with DOM. Then I applied little tricks onto it through XML children options. And I thought I need to share this code so other developers can save his time to get out this annoying issue.

Remove Default Search Box and Add Custom Box in DataTable

DataTable displaying a default search box while initializing it. So by default DataTable has a search box. But sometimes you might have to remove that default search box and add a custom search box. And place that somewhere in the page. This article will help you to do that.


See the above snippet, If your DataTable initializing it like that, then default search box will display. You might think, I can just use “bFilter: false” option to remove that search box. Yes you can! but the problem is if you do that, then DataTable will disable/turn off the search functionality. But you have to only remove the search box not search functionality.

In this case, you can use "dom: 't'" option. This will keep the default functionality of DataTable and just remove the search box, pagination (just hide it). It will just show the table elements.

Here I have shared a code snippet, you can get the idea to accomplish it.

$(document).ready(function() {
  var users = $('#users').DataTable({
    "dom": "t"

  $('#customSearchBox').keyup(function() {

See the full jsFiddle

Install Elasticsearch in Ubuntu 16.04

Elasticsearch is a distributed, real-time, full-text search engine. Elasticsearch developer by JAVA (based on Lucene). It has an HTTP web interface and schema-free JSON documents. In this article, I will describe how to install and then configure elasticsearch in ubuntu 16.04. Let’s see

Before you install elasticsearch, please ensure java is installed on your machine. If not then install java first before doing anything.

Install Elasticsearch in Ubuntu 16.04
Install Elasticsearch in Ubuntu 16.04

Installing Java 8

 First Add the Java PPA to apt package database.

sudo add-apt-repository -y ppa:webupd8team/java

Then run update commands to update your apt package database.

sudo apt-get update
Then install Java 8 and verify it is installed, run following command.

sudo apt-get -y install oracle-java8-installer
java -version
After successfully install Java, now you can install  Elasticsearch on your machine.

Installing and Configuring Elasticsearch

You can download elasticsearch from their official website elastic.co. It would be always good to download deb (Debian) version for the ubuntu, cause it has everything integrated to successfully run elasticsearch. You can also download it through the command line:

sudo wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.7.2.deb
Then install this as usual ubuntu way with the dpkg command:

sudo dpkg -i elasticsearch-1.7.2.deb

After execution this command your installation will be completed, now you have to configure elasticsearch. By default all configuration files of elasticsearch stored into the /etc/elasticsearch directory. Here you can get two files elasticsearch.yml and logging.yml. To configure the elasticsearch you have to open elasticsearch.yml file in your text editor.

sudo nano /etc/elasticsearch/elasticsearch.yml

Now find the line node.name and cluster.name in this file and uncomment it (remove # before them) and change the value of these two.

Find the line, network.bind_host uncomment it by removing the # character at the beginning of the line, and change the value to so it looks like this:


After all done, elasticsearch will be installed on your computer, now just run this command to start elasticsearch.

sudo service elasticsearch start

For testing elasticsearch output. just type http://localhost:9200/ in your browser and see the possible response.

  "status" : 200,
  "name" : "sohel-rana-pc",
  "cluster_name" : "sohel-rana-elasticsearch",
  "version" : {
    "number" : "1.7.2",
    "build_hash" : "e43676b1385b8125d647f593f7202acbd816e8ec",
    "build_timestamp" : "2015-09-14T09:49:53Z",
    "build_snapshot" : false,
    "lucene_version" : "4.10.4"
  "tagline" : "You Know, for Search"

Internationalization & Localization Application with CakePHP 3

CakePHP has one of the coolest features to make application Internationalization & Localization. It’s really easy to translate your application or website into multiple languages with CakePHP 3.  Let’s see it.

First of all, create a directory Locale inside PROJECT_ROOT/src

Create a subdirectory of each language (which language you want to translate your application) inside PROJECT_ROOT/src/Locale/. Subdirectory name can be anything (ex. english, french, etc), but prefer ISO code of the language (ex. en_US, fr_FR, bn_BN etc). So follow this tutorial and make your subdirectory name en_USfr_FR, and bn_BN

Create default.po file inside all subdirectories (en_USfr_FR, and bn_BN). And copy the following code in the respective file.


msgid "message"
msgstr "Hello World"



msgid "message"
msgstr "Bonjour le monde"



msgid "message"
msgstr "ওহে বিশ্ব"

Here msgid key of which will use inside the template (view files) and msgstr is the values which will gonna translate.

So now you have three different languages (en_USfr_FR, and bn_BN). and one key (message) which can be translated into these three languages.

Now use <?php echo __(‘message’); ?> in your view (any ctp file of your application).

Then open PROJECT_ROOT/config/app.php file and find

 'defaultLocale' => env('APP_DEFAULT_LOCALE', 'fr_FR')

and replace with your language.

But if you want to translate language in runtime then you can use it

use Cake\I18n\I18n;


I hope this article will help you to translate your application in multiple language.

Host Static Website in Google App Engine

This article is for hosting your static website into Google App Engine. This article provides an app.yaml file so you can host your static website into Google App Engine. Before do anything make your website’s folder structure like that (see below image). So put all the static files inside assets folder (css, js, images, fonts) and all HTML files in project’s root directory. Inside assets folder css, js, img, and fonts are sperate folders for holding separate files (ex. css file stylesheets, img for images)

Host Static Website in Google App Engine

Then copy-paste this snipped in your YAML file. And then deploy (gcloud app deploy) your application.

You can also make your project structure your own way, then you have to change YAML content based on your changes. So that means need to change YAML information according to your project’s structure.

Create NGINX Virtual Host with PHP 7.0

Here I have shared a script for creating NGINX virtual host with PHP 7.0. NGINX virtual host with  5.x and 7.0 is very similar but only different is php5-fpm.sock location. To create a NGINX virtual host open the configuration files by running this command.

sudo gedit /etc/nginx/sites-available/default

And then copy-pastes this code snippet and modify it by your configuration (information). Then restart your server. And you are ready to go.

See it for creating virtual host with PHP 5.x

CakePHP 3 – DebugKit Toolbar Not Visible

Are you looking for the solution of DebugKit Toolbar not visible in CakePHP 3? These small tips will help you do that. Ensure you have pdo-sqlite installed & enabled on your machine. Cause debugKit by default uses a sqlite db. If not then follow this instruction.

At first install pdo-sqlite in your machine.

sudo apt-get install php7.0-sqlite

Then restart your server (apache server)

sudo service apache2 restart

Now that will help you to visible the DebugKit Toolbar


Change an Array Value if Duplicate

I have an array which holds the multiple same values in same categories. And I want to If the data is duplicate and the category is ‘Sales’ I want 1 of them to change to ‘Service’ and vice versa.

From above snippet, you can see ‘Lane Assist’ is duplicate in ‘Sales‘ category and ‘Bandenafdichtset’ is duplicate in ‘Service‘ category and I changed them as vice versa.