OS : Amazon-Linux


파일질라 설치

https://filezilla-project.org/


1. AWS EC2 Instance에 vsftpd 설치

yum install vsftpd


2. AWS Security Groups 설정

20-21 범위 포트 추가

1024-1048 범위 포트 추가


3. vsftpd.conf 설정

vi /etc/vsftpd/vsftpd.conf


- 익명으로 FTP 접속 금지

anonymous_enable=YES -> anonymous_enable=NO //YES를 NO로 변경


- 사용자의 홈 디렉토리를 제한

chroot_Local_user=YES //(#제거)주석해제


- vsftpd.conf 파일의 마지막부분에

pasv_enable=YES

pasv_min_port=1024

pasv_max_port=1048

pasv_address=IPv4 Public IP


4. FTP 사용자 만들기

cat /etc/vsftpd/user_list 에 없는 사용자를 만들어야 한다.


- 계정생성

useradd test

passwd test


- www 그룹생성

groupadd www

chown -R root:www /var/www/html


- /var/www/html 디렉토리에 대한 권한 부여

usermod -d /var/www/html test //홈 디렉토리 변경

usermod -a -G www test //www 그룹 추가

cd /var/www/html

chmod 775 . //html 디렉토리 775로 권한 부여


5. vsftpd 재시작

service vsftpd restart


6. 파일질라-FTP접속

만들었던 test 계정으로 들어가면 FTP 접속이 된다.


 파일질라-SFTP접속

편집(E) - 설정(S) - SFTP - 키 파일 추가(A) - .ppk파일 추가 - 확인

호스트IPv4 Public IP 사용자명: 계정명 포트: 22 




'개발 > AWS' 카테고리의 다른 글

AWS - 계정 변경 및 Key pair 없이 로그인하기  (0) 2017.04.07

OS : Amazon-Linux


EC2 Instance 생성 후, root 비밀번호는 설정 되어 있지 않음

root계정 로그인 후


1. 계정 생성

adduser test

passwd test


2. ssh key 복사

mkdir /home/test/.ssh

cp /home/ec2-user/.ssh/authorized_keys /home/test/.ssh


3. 소유자, 그룹 소유자 변경

chown -R test:test /home/test/.ssh


4. sshd_config 설정

vi /etc/ssh/sshd_config

.

.

# To disable tunneled clear text passwords, change to no here!

#PasswordAuthentication yes

#PermitEmptyPasswords no

# EC2 uses keys for remote access

PasswordAuthentication no -> PasswordAuthentication yes //no를 yes로 변경

.
.

5. sudo 권한 추가(선택)
vi /etc/

.

.

## Allow root to run any commands anywhere

root    ALL=(ALL)       ALL

test    ALL=(ALL)       ALL //root 계정 밑에 추가하기

.

.


6. sshd 재시작

service sshd restart

'개발 > AWS' 카테고리의 다른 글

AWS - 파일질라 FTP/SFTP 연결하기  (0) 2017.04.09

참고 : 생활코딩


# include 와 require 는 파일을 로드 할 때 사용하는 명령어이다.

차이점은 

include가 warning을 일으킨다.

require은 fatal error를 일으킨다.

_once 붙은 것은 파일을 로드 할 때 단 한번만 로드하면 된다는 의미이다.

include

include_once

require

require_once


# namespace 라는 키워드는 동일한 함수의 이름을 하나의 php 애플리케이션 안에 사용할 수 있게 만든다.


# 파일복사 

리눅스일 경우 파일을 가지고 있는 디렉토리의 권한을 chmod 753 . 명령어를 실행시켜야만 파일이 복사된다.

원래 /var/www/html디렉토리의 권한은 chmod 755로 되어있다. 하지만 copy()함수를 사용하기 위해서는

디렉토리의 파일허가권(소유자,그룹,그외 사용자)부분에서 그외 사용자에 대해 쓰기(w)와 실행(x) 권한이 필요하다.

