'2018/06'에 해당되는 글 3건

  1. 2018.06.29 [PHP] 날짜 함수
  2. 2018.06.05 [MariaDB] Centos7 MariaDB 자동 설치
  3. 2018.06.04 [리눅스]selinux 아파치 접근 문제

[PHP] 날짜 함수

WEB 2018. 6. 29. 06:10

date("Y-m-d H:i:s")

현재 날짜/시간을 포맷(fotmat)에 맞게 date형식으로 출력 (24시간 형식 출력)

결과 : 2013-06-13 12:00:00 


date("Ymd") 현재 날짜/시간이 출력됨

결과 : 20070801


date("Y-m-d h:i:s");

현재 날짜/시간을 포맷(fotmat)에 맞게 date형식으로 출력합니다.

(12시간 형식 출력)


date("h:i:s");

현재 시간 출력


date("Y-m-d H:i:s",time());

현재 두번째 매개변수을 timestamp형식으로 읽어 날짜/시간을 포맷(fotmat)에 맞게 date형식으로 출력


date("Y-m-d",strtotime ("-1 months"));

현재의 날짜인 time형식에서 strtotime에 의해 한달을 뺀 time을 date형식으로 변환


date("Y-m-d",strtotime ("+1 days"));

현재의 날짜인 time형식에서 strtotime에 의해 하루를 더한 time을 date형식으로 변환


date("Y-m-d",strtotime ("+1 years"));

현재의 날짜인 time형식에서 strtotime에 의해 1년을 더한 time을 date형식으로 변환


date("Y-m-d",strtotime ("+24 hours"));

현재의 날짜인 time형식에서 strtotime에 의해 24시간을 더한 time을 date형식으로 변환


date("Y-m-d",strtotime ("+1500 minutes"));

현재의 날짜인 time형식에서 strtotime에 의해 1500분을 더한 time을 date형식으로 변환


date("Y-m-d",strtotime ("+1 week"));

현재의 날짜인 time형식에서 strtotime에 의해 1주일을 더한 time을 date형식으로 변환


date("Ymd",strtotime ("-1 days", strtotime('20070819')));

date("Ymd",strtotime ("-1 days", strtotime('2007-08-19')));

20070819의 날짜를 timestamp형식으로 변환후 1일을 빼고 다시 timestamp형식으로 변환후

Ymd 형식의 문자열로 출력


※ 날짜 형식은 -을 넣거나 빼야 한다. 다른 특수문자는 안됨(2007:08:12)

date("Ymd",strtotime ("+1 days",  strtotime('20070819')));

date("Ymd",strtotime ("+1 days",  strtotime('2007-08-19')));

20070819의 날짜를 timestamp형식으로 변환후 1일을 더한후 다시 timestamp형식으로 변환후

Ymd 형식의 문자열로 출력


※ date 함수의 2번째 인자는 timestamp 형입니다.


※ strtotime 함수의 2번째 인자는 timestamp 형입니다.


date( "Y-m-d\TH:i:s", strtotime('20070101040404') );

정상적으로 처리안됨


date( "Y-m-d\TH:i:s", strtotime('2007-01-01 04:04:04') );

정상적으로 처리됨(제트센스 rss에서 사용)


$timestamp=strtotime('+1 years +1 months +1 days');

현재 날짜/시간에 years months days hours minutes seconds 단위로 더하여

timestamp형식으로 리턴합니다.(매개변수 없이 사용불가)


출처: http://jhrun.tistory.com/137

Posted by 꼬장e
,

●설치전 파일 생성

# vi /etc/yum.repos.d/MariaDB.repo

[mariadb]

name = MariaDB

baseurl = http://yum.mariadb.org/10.1/centos7-amd64

gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

gpgcheck=1


●설치

# yum install MariaDB-server


●확인

# rpm -qa | grep MariaDB


●부팅시 자동실행

systemctl enable MariaDB

Posted by 꼬장e
,

출처 : http://forbis.egloos.com/m/3415718


Point : CentOS 설치후 selinux 관련을 사용하지 않음으로 설정하고 재부팅한 다음 설치를 시작했다.


[root@localhost ~]# vi /etc/selinux/config

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

#       enforcing - SELinux security policy is enforced.

#       permissive - SELinux prints warnings instead of enforcing.

#       disabled - SELinux is fully disabled.

SELINUX=disabled

# SELINUXTYPE= type of policy in use. Possible values are:

#       targeted - Only targeted network daemons are protected.

#       strict - Full SELinux protection.

SELINUXTYPE=targeted

[root@localhost ~]# reboot 


만약 재부팅을 하지 않고 진행하려면 쉘상에서 setenforce 0을 입력하면 된다.


[root@localhost ~]# setenforce 0

[root@localhost ~]# setenforce

usage:  setenforce [ Enforcing | Permissive | 1 | 0 ]

 

 

 

혹시라도 selinux를 적용해서 사용하고자 할때에는 웹서버 디렉토리 만든다음 selinux 문맥에 맞게 변경해 주어야 한다.


