2015. 9. 8. 02:53

server variable

$_SERVER['HTTPS’]

$_SERVER['HTTP_HOST’]

// 외에 엄청 많음.


POST / GET

array $_GET  // GET 방식에 의해 넘겨진 form tag data

array $_POST() // POST 방식에 의해 넘겨진 form tag data


internal function

bool empty(value) // value가 비어있는가?

bool isset(value) // value가 null인가?

bool is_array(array) // 배열인가?

bool count(array) // 배열 갯수

bool preg_match(pattern_string, comparing_value) // regular expression

bool in_array(value, array) // array안에 value라는 값이 포함되어있는지 체크

bool ctype_digit(value) // value 가 숫자인지 체크

string impload(separator, array) // 배열을 하나의 문자열로 만들어준다.

array explode($delimiter, $string, [$limit]) // 문자열을 배열로 변경시켜준다.

header(‘Location: file명’); // 페이지를 file명 페이지로 리다이렉션 시켜준다. 

htmlspecialchars() <— 받은 문자 그대로 보여준다. (XSS를 막는 방법 중 하나)
// 그 외에 많겠쬬?


echo, printf , sprintf, var_dump

echo “Hello World!”; // 문자열을 브라우저에 찍는다.

printf(’number=%d string=%s’, 5, ‘abcde’) // 브라우저에 메시지를 찍는다. ehco와 비슷

$value = sprintf(’number=%d string=%s’, 5, ‘abcde’) // 만들어진 문자열을 리턴해준다.

var_dump() // 디버깅을 위하여 변수값 찍어보기


Form Tag

form태그 중 <select> 태그가 multiple 속정이 있을 경우 name속성 끝에 []을 지정하여 배열 선택이 될 수 있다고 명시해주어야 한다.

예) <select name=“language[]” multiple />

html코드에서는 name속성에 []을 포함시켰지만 서버 코드에서는 값을 가져오려고 할 때에는 []을 제외한 name만 사용한다.

예) printf(‘%s’, impload(‘ ’,  $_POST(“language”))) 


File include