다른 방법으로는 chown 명령어로 소유자를 바꿔주면 된다.


1. 소스코드 

<?php

$file1 = 'test.txt';

$file2 = 'example.txt';


if(!copy($file1, $file2)){

  echo "failed to copy {$file1}...";

}

?>


2. 디렉토리 권한을 주지 않거나 소유자 변경을 안한경우

Warning: copy(example.txt): failed to open stream: Permission denied in /var/www/html/test.php on line 5 failed to copy test.txt...


3. 디렉토리 권한을 주거나 소유자 변경을 한경우 위 경고가 나오지 않으면서 test.txt 라는 파일내용을 복사해 example.txt 라는 파일을 생성시킨다.


# 파일삭제 

파일삭제 또한 마찬가지로 

디렉토리의 권한 그외 사용자에 대해 쓰기(w)와 실행(x) 권한이 있어야 한다.

다른 방법으로는 chown 명령어로 소유자를 바꿔준다.


1. 소스코드

<?php

unlink('example.txt');

?>


2. 디렉토리 권한을 주지 않거나 소유자 변경을 안한경우

Warning: unlink(example.txt): Permission denied in /var/www/html/test.php on line 2


3. 디렉토리 권한을 주거나 소유자 변경을 한경우 example.txt 라는 파일은 삭제된다.


#파일 읽기 / 파일 쓰기

file_get_contents() 텍스트로 이루어진 파일을 읽어서 문자열을 리턴한다 (내부,외부)

file_put_contents() 쓰기, 화면에는 글자수 리턴한다.

fopen()

fread()

fwrite()


#파일 제어 트러블 슈팅

복사,삭제,읽기,쓰기에 대해 permission denied가 나온다면

chown 명령어를 통해 디렉토리 소유자를 root에서 바꿀 소유자 명으로 지정해주면 된다.

ex) chown apache .

다른 방법으로는 chmod 명령어를 사용해서 그 외 사용자 대해 wx권한을 주면 된다.

ex) chmod 753 .


#디렉토리 제어

getcwd()   :현재 디렉토리 출력

chdir('../') :상위 디렉토리 이동

scandir()   :파일과 디렉토리를 배열로 리턴, 두번째 인자는 순서

mkdir()     :디렉토리 생성 ex)mkdir("1/2/3",0700,true) 디렉토리명,권한설정, recursive인자(true)


#파일 업로드, move_upload_file

참고 : 

http://home78.cafe24.com/tc/tag/163

https://opentutorials.org/course/62/5136


#문자열 다루기

strpos()


#정규표현식

특정한 규칙을 가진 문자열의 집합을 표현하는데 사용하는 형식 언어

programming language나 text editor 등에서 문자열의 검색과 치환을 위한 용도로 쓰임

정규표현식에서 사용하는 기호를 Meta문자라고 한다.

참고 :

https://opentutorials.org/course/909/5143

https://opentutorials.org/course/62/5141

http://www.nextree.co.kr/p4327/

연습 :

http://regexr.com

'개발 > php' 카테고리의 다른 글

php - 1  (0) 2017.04.05

참고 : 생활코딩


# 문자열을 표현할 때에는 '' or "" 사용

차이점은 

'' 경우 문자열로 인식한다.

"" 경우 문자열에서 치환할 곳을 찾아내어 값을 넣는다.

$d 부분에 $a를 보면 중괄호{} 안에 있지만 $e 부분처럼 사용 안 할 수 있다.


1. 소스코드

<?php 

$a='a';

$b='b{$a}';

$c='c$a';

$d="d{$a}";

$e="e$a";

echo $a. "<br />";

echo $b. "<br />";

echo $c. "<br />";

echo $d. "<br />";

echo $e. "<br />";

?>


2. 출력화면


# 결합시킬 때에는 '.' 을 사용


1. 소스코드

<?php 

$a="abc";

$b="def";

echo "123"."456". "<br />";

echo "Hello"."World". "<br />";

