웹사이트 추가를 위한 사전 작업 [2/2] – Apache VirtualHost 준비

새로운 PHP 설치 방법 안내

– 현재는 https://github.com/php79/stack 스크립트로 자동 설치하는 방법을 권장하고 있습니다.
– 본 문서는 2013년도에 작성된 CentOS 6 + Apache + PHP 5.3 + MySQL 조합으로 수동 설치하는 방법에 대해 다룹니다.


웹사이트 추가를 위한 사전 작업 2회차 입니다.  (서버에 사이트가 여러개라도 1회만 진행하면 됩니다.)
– Apache public_html Directory 권한 설정
– Apache VirtualHost (가상호스트) 활성화

1. Apache public_html Directory 권한 설정

– Apache 에서 public_html 디렉토리의 Directory 권한 설정을 확인합니다.

grep '<Directory' /etc/httpd/conf/httpd.conf
#<Directory /home/*/public_html>

– /home/*/public_html 디렉토리의 권한 설정이 기본값은 비활성화되어 있습니다. 이때 아래처럼 설정 파일 마지막에 디렉토리 권한 설정을 추가하면 됩니다.

echo '
<Directory /home/*/public_html>
AllowOverride All
Order allow,deny
Allow from all
</Directory>
' >> /etc/httpd/conf/httpd.conf

– 마지막에 추가된 Directory 권한 설정을 확인합니다. 만약 다음처럼 /home/*/public_html 디렉토리에 아래에 AllowOverride All 설정이 적용되지 않았을 경우, 웹사이트에서 .htaccess 파일을 사용할 수 없게 됩니다.

tail -n7 /etc/httpd/conf/httpd.conf
<Directory /home/*/public_html>
AllowOverride All
Order allow,deny
Allow from all
</Directory>

– Apache 웹서버의 설정파일에 오류가 없는지 확인합니다.

/etc/init.d/httpd configtest
Syntax OK

2. Apache VirtualHost (가상호스트) 추가

– Apache 에서 VirtualHost 설정을 확인합니다.

grep NameVirtualHost /etc/httpd/conf/httpd.conf
#NameVirtualHost *:80

– NameVirtualHost 항목에 주석 처리(#)가 되어 있다면, 활성화를 위해 주석을 제거합니다.

sed -i 's/^#NameVirtualHost \*:80/NameVirtualHost \*:80/' /etc/httpd/conf/httpd.conf

– 다시 NameVirtualHost 항목에 확인합니다.

grep NameVirtualHost /etc/httpd/conf/httpd.conf
NameVirtualHost *:80

이상입니다.

다음 글에서는 웹사이트 추가를 위한 user, VirtualHost, MySQL DB 추가 작업을 해보겠습니다.