readfile(‘~~~.templ.html')

include ‘xxx.php'

include_once ‘xxx.php'

require ‘xxx.php'

require_once ‘xxx.php'


Encryption

$pwd = password_hash(original_password, PASSWORD_DEFAULT);

$ok = password_verify(original_password, $p);


php operator

연산자 $A === $B 는? $A와 $B가 같고, 같은 자료형이면 TRUE

연산자 $A !== $B 는? $A와 $B가 같지 않거나, 같은 자료형이 아니면 TURE


use session

session_start(); // 세션을 사용하기전에 먼저 명령어 실행되어야 한다.

$_SESSION[‘key’] = ‘value’;


php with MySql

$db = new mysqli(‘localhost’, ‘username’, ‘password’, ‘database name’) or die(“Unable to connect”);

$db = mysqli_connect(“localhost”, “username”, “password”, “database name");

$query = sprintf(“insert into table(col1) values (‘%s’)”, mysql_real_escape_string($db, ‘value1’)); // avoid sql injection

mysqli_query($db, $query);

$result - mysqli_query($db, “SELECT * FROM table”);

foreach ($result as $row) {

$value = $row[“col1”];

}

$row = mysqli_fetch_assoc($result);

if ($row) {$col1 = $row[“col1”]; }

mysql_close($db);


Posted by CoolDragon
2015. 9. 5. 04:08
잡설
LinkedIn처럼 상단 메뉴를 고정시키고 마우스를 아래로 스크롤을 내리면 서브메뉴가 사라지고 다시 가장 상단페이지로 올라가면 (Top=0) 가면 다시 서브메뉴가 나타나도록 하는게 어떤건지 해보고자 한다.


index.html


후기

한동안 Front-UI쪽은 거의 안하다보니 많은 명령어도 많이 실제 코드는 별거 없지만 잊어버려 삽질했네순수 javascript로 해보고 싶었는데 그렇게 하려면 작업 시간이 많이 소요될거 같아서 jquery 의 도움을 받아서 해결(?) ㅋㅋ . 그나저나 mouseover와 out 이벤트가 직접 브라우저에서 열면 되는데 jsfiddle에서는 안되네.. 원하는 결과는 얻었지만 이렇게 말고 더 이쁘게 하는거 없나..

Posted by CoolDragon
2015. 9. 2. 23:05

잡설

아무리 정형화되어있는 사이트를 쉽게 뽑아 내기 위해서 워드프레스가 사용된다지만 내가 작업한 사이트보다 더 깔끔한 UI를 제공하는것 같다. 

하기사 돈주고 파는 테마(Theme)도 있으니 어느정도의 퀄리티는 보장하지 않을까 싶다. 조금의 자괴감이 들지만.. 저런 테마를 만들기 위해서 노력한 공과 시간이 있었겠지 라고 스스로를 위로 한다. ㅜㅜ


Search Themes

테마는 기본 테마가 설치 당시 워드프레스 설치 당시 존재하며 그 외에 다른 테마는 Themes에서 찾아보고 맘에 드는 것을 다운로드 받는다. (무료와 유료가 있습니다.)

Add New Theme을 통하여 쉽게 추가를 할 수 있는 것으로 알고 있으나, 본인은 VirtualBox를 사용해서인지 FTP를 통한 적용을 실패하여 수동으로 테마 파일을 다운로드 받고 해당 경로로 복사해주는 작업을 하였다. (본인 서버의 테마의 경로는 /opt/lampp/htdocs/wordpress/wp-content/themes/ 이며, 서버를 어떻게 설치하고 설정하냐에 따라 경로는 달라질 수 있다.)

그 후 Appearance > Themes메뉴를 보면 아래와 같이 기존 테마(Twenty thirteen, Twenty foruteen, Twenty fifteen)와 함께 새로 다운로드 받은 테마(OpenStrap) 같이 나타나는 것을 볼 수 있다. 마우스를 테마위에 hover를 하게되면 해당테마로 적용할 것인지 여부를 묻고 클릭하게되면 선택한 테마로 적용이 된다.


후기

테마 변경은 사실 별로 대단할게 없다. '다운로드 > 테마 디렉토리로 복사 > 선택' 이것이 전부이다. 실제 테마를 선택후 Customizing의 작업이 진짜 작업이지 않을까 싶다.

Posted by CoolDragon
2015. 9. 2. 22:21

잡설

항상 마이크로소프트의 제품군들만 사용해오다 보니 리눅스를 다루는 것은 가슴속 한켠엔 '어려운 것'으로 자리잡고 있었다. 지금이라도 이렇게 시간이 될 때 한가지 한가지 해보고 정리를 해다가 보면 '어려운 것' 에서 '해볼만 한 것'으로 바뀌지 않을까 싶다.


Install FTP

# sudo apt-get install vsftpd


Create User for FTP

$ sudo -i # root 변경

# 예) useradd -d {home directly} -u {user id}

useradd -d /opt/lampp/htdocs/wordpress/wp-content/themes/ -u themes #  FTP접속 시 '/home/cooldragon'가 홈디렉토리

$ passwd themes # 비밀번호 설정

Enter new UNIX password: 

Retype new UNIX password: 

$chmod 777 themes/ # 계정에 대한 쓰기 읽기 권한이 없다면 권한을 부여


FTP Configuration

$ vi /etc/vsftpd.conf

# Allow anonymous FTP? (Disabled by default)

anonymous_enable=NO


# Uncomment this to allow local users to log in.

local_enable=YES


# Uncomment this to enable any form of FTP write command.

write_enable=YES


# Default umask for local users is 077. You may wish to change this to 022,

# if your users expect that (022 is used by most other ftpd's)

local_umask=0

$ service vsftpd restart


Access Test

Now you can drag file and drop it into the directory.


후기

사실 FTP를 설치한 이유가 wordpress에서 Themes을 다운로드 FTP를 통하여 자동 업데이트 되도록 하기 위함이었는데.. virtualbox로 생성한 거라 내부IP와 상관이 있는것인지.. 모르겠지만 계속 실패가 났다. 결국 ftp client로 접속하여 다운로드 받은 파일을 드래그&드랍으로 파일을 붙여 넣었다.

깊이 없는 리눅스 겉핥기와 같은 나의 수준이 문제겠지.... 방법이 뭔가요?

Posted by CoolDragon
2015. 9. 2. 16:44

Insall XAMPP

refer to install XAMPP


Create Database
Open browser >> Put following the URL: http://192.168.xxx.xxx/xampp >> Click phpMyAdmin link as image capture below


Create database >> Put "Database name" on the textbox and select Collation

Create User >> Click "Add User" link

Put new user information >> User name, Host, Password (You can create password by Generate password)

Check privileges for new User

Check Global privilieges

Require SSL >> Click Go if you are done setting up for new user.






Posted by CoolDragon
2015. 9. 2. 01:51

잡설

얼마전에 채용 인터뷰를 보는데 대충 이런 질문이 하나 있었다.

면접관 : "CMS에 대한 경험 있어?"

나 : "CMS가 뭔가?"

면접관 : "Content Management System라고 WordPress같은거.."

나 : "아! 그거 안해봤다. 근데 그거 개발은 아니고 Admin 사이트에서 필요한 거 설정하면 자동으로 사이트를 만들어 주는 것으로 알고 있다."

그리고 여럿 채용공고를 보던 중 CMS와 관련된 제품(?)들이 생각보다 많은 것을 보고 놀랍기 까지 했다. (TYPO3, Magento, Drupal, Joomla)

암튼 이것이 동기부여가 되어  Wordpress는 어떻게 생성 사용하는지 알아보고자 한다.


Insall XAMPP

refer to install XAMPP


Download

Download .tar.gz — 6.2 MB

wget http://wordpress.org/latest.tar.gz

$ sudo tar xvzf latest.tar.gz -C /opt/lampp/htdocs   # unzip and copy into /opt/lampp/htdocs


Configuration

Open browser >> Put following the URL: http://192.168.xxx.xxx/wordprocess (refer to Create database and user for MySQL)

Put information of database that you've created > Submit

If you see the page below, you create 'wp-config.php' manually because your linux account doesn't have any permission.

$ sudo -i   # change root

cd /opt/lampp/htdocs/wordpress/

$ touch wp-config.php

$ sudo vi wp-config.php # and then paste the script

chown nobody:nogroup wp-config.php

chmod -R 777 wp-content # 이 명령어를 실행하지 않으면 theme 및 plugin 다운로드시 권한 문제로 오류가 난다. (더 좋은 대안은 무엇을까?)

$ exit

Put "Information needed"

Test

Login >> http://{IP Address}/wordpress/wp-admin/

After Login >> You can see Dashboard.

Open http://{IP Address}/wordpress/



후기

Wordpress 생성 과정중 'wp-config.php' 파일을 수동으로 생성을 하는 작업이 있는데 리눅스가 익숙치 않은 나는 수동작업 없이 자동으로 처리되게 하려면 무슨 권한 작업을 미리 설정해야 놓아야 하는지 잘 모르겠다. (알고 계신분들은 댓글로 좀 알려주시면 향후에 업데이트 하도록 하겠습니다.)

인스톨까지는 생각보다 쉬운데 이후 사이트 다운 구성을 하려면 사실 더 많은 시간과 노력이 필요하지 않을까 싶다.

Posted by CoolDragon
2015. 8. 31. 20:24

GitLab은  Private한 환경에서 git을 이용하여 개발 소스를 관리할 수 있게 도와준다. (쉽게 말하자면 Private GitHub이랄까...)


2014년 4월인가  GitLab을 수동으로 설치해 봤었는데 엄청 복잡하고 어렵게 어렵게 설치를 했는데

이렇게 간단하게 패키지로 설치 할 수 있는 방법이 있는 줄 몰랐다.

Install a GitLab CE Omnibus package on

 Check if your server meets the hardware requirements. GitLab packages are built for 64bit systems. For 32bit OS, consider alternative installation methods.

1. Install and configure the necessary dependencies

If you install Postfix to send email please select 'Internet Site' during setup. Instead of using Postfix you can also use Sendmail or configure a custom SMTP server. If you wish to use Exim, please configure it as an SMTP server.

On Centos 6 and 7, the commands below will also open HTTP and SSH access in the system firewall.

sudo apt-get install curl openssh-server ca-certificates postfix

2. Add the GitLab package server and install the package

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
sudo apt-get install gitlab-ce
If you are not comfortable installing the repository through a piped script, you can find the entire script here.

Alternatively you can select and download the package manually and install using
dpkg -i gitlab-ce-XXX.deb

3. Configure and start GitLab

sudo gitlab-ctl reconfigure

4. Browse to the hostname and login

Username: root 
Password: 5iveL!fe


설치 후 환경설정 

# host와 port 설정

$ sudo vi /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml

  gitlab:

    host: IP 또는 domain name

    port: 80


# external_url 설정

$ sudo vi /etc/gitlab/gitlab.rb

  external_url 'http://IP 또는 domain name'


# 적용

$ sudo gitlab-ctl reconfigure

$ sudo gitlab-ctl restart


결과

로그인 페이지

로그인 후

Email


GitLab에 SSH Key 생성 및 등록

$ cd ~/.ssh

$ ssh-keygen

cat ~/.ssh/id_rsa.pub  #내용 복사

복사한 내용을 Gitlab 사이트의 SSH Key 페이지를 통하여 등록


Git Project 생성 및 커밋

신규 프로젝트 생성


생성한 프로젝트명으로 git경로를 얻을 수 있으며, 그 이후 git golbal setup 및 create a new repository 작업을 통하여 리모트와 gitlab의 실제 repository를 연결할 수 있다.




Posted by CoolDragon
2015. 8. 31. 01:42

1. install

$ sudo apt-get update

$ sudo apt-get upgrade -y

$ sudo apt-get install golang -y

$ sudo apt-get install git -y


# create project directory

$ mkdir $HOME/go

$ mkdir $HOME/go/bin


2. Setting path

$ echo "export GOROOT=/usr/lib/go" >> /home/vagrant/.bashrc

$ echo "export GOBIN=/usr/bin/go" >> /home/vagrant/.bashrc

$ echo "export GOPATH=$HOME/go" >> /home/vagrant/.bashrc

$ echo "export PATH=$PATH:$GOPATH/bin:$GOROOT/bin" >> /home/vagrant/.bashrc


3. Download library

go get {URL}

$ go get github.com/gorilla/mux

$ go get github.com/gorilla/sessions


4. Sample

keyvalue.go

- http://localhost:8080/mapstore/set/{key}/{value}

- http://localhost:8080/mapstore/get/{key}

Posted by CoolDragon
2015. 8. 31. 01:16

1. Install PostgreSql

$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

$ sudo echo "deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main 9.4" >> pgdg.list

$ sudo cp pgdg.list /etc/apt/sources.list.d/pgdg.list

$ sudo apt-get update

$ sudo apt-get -y install postgresql-9.4 postgresql-client-9.4


2. Set password for Postgresql

$ sudo -u postgres psql postgres

postgres=# \password postgres

Enter new password: 

Enter it again: 

postgres=# \q


3. Allow aceess remote

$ sudo vi /etc/postgresql/9.4/main/pg_hba.conf

...

# IPv4 local connections:

host    all             all             127.0.0.1/32            md5

host    all             all             192.168.1.0/24          md5   # Add 

...

$ sudo vi /etc/postgresql/9.4/main/postgresql.conf

listen_addresses = '*' # replace "*" with "localhost"

port = 5432

$ sudo service postgresql restart


4. Open Port on firewall

$ sudo ufw allow 5432


5. Test

pgAdmin Download








Reference

http://www.unixmen.com/install-postgresql-9-4-phppgadmin-ubuntu-14-10/

http://askubuntu.com/questions/233064/why-am-i-getting-command-deb-not-found


Posted by CoolDragon
2015. 8. 27. 18:02


$ sudo dpkg -i "YourDebPackage.deb"


Posted by CoolDragon