2018. 7. 24.

Amazon Linux AMI에 mysql57 설치

Amazon Linux AMI 에 설치

# wget https://dev.mysql.com/get/mysql57-community-release-el6-11.noarch.rpm
# yum localinstall mysql57-community-release-el6-11.noarch.rpm
# yum remove mysql55 mysql55-common mysql55-libs mysql55-server
# yum install mysql-community-server
# service mysqld restart
# mysql_upgrade -p
Amazon Linux Ami 에 설치환경

Apache 2.4.33

[root@ip-172-31-10-31 html]# httpd -V
Server version: Apache/2.4.33 (Amazon)
Server built:   May 23 2018 19:02:39
Server's Module Magic Number: 20120211:76
Server loaded:  APR 1.5.2, APR-UTIL 1.5.4
Compiled using: APR 1.5.2, APR-UTIL 1.5.4
Architecture:   64-bit
Server MPM:     prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/etc/httpd"
 -D SUEXEC_BIN="/usr/sbin/suexec"
 -D DEFAULT_PIDLOG="/var/run/httpd/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

MYSQL 5.7.22

[root@ip-172-31-10-31 html]# mysql -V
mysql  Ver 14.14 Distrib 5.7.22, for Linux (x86_64) using  EditLine wrapper

PHP 7.0.30

[root@ip-172-31-10-31 html]# php -v
PHP 7.0.30 (cli) (built: May 10 2018 17:39:13) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.30, Copyright (c) 1999-2017, by Zend Technologies

2018. 6. 20.

nginx + php71 + php-fpm 설치하기

version 정보

  • nginx : 1.14.0
  • php : 7.1.18

yum install nginx 를 통해서 설치하였으며,

# yum install nginx

[root@centos html]# nginx -v
nginx version: nginx/1.14.0

php71 은 remi repo를 추가해서 아래와 같이 설치했다.

# yum --enablerep=remi-php71 install php-fpm php-common

[root@centos html]# php -v
PHP 7.1.18 (cli) (built: May 24 2018 07:59:58) ( NTS )
Copyright © 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright © 1998-2018 Zend Technologies

설정파일

/etc/php-fpm.d/www.conf 파일

########### file /etc/php-fpm.d/www.conf
user = nginx
group = nginx
;listen은 nginx 설정과 맞춰줘야 한다.
;listen = 127.0.0.1:9000
listen = /var/run/php-fpm/php-fpm.sock;
listen.owner = nginx
listen.group = nginx

/etc/nginx/conf.d/default.conf 파일

########### file /etc/nginx/conf.d/default.conf

server {
    listen   80;
    server_name  your_server_ip;

    # note that these lines are originally from the "location /" block
    # root 설정이 없으면 404 에러가 날수 있다.
    root   /usr/share/nginx/html; 
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        #fastcgi_pass 는 아래 두개 중 아무거나 사용해도 좋으나 php-fpm.d/www.conf 설정과 맞춰줘야 한다.
        #fastcgi_pass 127.0.0.1:9000;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        #/scripts 이름으로 인해서 오류가 생길 수 있다.
     #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

에러상황 #1

사이트에 접속은 되는데 404 error 또는 파일을 찾을 수 없는 상황

[error] 7469#7469: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.0.114, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:",

해결방법

/etc/nginx/conf.d/default.conf 설정파일에서 아래와 같이 root 폴더 설정을 한다.

server {
 root /usr/share/nginx/html;
 index
}

에러상황 #2

*1 connect() to unix:/var/run/php-fpm/php-fpm.sock failed (13: Permission denied) while connecting to upstream,

php-fpm.sock 의 그룹:사용자 권한 문제
아래와 같은 명령어로 해결할 수 있다.

# chown nginx:nginx /var/run/php-fpm/php-fpm.sock

다른 분들 고생 안했으면 좋겠다.

2018. 6. 15.

아이맥, 맥북, 맥 부팅이 느려질 때 해결방법

아이맥, 맥북, 맥 부팅이 느려질 때 해결방법

2013 late 아이맥을 사용하고 있는데 high sierra로 올리고 난 다음 부터 부팅 시동음이 울릴때까지 2,3분이 걸린다.

그 해결책으로 여러가지를 검색 해 본 결과 아래와 같은 방법을 적용해 보라고 한다.

  1. Shutdown the computer, wait 30 seconds, restart the computer.
  2. Resetting your Mac’s PRAM and NVRAM
  3. Reset the System Management Controller (SMC)
  4. Start the computer in Safe Mode, then restart normally. This is slower than a standard startup.
  5. Repair the disk by booting from the Recovery HD. Immediately after the chime hold down the Command and R keys until the Utility Menu appears. Choose Disk Utility and click on the Continue button. Select the indented (usually, Macintosh HD) volume entry from the side list. Click on the First Aid button in the toolbar. Wait for the Done button to appear. Quit Disk Utility and return to the Utility Menu. Restart the computer from the Apple Menu.
  6. Create a New User Account Open Users & Groups preferences. Click on the lock icon and enter your Admin password when prompted. On the left under Current User click on the Add [+] button under Login Options. Setup a new Admin user account. Upon completion log out of your current account then log into the new account. If your problems cease, then consider switching to the new account and transferring your files to it - Transferring files from one User Account to another.
  7. Download and install theOS X El Capitan 10.11.6 ComboUpdate or 10.12.6 Combo Update or macOS High Sierra 10.13.2 Combo Update as needed.
  8. Reinstall OS X by booting from the Recovery HD using the Command and R keys. When the Utility Menu appears select Reinstall OS X then click on the Continue button.
  9. Erase and Install OS X Restart the computer. Immediately after the chime hold down the CommandandRkeys until the Apple logo appears. When the Utility Menu appears:
  10. 개발자 포럼에서 sudo trimforce diasble을 적용하면 빨라진다는 말이 있다.

본인은 일단 다 했봤는데, 재부팅은 빨라졌다. 첫 구동 할때는 느림. 그래도 재시작이 빨라져서 너무 좋다.

2018. 5. 28.

vuejs | filter | 숫자단위당 쉼표 표기하기

vuejs | filter | 숫자단위당 쉼표 표기하기
화폐 단위를 표기하기 위해서 숫자 단위당 쉼표를 표기하는 방법
Vuejs Filter Currency with decimal places
regex를 이용하는 방법도 있겠지만, 기본 내장함수를 이용하는게 제일 간단한 방법이다. 코드량도 늘어나지 않고.
필터ㅌ에 아래와 같은 코드를 추가 합니다.
filters: {
  currency: value => {
    if (!value) return  ''
    return value.toFixed(0).replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, "$1,")
  }
}
.toFixed(num) : 소수점 아래 표기 자릿수(num)

