'아파치'에 해당되는 글 2건

  1. 2014.01.10 Apache 2.x + OpenSSL 인증서 설치 2
  2. 2011.09.14 Installation Apache 2 + PHP 5 + Oracle Client 2



## 설치 환경


- OS : CentOS 6.4

- httpd Server : Apache 2.4.6

- 인증서 발급기관 : COMODO


- 본 설치과정은 "가비아(www.gabia.com)"에서 인증서를 구매 / 발급받는 과정을 전제로 기술되었습니다.



1. Apache 및 OpenSSL 설치

 - http://calflove.tistory.com/335  참고




2. 개인키 생성


1) 랜덤 넘버 생성


# cd /usr/local/openssl/certs

# ../bin/openssl md5 * > rand.dat



2) 키 쌍 생성


# ../bin/openssl genrsa -rand ./rand.dat -des3 2048 > key.pem


- 위 명령을 실행시키면 아래와 같이 개인키 비밀번호를 물어보는데 반드시 기억해야 한다.


48 semi-random bytes loaded

Generating RSA private key, 1024 bit long modulus

..++++++

...++++++

e is 65537 (0x10001)

Enter pass phrase for 2048: {키입력}

Verifying - Enter pass phrase for 2048: {키다시입력}



3) 생성된 키 쌍을 이용하여 CSR 생성


# ../bin/openssl req -new -key key.pem > csr.pem


- CSR 생성시 아래 정보는 모두 영문으로 입력해야 한다.

- 추가 속성 질문에는 건너 뛰어도 무방하다.


Enter pass phrase for key.pem: {개인키비밀번호입력}

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN.

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter '.', the field will be left blank.

-----

Country Name (2 letter code) [AU]:KR

State or Province Name (full name) [Some-State]:SEOUL

Locality Name (eg, city) []:GANGNAM-GU

Organization Name (eg, company) [Internet Widgits Pty Ltd]:회사명

Organizational Unit Name (eg, section) []:Development

Common Name (e.g. server FQDN or YOUR name) []:호스트명

Email Address []: 메일주소


Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:

An optional company name []:



- 위에서 Common Name에는 호스트명을 정확히 기재한다. ( SSL 인증서 발급기관에 요청한 호스트명과 일치해야 함)

- 메일주소는 인증메일이 발송되므로 꼭 확인이 가능한 메일주소를 기입한다.




3. CSR 내용을 인증기관에 송부하여 인증서를 발급받는다.


1) 인증메일로 인증코드를 보내주는데 이를 확인해주면 인증서가 메일에 첨부되어 발송된다.


2) 서버에서 생성한 키파일과 인증기관에서 보내온 파일을 아래 명령어로 비교해 보면 똑같아야 한다.


# openssl rsa -in key.pem -modulus -noout | openssl md5

# openssl x509 -in cert.pem -modulus -noout | openssl md5





4. 인증서 설치 


1) 인증서 복사


 - 메일에 첨부되어 있는 인증서를 서버에 복사해 넣는다

   (필자의 경우 아파치 설정 파일이 위치해 있는 /usr/local/httpd/conf/ssl에 넣어두었다 )

 - RootCA_ChainCAs_Basic.zip는 압축을 풀면 2개의 파일이 나오는데, ChainCA.cer은 증계인 인증서(발급기관)이며 RootCA.cer은 최상위인증기관 인증서(루트인증서)이다.


2) SSL 설정 파일 변경


 # cd /usr/local/httpd/conf/extra

 # vi httpd-ssl.conf


아래 내용을 수정한다.


Listen 443


<VirtualHost _default_:443>

DocumentRoot "디렉토리위치"

ServerName 호스트명:443

ServerAdmin 메일주소

ErrorLog "/usr/local/httpd/logs/ssl-error_log"

TransferLog "/usr/local/httpd/logs/ssl-access_log"


인증서가 있는 위치 파일을 지정해준다.


SSLCertificateFile "/usr/local/httpd/conf/ssl/cert.pem"

SSLCertificateKeyFile "/usr/local/httpd/conf/ssl/key.pem"

SSLCertificateChainFile "/usr/local/httpd/conf/ssl/ChainCA.cer"



SSLCertificateFile 은 인증서 파일 경로, 

SSLCertificateKeyFile 은 개인키 파일 경로,

