linux class(new) 1 페이지

본문 바로가기
사이트 내 전체검색


회원로그인

linux class(new)

Apache Web Server

페이지 정보

작성자 admin 작성일16-05-02 19:10 조회1,385회 댓글0건

본문

apche / php / mysql database 서버 설치 및 연동
바이너리 패키지로 설치할 경우에는 아래와 같은 패키지기 필요하다.
yum grouplist 로 패키지그룹을 확인한다음

MySQL 데이터베이스 서버
MySQL 데이터베이스 클라이언트
PHP 지원
웹 서버

centos[root ~]# yum groupinfo "php 지원"
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Group Process
Loading mirror speeds from cached hostfile
* base: centos.mirror.cdnetworks.com
* extras: centos.mirror.cdnetworks.com
* updates: centos.mirror.cdnetworks.com

Group: PHP 지원
Description: PHP 웹 어플리케이션 프레임워크.
Mandatory Packages:
php
Default Packages:
php-gd
php-pdo
php-pear
php-xml
Optional Packages:
php-ldap
php-mysql
php-odbc
php-pecl-apc
php-pecl-memcache
php-pgsql
php-soap
php-xmlrpc
centos[root ~]#

- php 지원패키지그룹중에서는 mysql database 와 연동하기위해서 php-mysql 패키지를 설치해야 한다.
패키지 그룹설치시 optional 패키지는 기본적으로 설치되지 않는다.


centos[root ~]# rpm -q php-mysql
php-mysql 패키지가 설치되어 있지 않습니다
centos[root ~]#



centos[root ~]# yum install php-mysql
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
.... 이하 생략.


APM 연동을 위해서 필요한 패키지를 확인하고 설치하였으면
데이터베이스 서버부터 올려서 테스트 한다.

centos[root ~]# service mysqld start
MySQL 데이타베이스 초기화 중: Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h centos password 'new-password'
...


centos[root ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.00 sec)

mysql> quit
Bye
centos[root ~]#

- mysql database 관리자 암호 설정

centos[root ~]# mysqladmin -u root -p password 암호지정
Enter password: <--- 암호변경전 현재의 db root 암호를 입력.(없으면 그냥 엔터)
centos[root ~]#



centos[root ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
centos[root ~]#

- root 암호가 설정되어 있으므로 그냥은 접속 안되며 아래와 같이 접속해야 한다.

centos[root ~]# mysql -u root -p [ -h localhost ]
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>


- apm 연동 테스트
1. apache server 실행

centos[root /var/www/html]# service httpd start
httpd (을)를 시작 중: httpd: Could not reliably determine the server's fully qualified domain name, using 172.20.1.100 for ServerName
[ OK ]
centos[root /var/www/html]#

- ServerName 지시자를 확인하여 경고가 뜨지 않게 아파치 설정을 고쳐야 한다.


아래와 같은 테스트 파일을 /var/www/html 디렉토리에 test.php 로 작성
<?php
echo "

Hello PHP

";
?>
- 웹브라우저에서 실행이 잘되는지 확인.

- db 연동 테스트

<?php
$connect = mysql_connect("localhost","root","암호");
if(! $connect) {
echo "DB connect fail
";
echo mysql_error() . "
";
}
else {
echo "successful db connect";
}
?>

*. php 소스 파일의 시작을 opne short tag(<? ) 로 하는 경우에는
/etc/php.ini 파일에 open_short_tag 설정옵션이 On 으로 되어 있어야 한다.
php.ini 파일을 수정하고나서 httpd 를 다시 실행해야 한다.

--------------------------------------------------------------------------------
아파치 서버 주요 설정 지시어

apache 설정(httpd.conf) 주요 지시어

ServerRoot "/usr/local/apache" ; 아파치서버 디렉토리
Listen 80 ; 아파치 서버 포트
LoadModule : 아파치 서비스 구동시 로드되는 모듈.(DSO 방식일경우)
- 정적컴파일된 모듈은 httpd -l 로 확인할 수 있다.

User daemon ; 아파치 서버 프로세스 소유자
Group daemon ; 아파치 서버 프로세스 그룹

ServerName 도메인명 또는 ip address ; 이부분이 설정되어 있지 않으면
아파치가 시작될때 경고메세지가 출력된다.
도메인이 없다면 자신의 ip address 라도 적어두어야 한다.
ex) ServerName 127.0.0.1

DocumentRoot "/usr/local/apache/htdocs"
웹페이지의 root 디렉토리.

<= 아파치 서버의 DocumentRoot 디렉토리
Options FollowSymLinks <== 웹페이지에 심볼릭링크 파일을 허용.
AllowOverride None <= 보안상 None 으로 하는것이 안전하다.
(웹문서 디렉토리의 접근제한 설정인 .htaccess 파일사용여부)
Order deny,allow
Deny from all



