Archive for the ‘Linux’ Category

0235 | ใช้ php บน WSL กับ VSCode

Friday, November 16th, 2018 Posted in Linux, PHP Coding, Programming | No Comments »

1) เปิด wsl ขึ้นมา สั่ง sudo vi /usr/local/bin/windows-php ใส่ข้อมูลตามนี้

# Pass all the arguments to PHP.
output=$(php "$@")
# Perform UNIX->WINDOWS syntax replacements.
output="${output//$'\n'/$'\r'$'\n'}"
output="${output//\/mnt\/c/C:}"
output="${output//\//\\}"
# Echo corrected output.
echo $output

2) สั่ง sudo chmod +x /usr/local/bin/windows-php
3) สร้างไฟล์ php.bat เก็บไว้ซักที่ในฝั่ง windows (สมมติ c:\apps\php.bat) ใส่ข้อมูลตามนี้

@echo off
 
setlocal ENABLEDELAYEDEXPANSION
 
rem Collect the arguments and replace:
rem  '\' with '/'
rem  'c:' with 'mnt/c'
rem  '"' with '\"'
set v_params=%*
set v_params=%v_params:\=/%
set v_params=%v_params:C:=/mnt/c%
set v_params=%v_params%
set v_params=%v_params:"=\"%
 
rem Call the windows-php inside WSL.
rem windows-php is just a script which passes the arguments onto
rem the original php executable and converts its output from UNIX
rem syntax to Windows syntax.
C:\Windows\system32\bash.exe -l -c "windows-php %v_params%"

4) ใน vscode ตั้ง setting ตามนี้

    "php.validate.executablePath": "C:\\apps\\php.bat"

reference: https://github.com/Microsoft/vscode/issues/22391

0234 | named allow recursion query for only specific zone

Thursday, October 18th, 2018 Posted in IP Network, Linux, Misc | No Comments »

first> define dummy ip address (e.g. 192.0.2.1) set it to loopback interface

ip addr add 192.0.2.1/32 dev lo

second> named configuration:

  • define acl for blackhole query to the dummy ip address defined
acl acl_blackhole { 192.0.2.1; };
  • declare view for blackhole dns request
view blackhole {
    match-destinations { acl_blackhole; };
    recursion no;
}
  • declare default view for accepting the query. recursion should be yes for allowing the query
view default {
    recursion yes;
    forward only;
    forwarders { 192.0.2.1; }; # by default forward to blackhole

    zone "example.com." IN {
        type forward;
        forward only;
        #  specify your real recursion dns server here
        forwarders { 1.0.0.1; 1.1.1.1; }; 
    }
}