echo $a.$b. "<br />";

?>


2. 출력화면



# echo 와 print

차이점

echo는 하나 이상의 문자열을 출력하며 리턴값 없음.

print는 하나의 입력값을 받으며 '1'이라는 값을 리턴, 괄호()를 넣어서 사용하거나 없이 사용가능함.


1. 소스코드

<?php 

echo "abc","def". "<br />";

echo "abcdef". "<br />";

print "abcdef". "<br />";

print("abcdef"). "<br />";

var_dump(print "abcdef". "<br />");

?>


2.출력화면


# var_dump(), var_export(), print_r() 함수

var_dump(), var_export(), print_r() : 배열이나 객체를 문자열로 출력할때 사용, 디버깅용 함수로 적합.

참고 :

https://chongmoa.com:45183/php/5130


1.소스코드

<?php  

$var = array(1,2,3,4,5);

var_dump($var);

echo "<br />";

var_export($var);

echo "<br />";

print_r($var);

?>


2.출력화면



# define() 함수를 사용해서 상수를 정의할 수 있다.

상수가 한번 정의되면, 변경하거나 해제 할 수 없다.


1.소스코드

<?php  

define("title","Hello world!");

echo title;

?>


2.출력화면


# const 키워드도 상수를 정의 할 수 있다.

PHP5.3.0 부터 사용 가능

함수, 루프, if구문, try / catch 블록 안에서는 선언 불가.

컴파일 시에 정의되기 때문에 최상위 영역에서 선언.


1. 소스코드

<?php  

const title = "Hello world!";

echo title;

?>


2. 출력화면


# gettype() 함수와 settype() 함수

gettype() 함수는 데이터타입을 보여준다.

settype() 함수는 데이터타입을 바꿀 수 있다.


1. 소스코드

<?php  

$var = 1;

echo gettype($var). "<br />";

settype($var,'string');

echo gettype($var). "<br />";

?>


2. 출력화면


# 변수의 이름조차도 가변적으로 바꿀 수 있다.

 

1. 소스코드

<?php  

$stage = 'level1';

$$stage = 'level2';

echo $level1;

?>


2. 출력화면


# '=='와 '==='의 비교

차이점

==(Equal) : 서로 같다(단순 데이터 비교)

===(Identical) :서로 같고, 자료형도 같다 (단순 데이터 비교, 자료형까지 비교하여 엄격히 비교)

'===' 비교연산자를 사용하는게 보안상 좋다.

참고 :

http://vucket.com/index.php/topic/view/51


1. 소스코드

<?php 

$a = '1';

$b = 1;

if ($a == $b) {

     echo "true". "<br />";

} else {

     echo "false". "<br />";

}

if ($a === $b) {

  echo "true". "<br />";

} else {

  echo "false". "<br />";

}

?>


2. 출력화면



# 0외에 값이 없는 배열, 빈문자열("",''), NULL, 문자 0 등도 0으로 간주 된다.

empty() : 변수가 비어있는지 확인 (값이있으면 FALSE)

is_null() : 변수가 NULL인지를 확인 (NULL이 아니면 FALSE)

isset() : 변수에 값이 존재하고, NULL 이 아닌지 확인(NULL일 경우 FALSE)


1. 소스코드

<?php  

$var = 1;

var_dump(empty($var));

var_dump(is_null($var));

var_dump(isset($var));

?>


2. 출력화면


'개발 > php' 카테고리의 다른 글

php - 2  (0) 2017.04.06

QR 코드 생성하기


- ZXing 라이브러리 추가하기

1. bulid.gardle(Module: app) 을 더블클릭합니다.

2. dependencies 안에 zxing 라이브러리를 추가 시킵니다.

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.google.zxing:core:3.2.1'
compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
}

3. Sync Now를 클릭해 동기화 시킵니다.


- ZXing 라이브러리 추가 확인하기


1. app 우클릭해서 Open Module Settings 클릭합니다.