Options Indexes FollowSymLinks
Order allow,deny
Allow from all



Order allow,deny
Deny from all
Satisfy All


ErrorLog "logs/error_log"
LogLevel warn
- warn 수준이상의 메시지를 logs/error_log 파일에 기록.

CustomLog "logs/access_log" common
- access 기록.

ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"
- cgi 파일을 위한 디렉토리가 DocumentRoot 바깥에 있을경우
/cgi-bin 으로 alias 시켜준다. ( /usr/local/apache/htdocs/cgi-bin 이런 의미가 된다)


AllowOverride None
Options None
Order allow,deny
Allow from all


DefaultType text/plain <= Default MIME type 으로 Document 형식을 지정.

TypesConfig conf/mime.types <= MIME type 설정파일

AddType <= MIME type 설정.
ex)
AddType application/x-httpd-php .php .html .htm
AddType application/x-httpd-php-source .phps
AddHandler cgi-script .cgi <= cgi 는 보안상 특정 디렉토리에서만 실행되도록
설정되어 있는데 아무디레토리에서나 실행가능하게 하기위한 설정.
확장자가 cgi 이기만 하면 된다.

include 경로명 <= 웹서버 관련 설정파일을 포함하기 위한 설정




Options
-----------
All : 모든 옵션 사용. 보안상 좋지 않다
None: 아무 옵션도 사용하지 않음.
Indexes : 파일리스트를 다 보여준다. 역시 보안상 좋지 않다.
ExecCGI : CGI 실행을 할수 있도록 한다.
FollowSymLinks : symbolic 링크된 파일을 사용할 수 있도록 한다.
DocumentRoot 외부에 지정된 디렉토리라도 링크걸려 있으면
사용가능하다.

AllowOverride
----------------
.htaccess 및 .htpasswd 사용여부에 관련된 설정.
이 설정은 특정 디렉토리를 access 하는경우 인증절차를
거쳐서 디렉토리에 access 되게 하는 방식.

ex) 인증을 필요로 하는 디렉토리에서 아래처럼 파일을 만들고
암호 설정을 하게 되면 허가된 사용자만 디렉토리에 접근할 수 있다.
htpasswd -c .htpasswd admin
암호파일에 사용자 추가및 암호설정
c 옵션은 (create ; 파일을 새로 만듦)
htpasswd .htpasswd user1
(암호파일에 계정 추가, user1 계정이 이미 있으면 암호가 변경이 됨)

# cat .htaccess
AuthName "member"
AuthType Basic
AuthUserFile /usr/local/apache/htdocs/test/.htpasswd
require valid-user

httpd.conf 파일에서는
AllowOverride 지시자를 All 로 해주어야 적용이 된다.


Order deny,allow <= deny 규칙 먼저 적용, allow 는 나중.
--------------------
deny - 특정 위치에서 access 거부
allow - 특정 위치에서 access 허용

ex)
Order deny,allow 먼저 거부하고 나서 허용하는 순서로 동작(특정주소만 허락할 경우),반대의 설정은 Order allow,deny
Deny from all ; 모든 주소에 대해서 access 금지
Allow from 192.168.1.0/24

/test 디렉토리 access 권한은 192.168.1.0 네트워크에서만 가능하다.

*. 아파치를 DSO 방식으로 설치를 한 경우라면 아파치 설치후 나중에
필요한 모듈이 있으면 apxs 를 이용해서 올려줄 수 있다.

실습 -
apm 을 설치 및 설정 완료 후 제로보드나 워드프레스등을 설치하여 테스트
- 홈페이지 이용을 위한 DB 계정 및 데이터베이스 설정
- 홈페이지 운영을 위한 mysql 계정과 디비를 생성.

mysql> create database shop;
Query OK, 1 row affected (0.00 sec)
mysql>

- 사용자 계정 생성 query
mysql> create user 사용자아이디@localhost identified by '사용자암호';

mysql> create user admin@localhost identified by 'pass1234';
Query OK, 0 rows affected (0.00 sec)



mysql> grant all privileges on shop.* to admin@localhost;
Query OK, 0 rows affected (0.00 sec)

- admin 계정한테 shop DB 의 모든 권한을 부여

* 사용자 계정 삭제 및 DB 권한 삭제
사용자 계정 삭제

drop user user명@server명;
ex) drop user kildong@localhost;


db 권한삭제
REVOKE ALL ON db명.table명 FROM user명@server 명; 모든 권한삭제;
REVOKE ALL ON db명.table명 FROM user명@server 명; 특정권한삭제;

댓글목록

등록된 댓글이 없습니다.


접속자집계

오늘
42
어제
75
최대
611
전체
448,092
개인정보취급방침 서비스이용약관 twoseven.kr All rights reserved.
상단으로