2018. 5. 21.

axios.post 에 form 데이터 전송

axios form 데이터 저장하기

axios.post 에 form 데이터를 넣는 방법

axios.post 는 그냥 사용하면 form 데이터 형식을 사용할 수 없다. 그래서 new FormData()를 이용해서 form 형식으로 데이터를 보내야 한다.
기존에 데이터에 post 형식으로 데이터를 보내는 방법
axios.post(`http://localhost:8000/api/auth`, {
    headers: {
      'Content-type': 'application/x-www-form-urlencoded',
    },
    id : 'hong',
    pwd: '12345'
  }).then( response => {
    console.log('response', JSON.stringify(response, null, 2))
  }).catch( error => {
    console.log('failed', error)
  })
form 형식으로 데이터를 전송하고 제어하기 위해서 는 아래와 같이 사용을 한다.
let form = new FormData()
form.append('id', this.userID)
form.append('pwd',this.userPass)

axios.post(`http://localhost:8000/api/auth`, form)
  .then( response => {
    console.log('response : ', JSON.stringify(response, null, 2))
  }).catch( error => {
    console.log('failed', error)
  })

2018. 4. 17.

.JSON 설정파일 읽어오기

.JSON 설정파일 읽어오기

.JSON 설정파일 읽어오기

github에 코드를 작성하는데 db의 중요한 설정값을 공개할 수는 없기 때문에 설정파일만 따로 보관해야 한다. 자금이 있어서 private github 서비스를 사용할 수도 없는 입장이고, 개인 개발자의 한계.

GO RESTFUL 서브를 만드려고 하는데 설정 파일을 json으로 저장하고, 이를 필요할 때 불러오는 코드를 작성하려고 한다.

go-mssqldb 패키지를 사용해서 microsoft sql server에 접속을 해서 이를 쏴주는 기능을 사용하려고 한다.

우선 저는 아래와 같은 구조를 갖는 setting.json 을 만드려고 합니다.

setting.json

{
    "database": "sqlserver",
    "user":{
        "id":"admin",
        "pwd":"123456789a!"
    },
    "host":{
        "address": "222.111.111.111",
        "port": 1433
    }
}

이제 이를 golang 에 맞는 type struct를 만듭니다.

type config struct

type MssqlConnect struct {
 Database string `json:"database"`
 User struct {
  ID  string `json:"id"`
  Pwd string `json:"pwd"`
 } `json:"user"`
 Host struct {
  Address string `json:"address"`
  Port    int    `json:"port"`
 } `json:"host"`
}

Load Config

다음은 config.json 파일을 읽어오는 과정입니다.

func LoadConfig() (string, error){
 var config MssqlConfig
 file, err := os.Open("setting.json")
 defer file.Close()
 if err != nil {
  Log.Fatal(err)
 }
 decoder := json.NewDecoder(file)
 err = decoder.Decode(&config)
 if err != nil {
  Log.Fatal(err)
 }
 return config, err
}

func main

아래와 같이 사용하면 됩니다.

func main() {
  config, err := LoadConfig()
  fmt.Println(config.Database) // sqlserver
  fmt.Println(config.User.ID) // admin
}

2018. 1. 24.

Javascript | Null 과 undefined

Javascript | Null 과 undefined

Javascript 를 사용하다보면, 언젠가 한번은 직면하게 될 문제인 NullUndefined입니다. 자바스크립을 처음 접할때는 둘다 같은 같은 null을 의미한다고 생각하고 넘어갔습니다만, 깊게 들어가보면 다르다는 것을 알 수 있습니다.,

Null

  • 비어있거나 존재하지 않는값
  • 할당해야 하는 값
let a = null;
console.log(a); // result : null

객체로 취급됩니다.

Undefined

  • 변수가 선언 되었지만, 아무 값도 할당되지 않은 상태
let b;
console.log(b); // undefined

변수를 underfined로 설정할 수도 있습니다.

let c = underfined;
console.log(c); // undefined
var d = {};
console.log('d',d); // undefined

아무값도 할당되지 않은 상태라 값을 할당할 수 있지만 null은 아닙니다.