2. Modules 목록에 있는 app을 클릭하면 상단 바에 여러 목록이 중에 Dependencies를 클릭하면 아래 화면에 ZXing라이브러리가 추가된것을 확인가능. 



- 새로운 액티비티 생성


1. 액티비티 생성하기(QrActivity)



- Coding


MainActivity.java


public class MainActivity extends AppCompatActivity {

private Button button;
private EditText editText;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

final Context context = this;
editText = (EditText) this.findViewById(R.id.editText);
button = (Button) this.findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String text2Qr = editText.getText().toString();
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
try {
BitMatrix bitMatrix = multiFormatWriter.encode(text2Qr, BarcodeFormat.QR_CODE,200,200);
BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
Bitmap bitmap = barcodeEncoder.createBitmap(bitMatrix);
Intent intent = new Intent(context, QrActivity.class);
intent.putExtra("pic",bitmap);
context.startActivity(intent);
} catch (WriterException e) {
e.printStackTrace();
}
}
});
}
}


activity_main.xml


<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Generate"
android:id="@+id/button"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />


QrActivitiy.java


public class QrActivity extends AppCompatActivity {

private ImageView imageView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_qr);
imageView = (ImageView) this.findViewById(R.id.imageView);
Bitmap bitmap = getIntent().getParcelableExtra("pic");
imageView.setImageBitmap(bitmap);
}
}


activity_qr.xml


<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />

- 출력화면



- 참고사이트

https://www.youtube.com/watch?v=-vWHbCr_OWM


간단한 서버 구축


· C드라이브에 디렉터리(폴더)를 생성시킨 후 server.js파일을 저장합니다.

--server.js--

const http = require('http');

const hostname = '127.0.0.1';

const port = 1337;

http.createServer((req, res) => {

  res.writeHead(200, { 'Content-Type': 'text/plain' });

  res.end('Hello World\n');

}).listen(port, hostname, () => {

  console.log(`Server running at http://${hostname}:${port}/`);

});


1. cmd를 열어 server.js파일이 있는 디렉터리로 이동합니다.


2. node server.js 입력하면 서버가 올라갑니다.


3. localhost:1337 or 127.0.0.1 을 입력하면 위에 있는 화면이 보입니다.


외부에서 자기아이피로 서버 접근하기


-ttp = require('http');


const port = 1337;


http.createServer((req, res) => {

  res.writeHead(200, { 'Content-Type': 'text/plain' });

  res.end('Hello World\n');

}).listen(port, () => {

  console.log(`Server running at http:// ip :${port}/`);

});


*hostname 부분을 지우고 node명령어로 실행시켜주시면 됩니다.-server.js--

const h


'개발 > Node.js' 카테고리의 다른 글

Node.js -1 Node.js & NPM(Node Pakaged Modules) 설치  (0) 2016.05.02

Node.js & NPM(Node Packaged Modules) 설치


- Node.js 다운로드 https://nodejs.org/ko/


        

* 자기에게 맞는 버전을 보고 설치합니다.


- NPM 설치

1. 원하는 위치에서 폴더를 생성합니다. (C드라이브에 node라는 폴더 생성했습니다.)

2. cmd창을 열어 npm 명령어를 사용합니다.

  ex) cd c:\node

      npm init //모듈 받는 폴더를 지정, 몇가지 입력할게 나오는데 다 엔터 눌러서 넘깁니다.

      npm install fs --save //fs 는 파일시스템을 편하게 이용할 수 있는 모듈
      npm install express --save //express 설치

      npm install jade --save //템플릿 엔진 설치, http://expressjs.com/ko/guide/using-template-engines.html 템플릿 엔진 설명

NPM 설치 목록 보기: npm list //package.json 파일을 열어 확인할수있습니다.

NPM 제거 : npm uninstall 모듈명

'개발 > Node.js' 카테고리의 다른 글

Node.js -2 간단한 서버 구축  (0) 2016.05.03

- APMSETUP 설치

