PHP: How to Install Zend Framework v1 (zf1)

You can install Zend Framework v2 as follows:

composer require zendframework/zendframework

However Zend Framework v1 has already been obsolete, therefore when you want to install it manually, you need to download the library from GitHub, and copy (move) to your application directory.

続きを読む

Drupal 8: How to Translate Your Custom Block Fields

If you want to create a module that provides your custom block(s) in Drupal 8, for instance, you can only write two source codes such as my_custom_block.info.yml and MyCustomBlock.php. However how can you make custom configuration fields on your custom block translatable? The answer is to add one additional file my_custom_block.yml as a schema file.

続きを読む

AWS EC2: Use NPT inside VPC

AWS announced to provide their own internal NTP inside VPC at AWS re:Invent 2017. Here is how to do it:

CentOS

sudo yum erase ntp*; sudo yum -y install chrony; sudo service chronyd start

Debian/Ubuntu

sudo apt-get remove -y ntp*; sudo apt-get -y install chrony; sudo service chronyd start; apt-get autoremove
続きを読む

SSH: How to Avoid Connection Error

Add an option -o StrictHostKeyChecking=no into a ssh command:

ssh -o StrictHostKeyChecking=no your_username@example.com

OR

export TARGET_HOST='example.com'

if [ -z `ssh-keygen -F ${TARGET_HOST}` ]; then
  ssh-keyscan -H ${TARGET_HOST} >> ~/.ssh/known_hosts
fi

ssh-keygen -R ${TARGET_HOST}
ssh-keyscan -f ~/.ssh/known_hosts ${TARGET_HOST} >>~/.ssh/known_hosts 2>/dev/null
続きを読む

Linux: How to Increase Swap

  1. Create a file for swap
    ======================

Create a file named /swapfile for 4GB size (e.g. Create a file called swapfile under root (/))

$ dd if=/dev/zero of=/swapfile bs=1024K count=4096
  1. Format the swapfile with a mkswap command
    ======================================
$  mkswap /swapfile
続きを読む

Python: How to Make Bluetooth Proximity Checker by Raspberry PI

  1. Specification - What I want to do
    =================================
    I would like to input in-out records at my company automagically by using Raspberry PI and detecting my iPhone's bluetooth signal. That is, I want to make bluetooth proximity checker with my Raspberry PI. The specification is:
  • Detect Bluetooth signal by Raspberry PI
  • When I come into my office, the system records the time to come into the office
  • When I leave from my office, the system records the time to leave out from the office
  • Integrate Google Sheet to record the time

That is only what I want to do. Think about the spending time to input the in/out time manually. We can reduce our precious 12-20 total hours through a year (Assuming 3-5 min per a day and 240 working days through a year in order to input the records). It can be converted to a half or a day.

Then, OK, Let's see how we can make it!

続きを読む

Apache2: How to Enable HTTP/2 on Ubuntu 16.04

HTTP/2 has been supported since Apache 2.4.17. I tried sudo a2enmod http2 on this Ubuntu 16.04 host, however it said ERROR: Module http2 does not exist!. Looks I needed to upgrade Apache2 as follows:

sudo add-apt-repository -y ppa:ondrej/apache2
sudo apt-key update
sudo apt-get update
sudo apt-get --only-upgrade install apache2 -y

Select Y (Note that this will overwrite your current configuration; therefore do backup of apache2.conf if necessary.

続きを読む

AWS EC2: How to Create AMI Image by Bash Shell Script

#!/bin/sh

export DATE_CURRENT=`date +%Y-%m-%d`
export TIME_CURRENT=`date +%Y%m%d%H%M%S`
export PURGE_AFTER_DAYS=30
export PURGE_AFTER=`date -d +${PURGE_AFTER_DAYS}days -u +%Y-%m-%d`
export BACKUP_TAG='backup'
 
# 1-1 Get the list of instances that you want to get backup
INSTANCES=`aws ec2 describe-tags --filters "Name=resource-type,Values=instance" "Name=key,Values=${BACKUP_TAG}" | awk '{print $3}'`

for INSTANCE in ${INSTANCES}; do
 
  BACKUP=`aws ec2 describe-tags --filters "Name=resource-type,Values=instance" "Name=resource-id,Values=${INSTANCE}" "Name=key,Values=${BACKUP_TAG}" | awk '{print $5}'`
 
  # 1-2 Check if the instance is marked as backup or not
  if [ "${BACKUP}" == "true" ]; then
 
    # 1-3 Create a backup
    AMI_ID=`aws ec2 create-image --instance-id ${INSTANCE} --name "${INSTANCE}_${TIME_CURRENT}" --no-reboot`
 
    # 1-4 Create a tag for search for later use
    aws ec2 create-tags --resources ${AMI_ID} --tags Key=PurgeAllow,Value=true Key=PurgeAfter,Value=$PURGE_AFTER
  fi
done
 
# 2-1 Search backups by tag
AMI_PURGE_ALLOWED=`aws ec2 describe-tags --filters "Name=resource-type,Values=image" "Name=key,Values=PurgeAllow" | awk '{print $3}'`
 
for AMI_ID in ${AMI_PURGE_ALLOWED}; do
  PURGE_AFTER_DATE=`aws ec2 describe-tags --filters "Name=resource-type,Values=image" "Name=resource-id,Values=${AMI_ID}" "Name=key,Values=PurgeAfter"  | awk '{print $5}'`
 
  if [ -n ${PURGE_AFTER_DATE} ]; then
    DATE_CURRENT_EPOCH=`date -d ${DATE_CURRENT} +%s`
    PURGE_AFTER_DATE_EPOCH=`date -d ${PURGE_AFTER_DATE} +%s`
 
    if [[ ${PURGE_AFTER_DATE_EPOCH} < ${DATE_CURRENT_EPOCH} ]]; then
      # 2-2 Delete backup if it is marked as backup
      aws ec2 deregister-image --image-id ${AMI_ID}
       
      SNAPSHOT_ID=`aws ec2 describe-images --image-ids ${AMI_ID} | grep EBS | awk '{print $4}'`
      aws ec2 delete-snapshot --snapshot-id ${SNAPSHOT_ID}
    fi
  fi
done
続きを読む