22 ม.ค. 2563

LINE BOT WITH PHP

แบบ  Reply
<?php
$strAccessToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

$content = file_get_contents('php://input');
$arrJson = json_decode($content, true);

$strUrl = "https://api.line.me/v2/bot/message/reply";

$arrHeader = array();
$arrHeader[] = "Content-Type: application/json";
$arrHeader[] = "Authorization: Bearer {$strAccessToken}";

http_response_code(200);

Time Remain Function PHP

<?php
function remainTime($fromTime=0, $toTime = 0) {
        $returnTime = array('day'=>0,'hour'=>0,'minute'=>0,'second'=>0);
        $seconds = floor($toTime - $fromTime);
         
        if($seconds < 0){
            return $returnTime;
        }
         

8 ม.ค. 2563

rc.local on Ubuntu 18.04

Create file
vi /etc/systemd/system/rc-local.service


Add
[Unit]
Description=Start up script
ConditionPathExists=/etc/rc.local

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99

[Install]
WantedBy=multi-user.target

 Create file /etc/rc.local with
#!/bin/bash

touch /root/OK

exit 0

Make it executable with
 chmod 755 /etc/rc.local

Reload systemd
 systemctl daemon-reload

 Enable the service
 systemctl enable sok-startup.service

7 ม.ค. 2563

Setting up Flask and Apache on Ubuntu 18.04 Server

Setup Python3 Environment

First, update apt-get.
$ sudo apt-get update
 
Python3 installed.
$ sudo apt-get install python3-pip
 
Get virtualenv.
$ pip3 install virtualenv
 
Create the project folder.
$ mkdir flaskproject
 
Set up the virtual environment.
$ cd flaskproject
$ virtualenv venv
 
Activate the environment (use deactivate to exit the environment).
$ . venv/bin/activate

Fix Bug Phpmyadmin Warning in ./libraries/sql.lib.php#601

#vi /usr/share/phpmyadmin/libraries/sql.lib.php

 chang line

|| (count($analyzed_sql_results[‘select_expr’] == 1)
 
to
 
|| (count($analyzed_sql_results[‘select_expr’]) == 1  

How To Install LAMP on Ubuntu 18.04 LTS

Install Apache2

apt install apache2 apache2-utils libapache2-mod-php


Install MySQL

apt install mysql-server


Install PHP

apt install php-fpm php-mysql

Install PHPMYADMIN

apt install phpmyadmin

Error #1698 - Access denied for user 'root'@'localhost'
$ sudo mysql -u root -p
$ ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new-password';
$ sudo service mysql restart

Ubuntu server 18.04 config static IP with netplan

แก้ไขแฟ้ม
/etc/netplan/01-netcfg.yaml


network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: yes
    enp0s8:
      dhcp4: no
      addresses: [ 172.0.0.253/22 ]
      gateway4: 172.0.0.1
      nameservers:
          addresses: [8.8.8.8,8.8.4.4]
 
หลังจากแก้ไขค่าเสร็จแล้ว สั่งให้ network ทำงานใหม่ ใช้คำสั่ง 
sudo netplan apply 

5 ม.ค. 2563

server responded Algorithm negotiation failed On Ubuntu 16.04

 Enter the next message in the final line.
 
# Ciphers
Ciphers aes128-cbc,aes192-cbc,aes256-cbc,blowfish-cbc,arcfour
KexAlgorithms diffie-hellman-group1-sha1
 
After that restart service
service sshd restart