SSLCertificateChainFile 은 중개 인증서이다.


- CSR 파일 / 루트 인증서는 별도 설정안해도 됨.



3) httpd.conf 설정 수정



# cd /usr/local/httpd/conf

# vi httpd.conf


아래 두가지 항목에 주석이 되어 있으면 풀어준다.


LoadModule ssl_module modules/mod_ssl.so

Include conf/extra/httpd-ssl.conf



<IfModule ssl_module>

SSLRandomSeed startup builtin

SSLRandomSeed connect builtin

</IfModule>





5. 설정 파일 점검


# cd /usr/local/httpd/bin

# ./apachectl configtest



Case 1) 만약에 아래와 같은 에러가 발생하면.. 


# ./apachectl configtest

AH00526: Syntax error on line 76 of /usr/local/httpd-2.4.6-ssl/conf/extra/httpd-ssl.conf:

SSLSessionCache: 'shmcb' session cache not supported (known names: ). Maybe you need to load the appropriate socache module (mod_socache_shmcb?).


A1) 아래 라인의 주석을 풀어준다. (물론 /usr/local/httpd/modules)에 해당 모듈이 있어야 한다.


LoadModule socache_shmcb_module modules/mod_socache_shmcb.so



A2) 만약 SSL 캐쉬를 안 쓰려면 아래와 같이 옵션을 none으로 해 둔다. 


SSLSessionCache         none

#SSLSessionCache         "dbm:/usr/local/httpd-2.4.6-ssl/logs/ssl_scache"

#SSLSessionCache        "shmcb:/usr/local/httpd-2.4.6-ssl/logs/ssl_scache(512000)"

#SSLSessionCacheTimeout  300





6. 보안 환경 설정


1) 네트워크 방화벽 설정


신규로 SSL 쓴다면 443포트가 막혀있을 가능성이 크다. 외부에서 서버로 443 포트가 접속이 가능하도록 네트워크 방화벽을 열어준다. 


2) 시스템 방화벽 설정


시스템에도 방화벽이 설치되어 있는 경우가 많을 텐데 시스템에서도 443 포트를 열어준다.


# lokkit --service https





7. 아파치 기동



# cd /usr/local/httpd/bin

# ./apacehctl start

Apache/2.4.6 mod_ssl (Pass Phrase Dialog)
Some of your private key files are encrypted for security reasons.
In order to read them you have to provide the pass phrases.

Server 호스트명:443 (RSA)
Enter pass phrase:  


- 인증서 생성시 사용했던 키를 넣어준다.


- 인터넷 검색을 하다보면 # apachectl 뒤에 startssl|sslstart|start-SSL 옵션을 쓰는 경우가 있는데

  현재는 더이상 지원하지 않으며 start해주면 된다.




참고 자료


1. https://kicassl.com/intro/installguide.php ( SSL 설치 가이드 )

2. https://sslhosting.gabia.com/service ( SSL 설치가이드)

3. http://talkit.tistory.com/111 (SSL 캐쉬로 인한 속도 저하) 

Posted by 카프러브


본 문서는 Apache + PHP + Oracle Client를 설치 문서이다.

작성일 : 2011. 9. 7



참고 사이트

- Installing PHP and the Oracle Instant Client : http://www.oracle.com/technetwork/articles/technote-php-instant-084410.html

- Apache 2.X + PHP 5.X 설치 : http://www.dakrink.pe.kr/archives/341

- php.ini 관련 설정 : http://www.solanara.net/solanara/amp



설치 환경 및 모듈 버전

- OS : Redhat Enterprise 5.2

