Install phpMyAdmin ubuntu via command line

phpMyAdmin is useful tool to check database content. And I would like to use it on my development server. It’s quite simple and straight forward steps.

You will need root privilege to install this and supposed to be mysql installed and configured already.

  1. First prepare apt-get up to date
    apt-get update && apt-get upgrade
  2. Install phpMyAdmin
    apt-get install phpmyadmin

    When you install and will see and option to choose a web server to choose. If you have apache2 installed, select the option. By default, it’s  blank and looks like chosen but actually need to press space key to select. Then press tab and click OK.

    phpmyadmin install choose apache2
    phpmyadmin install choose apache2

    Another option window is asking if I want to use dbconfig-common. If you already db configured, simply choose “No”.

    phpmyadmin install config

    It will ask password for phpmyadmin user if you choose dbconfig-common as Yes. Put desired password there.

  3. Now you can try access http://yourdomain.com/phpmyadmin

    phpmyadmin installed
    phpmyadmin installed

mysql allow remote access from any host

Granting mysql access from remote is not secure, so it’s not recommendable but sometimes we need to do it. Here’s how to do.

  1. Login to mysql with root and create user with remote connect.
    GRANT ALL PRIVILEGES ON remote_db.* TO 'remote_user'@'%' IDENTIFIED BY 'passwordhere';
    
    FLUSH PRIVILEGES;
  2. We need to allow remote connection from mysql configuration. mysql.cnf or mysqld.cnf files locations are differ but in my case, it is located in /etc/mysql/mysql.conf.d/ folder.
    vi /etc/mysql/mysql.conf.d/mysqld.cnf And comment out  below line.
    #bind-address = 127.0.0.1
    After that mysql restart desired.
    service mysql restart
  3.  Now if you have any firewall or network security, allow the port. In my case, I needed to allow 3306 port in AWS inbound rule.
  4. Try to connect from remote.

    mysql -u {username} -p -h {ip address}

    mysql remote connection
    mysql remote connection

Use HipChat PHP API

Hipchat is good communication platform not just between people but also between machine and apps.

I am using HipChat to monitor deployment in Jenkins. There’s HipChat plugin for Jenkins.

Hipchat Jenkins plugin
Hipchat Jenkins plugin

And I would like to get this deployment result using API.

hipchat log
hipchat log

Here we go.

First we need to install composer if it is not installed on the server.

sudo apt-get update
sudo apt-get install curl php-cli php-mbstring git unzip
cd ~
curl -sS https://getcomposer.org/installer -o composer-setup.php

After get composer setup file, we can verify the installer. go to https://composer.github.io/pubkeys.html and get key.
Run this command after replace key.

php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

You will see the message like “Installer verified”. Then turn this.

sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

Next step is get HipChat PHP API and configure composer accordingly.

git clone https://github.com/vanilla/hipchat-api.git
curl -sS https://getcomposer.org/installer | php
php composer.phar install

When you git clone, the git repository has composer.json file and run curl -sS https://getcomposer.org/installer | php  will down load composer.phar file and all sub folders will be created after run php composer.phar install

Now we need to get API Token.  Login to HipChat and go to Profile > API access menu > create new token.

get hipchat api token
get hipchat api token

Finally, we can make example script.

<?php
// The library lives in the HipChat namespace.
use HipChat\v2\HipChatClient;

// Require composer's autoloader.
require_once 'vendor/autoload.php';
  
// Define the cli options.
$client = new HipChatClient();
$client->setAuth('{your api token put here}');

// Start making calls!
$options['max-results']=5;
$options['start-index']=0;
$message = $client->roomsAPI()->getHistory('{room number goes here}',$options);
print_r($message);

I got this chat history. Yay!

hipchat api result
hipchat api result

I put it on my Raspberry Pi LCD display to monitor quickly.

hipchat on my raspberry pi
hipchat on my raspberry pi