APMSETUP다운로드  ◀ APMSETUP 설치프로그램을 다운받아 설치 합니다.


구글이나 익스플로어를 열어 주소창에 localhost 를 입력해서 아래 그림이 나오면 설치 완료.




- 업데이트 버전 발견 팝업창 없애기

작업표시줄에 있는 APMSETUP 모니터 아이콘 우클릭 시 아래에 있는 화면이 나옵니다.




1. 서버 환경 설정(V) 클릭 

2. 체크 해제하고 저장 버튼을 클릭하면 끝납니다.




- Apache 설정

Listen : 포트번호 

ServerName : 서버의 주소 (도메인) //localhost = 127.0.0.1

ServerAdmin : 관리자이메일 입력하는 곳

DocumentRoot : 웹서버 경로

DirectoryIndex : 웹서버에 접속할 때 기본적으로 실행되는 파일명


여기서, Listen , ServerName 을 수정해야 합니다.

* 포트 인바운드 규칙 추가 하기

Listen : 80 //기본설정 , HTTP 서버는 80 포트

80포트로 접속이 안된다면 8080 이나 남는 포트번호를 설정해주시면 됩니다. 

ServerName : 자기의 아이피 입력 //cmd창에서 ipconfig로 확인



-MySQL 설정

* InnoDB 설정 & 동시 사용자 설정 & UTF-8 설정

C:\APM_Setup\Server\MySQL5\data의 my.ini를 C:\APM_Setup\Server\MySQL5로 복사 //두 경로에 모두 my.ini 파일있어야합니다.


<my.ini 파일 캡처>

[mysqld]

character-set-server = utf8

collation-server = utf8_general_ci

init_connect = SET collation_connection = utf8_general_ci

init_connect = SET NAMES utf8

      (생략)

default-storage-engine=innodb

max_connections = 500 

wait_timeout = 60


[mysqldump]

default-character-set = utf8


[mysql]

default-character-set = utf8


* my.ini 파일 설정을 저장한 후 재시작



- Apache (httpd.conf 설정)

C:\APM_Setup\Server\Apache\conf 안에 httpd.conf 파일 설정

한글 지원 설정

php 연동 설



- 외부에서 phpmyadmin 접속 설정

C:\APM_Setup\Server\Apache\conf\extra 안에 httpd-alias.conf 파일 설정


#

# Alias 설정

#


<IfModule alias_module>


    Alias /myadmin/ "C:/APM_Setup/Server/phpMyAdmin/"

    <Directory "C:/APM_Setup/Server/phpMyAdmin">

        Options MultiViews

        AllowOverride None

        Order deny,allow

deny from all

        Allow from 127.0.0.1

    </Directory>


# 외부 접속 가능하게 하려면 아래 설정처럼 변경하여 주시기 바랍니다.


#    <Directory "C:/APM_Setup/Server/phpMyAdmin">

#        Options MultiViews

#        AllowOverride None

#        Order allow,deny

#        Allow from all

#    </Directory>


</IfModule>


 < httpd-alias.conf 원본내용>



#
# Alias 설정
#

<IfModule alias_module>

    Alias /myadmin/ "C:/APM_Setup/Server/phpMyAdmin/"
    <Directory "C:/APM_Setup/Server/phpMyAdmin">
        Options MultiViews
        AllowOverride None
        Order allow,deny
Allow from all
    </Directory>

# 외부 접속 가능하게 하려면 아래 설정처럼 변경하여 주시기 바랍니다.

#    <Directory "C:/APM_Setup/Server/phpMyAdmin">
#        Options MultiViews
#        AllowOverride None
#        Order allow,deny
#        Allow from all
#    </Directory>

</IfModule>

     < httpd-alias.conf 수정내용>

* 포트 3306(Mysql 포트) 인바운드 해줄 것!
Windows 방화벽 -> 고급설정 -> 인바운드 규칙 -> 새 규칙 -> 3306포트 추가


+ Recent posts