useradd 명령으로 test 사용자를 추가하면 /home/test 디렉토리가 생성된다.

하지만 selinux가 적용된 시스템에서는 /home/test 디렉토리의 보안문맥이 user_home_t 로 구성되는데, 디렉토리 권한이 755로 되어 있어도 기본 보안문맥으로는 웹(80포트)에서 접근이 불가능하다. 


그러므로 사용자 디렉토리에 대한 보안문맥을 chcon 명령어로 아래와 같이 변경해 주어야 한다.


# chcon -R -t httpd_sys_content_t /home/test


쓰기권한이 필요한 경우 ( 보안 문제가 있으니 정확한 폴더만 승인하자 )

#chcon -R -t httpd_sys_rw_content_t /home/계정/폴더


이렇게 보안문맥을 지정해 주면 /home/test 디렉토리 아래에 생성되는 모든 파일들은 이제부터 httpd_sys_content_t 문맥의 영향을 받아 모두 httpd_sys_content_t 보안문맥으로 생성된다.


이제 "mkdir /home/test/public_html" 명령으로 디렉토리를 생성하면 위의 httpd_sys_content_t 문맥을 가지는 디렉토리가 생성되고 웹 80포트에서 접속이 가능하게 되는 것이다.


[root@localhost ~]# useradd test

[root@localhost ~]# touch ~test/test.txt

[root@localhost ~]# ls -lZ ~test/

-rw-r--r--  root root user_u:object_r:user_home_t      test.txt

[root@localhost ~]# chcon -R -t httpd_sys_content_t /home/test

[root@localhost ~]# ls -lZ ~test/

-rw-r--r--  root root user_u:object_r:httpd_sys_content_t test.txt

[root@localhost ~]#


===


[root@localhost ~]# su - test

[test@localhost ~]$ ls -lZ

-rw-r--r--  root root user_u:object_r:httpd_sys_content_t test.txt

[test@localhost ~]$ touch selinux.txt

[test@localhost ~]$ ls -lZ

-rw-rw-r--  test test user_u:object_r:httpd_sys_content_t selinux.txt

-rw-r--r--  root root user_u:object_r:httpd_sys_content_t test.txt

[test@localhost ~]$



[* 참고 *]


만약 다른곳의 파일을 /home/test 디렉토리 아래로 복사 또는 이동할때에는 어떻게 될까?


cp 명령에 의한 복사시에는 기존 파일 자신의 보안문맥과 함께 httpd_sys_content_t 문맥을 추가적으로 붙여서 복사된다.


[root@localhost ~]# touch root.txt

[root@localhost ~]# ls -lZ root.txt

-rw-r--r--  root root user_u:object_r:user_home_t      root.txt

[root@localhost ~]# cp root.txt /home/test

[root@localhost ~]# ls -lZ /home/test/

-rw-r--r--  root root user_u:object_r:httpd_sys_content_t root.txt

-rw-rw-r--  test test user_u:object_r:httpd_sys_content_t selinux.txt

-rw-r--r--  root root user_u:object_r:httpd_sys_content_t test.txt

[root@localhost ~]#


mv 명령에 의한 이동시에는 기존 파일 자신의 보안문맥만 유지하고 파일이 이동된다. 즉 httpd_sys_content_t 보안문맥이 추가되지 않는다는 것이다.


[root@localhost ~]# touch mv.txt

[root@localhost ~]# ls -lZ mv.txt

-rw-r--r--  root root user_u:object_r:user_home_t      mv.txt

[root@localhost ~]# mv mv.txt /home/test/

[root@localhost ~]# ls -lZ /home/test/

-rw-r--r--  root root user_u:object_r:user_home_t      mv.txt

-rw-r--r--  root root user_u:object_r:httpd_sys_content_t root.txt

-rw-rw-r--  test test user_u:object_r:httpd_sys_content_t selinux.txt

-rw-r--r--  root root user_u:object_r:httpd_sys_content_t test.txt

[root@localhost ~]#


그러면 ftp에서는 어떻게 할까?


* ftp 홈에대한 권한적용을 풀어주기 위해 아래와 같이 입력한다.

-P옵션은 재부팅후에도 적용되는 옵션으로 selinux 환경설정이 저장된다는 의미다.


# setsebool -P ftp_home_dir 1 


* ftp에 대해 selinux 파일보안 정책을 사용하지 않도록 하려면 아래와 같이 입력한다.


# setsebool -P ftpd_disable_trans 1 



'OS' 카테고리의 다른 글

윈도우10 자동업데이트 끄기  (0) 2018.08.03
[php] POST 전송 데이터 잘릴때  (0) 2018.07.24
[리눅스] 절전모드 해제  (0) 2018.05.30
[리눅스]자바 설치  (0) 2018.05.30
[리눅스]ssh 포트 변경  (0) 2018.05.30
Posted by 꼬장e
,