- Httpd : Apache 2.2.20 (http://httpd.apache.org)

- PHP : php 5.3.8 (http://www.php.net)

- Oracle Instant Client : 11.2.0.2.0 (http://www.oracle.com/technetwork/database/features/oci/index.html)

- OCI8 : 1.4.6 (http://pecl.php.net/package/oci8)



설치 위치

- Apache : /usr/local/httpd-2.2.20
- PHP : /usr/local/php-5.3.8



소스 위치

- /usr/local/src



Step 1. Installing Apache with PHP


1. Compile & Install Apache

# cd /usr/local/src/httpd-2.2.20
# ./configure --prefix=/usr/local/httpd-2.2.20 --enable-module=so --enable-mods-shared=most
# make ; make install


2. Edit httpd.conf ( 아래 라인 추가 )

AddType application/x-httpd-php .php .htm .html .inc .php5 .php4
AddType application/x-httpd-php-source .phps
DirectoryIndex index.html index.php index.htm


3. Compile & Install PHP

# cd /usr/local/src/php-5.3.8
# ./configure --prefix=/usr/local/php-5.3.8 \
--with-apxs2=/usr/local/httpd-2.2.20/bin/apxs \
--with-config-file-path=/usr/local/httpd-2.2.20/conf \
--with-exec-dir=/usr/local/httpd-2.2.20/bin --with-gd
# make ; make install


4. Check Web Server Working



Step 2. Install Oracle Instant Client


1. Download Oracle Instant Client

1) Download URL : http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html

2) Download Package
- Instant Client Package - Basic
- Instant Client Package - SDK


2. Installing by RPM (32BIT)

1) 32bit

# rpm -Uvh oracle-instantclient11.2-basic-11.2.0.2.0.i386.rpm
# rpm -Uvh oracle-instantclient11.2-devel-11.2.0.2.0.i386.rpm

2) 64bit

# rpm -Uvh oracle-instantclient11.2-basic-11.2.0.2.0.x86_64.rpm
# rpm -Uvh oracle-instantclient11.2-devel-11.2.0.2.0.x86_64.rpm

위 RPM은 /usr/lib/oracle/11.2/client 또는 /usr/lib/oracle/11.2/client64에 설치된다.



Step 3. Installing OCI8


1. OCI 8 설치

# /usr/local/php-5.3.8/bin/pecl install oci8

그럼 아래와 같은 질문이 출력된다.

Please provide the path to the ORACLE_HOME directory. Use 'instantclient,/path/to/instant/client/lib' if you're compiling with Oracle Instant Client [autodetect] :

그러면 아래와 같은 옵션을 입력한다.

instantclient,/usr/lib/oracle/11.2/client/lib


2. 모듈 복사

OCI8이 설치되면 /usr/local/php-5.3.8/lib/php/extensions/no-debug-non-zts-20090626 아래 oci8.so가 생성된다. 이 외에 Extension Modules이 있을 수 있으니 상위 디렉토리(/usr/local/php-5.3.8/lib/php/extensions) 로 복사해 넣는다.


3. 모듈 설정

1) php.ini 복사

소스 컴파일 경우 php.ini가 생성되지 않는다. 이를 위해 상용 서비스용 샘플 Config 파일을 복사한다.
PHP 컴파일시 준 옵션 (--with-config-file-path=/usr/local/httpd-2.2.20/conf)에 의해 httpd 설정 디렉토리에 복사해 넣는다.

# cp /usr/local/src/php-5.3.8/php.ini-production /usr/local/httpd-2.2.20/conf

2) php.ini 수정 ( 아래 라인을 찾아 수정한다)

date.timezone = Asia/Seoul
short_open_tag = On
include_path = ".:/usr/local/php-5.3.8/lib"
extension_dir = "/usr/local/php-5.3.8/lib/php/extensions/"
expose_php = Off

3) php.ini 에 추가 ( Dynamic Extensions 섹션에 추가 )

extension=oci8.so

4) 환경 변수 수정

# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH;/usr/lib/oracle/11.2/client/lib



Finally, Start Apache Server & Testing


1. 아파치 문서 디렉토리에 테스트 페이지 생성

# vi test.php

<?

phpinfo ();

?>


2. 웹 브라우져에서 확인




3. 테스트용 소스 코드 작성

# vi testoci.php

<?php

$conn = oci_connect('hr', 'hr_password', 'mymachine.mydomain/MYDB');

$stid = oci_parse($conn, 'select table_name from user_tables');
oci_execute($stid);

echo "<table>\n";
while (($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) != false) {
echo "<tr>\n";
foreach ($row as $item) {
echo " <td>".($item !== null ? htmlentities($item, ENT_QUOTES) : "&nbsp;")."</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";

?>


4. 에러 확인

위 코드 수정후 정상 작동이 안 될 경우 php.ini의 옵션 값중 display_errors = Off를 On으로 변경해 주면 에러값이 출력된다.


Posted by 카프러브