Wednesday, April 17, 2019

[Ubuntu] วิธีการเพิ่มหรือแก้ไขผู้ใช้งานบน Ubuntu
[Ubuntu] How to Add and Modify User on Ubuntu

คำสั่งสำหรับเพิ่ม account ผู้ใช้งานใหม่
adduser <username>
คำสั่งสำหรับเพิ่มผู้ใช้งานของคุณเข้ากลุ่ม sudo เพื่ออนุญาตให้ผู้ใช้งานคนนั้นรันคำสั่งด้วย administrative privileges ได้ โดยใส่ sudo นำหน้า
usermod -aG sudo <username>
คำสั่งสำหรับสลับเป็นผู้ใช้งานอื่นชั่วคราว ในขณะที่ผู้ใช้งานเป็น root
su - <username>
คำสั่งสำหรับเปลี่ยนรหัสผ่านผู้ใช้งานของคุณ
passwd <username>
คำสั่งสำหรับตรวจสอบผู้ใช้งานปัจจุบัน
whoami

Thursday, April 11, 2019

[Blogger] การทำ Code Snippet สำหรับ Blogger ที่เป็น HTTP
[Blogger] How to Make Code Snippet for Blogger (HTTP Version)

  1. เข้าไปที่ Theme 
  2. กดปุ่ม Edit HTML ภายใต้ Live on Blog
  3. Copy script ด้านล่างไปใส่ไว้ในส่วนของ head ของ theme
  4. <link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>
    <link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>
    
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js' type='text/javascript'/>
    <script language='javascript'>
        SyntaxHighlighter.config.bloggerMode = true;
        SyntaxHighlighter.config.clipboardSwf = 'http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf';
        SyntaxHighlighter.all();
    </script>
    
  5. กดปุ่ม Save theme
  6. ใส่ code ตามด้านล่างในส่วนของ HTML ของ Post
  7. <pre class="brush: html">
        <link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>
        <link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>
    </pre>
    
หมายเหตุ: เราไม่จำเป็นต้องใส่ brush ทุกอันในข้อ 3 สามารถเลือกเฉพาะอันที่ใช้เท่านั้นได้ สำหรับ brush เพิ่มเติม สามารถดูได้จาก http://alexgorbatchev.com/SyntaxHighlighter/manual/brushes/

Thursday, April 4, 2019

[Laravel - Exception] วิธีการแก้ไข exception หลังจากพลาดรันคำสั่ง php artisan config:cache
[Laravel - Exception] How to Fix Exception after Running php artisan config:cache Command

คำอธิบายของคำสั่ง config:cache คือ สร้าง cache file สำหรับการโหลดค่า config ที่เร็วขึ้น (คุณสามารถรันคำสั่ง php artisan ใน console เพื่อดูคำอธิบายของแต่ละคำสั่งได้)

อย่างไรก็ตาม ผลกระทบจากการรัน  php artisan config:cache อาจจะประกอบด้วย
  1. Website/APIs ของคุณจะตอบกลับด้วย error code 500 Internal Server Error เสมอ โดยไม่มี log ใดๆใน laravel.log
  2. ทุกคำสั่งที่รันด้วย php artisan จะ throw exception ตามภาพด้านล่าง
  3. ทุกคำสั่งที่รันด้วย composer จะรันได้ตามปกติ

วิธีแก้ไข exception นี้ คือ การลบ cache file ที่ถูกสร้างขึ้นมา ซึ่งสำหรับ Laravel 5.6 cache file ดังกล่าวจะอยู่ที่ bootstrap/cache/config.php

Sunday, March 31, 2019

[AWS] การติดตั้ง ELK อย่างง่ายบน AWS
[AWS] How to Install ELK on AWS

ELK stack เป็น platform สำหรับการจัดการ log ซึ่งประกอบไปด้วย 3 ส่วน คือ
  1. Elasticsearch (deep search and data analytics)
  2. Logstash (centralized logging and parsing)
  3. Kibana (powerful data visualizations)

การติดตั้งเริ่มต้นโดยเข้าไปที่ ELK Certified by Bitnami แล้วทำการ subscribe และทำตามขั้นตอนไปจนจบ ก็จะได้ Instance ที่มี ELK stack มาใช้งาน

Friday, March 29, 2019

[Docker] การติดตั้ง Docker และ Docker Compose บน Ubuntu
[Docker] How to Install Docker and Docker Compose on Ubuntu

ถ้าหากเครื่อง server ยังไม่ได้ติดตั้ง curl ให้ติดตั้ง curl ก่อน โดยใช้คำสั่งดังนี้
sudo apt-get install curl
หลังจากนั้นให้ติดตั้ง Docker โดยใช้คำสั่งดังนี้
sudo curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
สำหรับการทดสอบ เมื่อติดตั้ง Docker สำเร็จแล้ว ให้รันคำสั่งดังนี้
docker run hello-world
จะได้ผลลัพธ์ดังรูป


หลังจากนั้นให้ติดตั้ง Docker Compose โดยใช้คำสั่งดังนี้ 
sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
สำหรับการทดสอบ เมื่อติดตั้ง Docker Compose สำเร็จแล้ว ให้รันคำสั่งดังนี้
docker-compose -v
จะได้ผลลัพธ์ดังรูป