Macbook Pro 사용기/MacPorts

MacPorts로 Apache + PHP5 + PostgreSQL 설치하기

向雲™ 2011. 8. 21. 09:55
오픈 소스를 쉽게 설치하기 위한 툴은 MacPorts를 이용해서 프로그램을 설치하는 방법을 알아보도록 한다. MacPorts를 설치하는 방법은 이전 Post인 아래의 Post를 참고하기 바란다.

Mac OS X Lion에서 MacPorts 설치 및 사용

설치순서로는 Apache -> PHP -> postgreSQL  순으로 설치하기로 합니다.

1. Apache 웹서버 설치


sudo port install apache2

2. PHP5 설치

sudo port install php5 +apache2 +postgresql91 + pear

Apache와 PHP5를 설치하였다면 Apache에 PHP5를 사용할 수 있도록 모듈을 추가하고 활성화시켜야 한다.

$ cd /opt/local/apache2/modules
$ sudo /opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so

모듈추가가 완료되었다면 다시 Apache의 httpd.conf의 환경파일을 수정해 주어야 한다. 아래의 노란색 글자부분을 추가 또는 수정해 주어야 한다.

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.php
</IfModule>

<IfModule mime_module>
# TypesConfig points to the file containing the list of mappings from
# filename extension to MIME-type.
#
TypesConfig conf/mime.types

#
# AddType allows you to add to or override the MIME configuration
# file specified in TypesConfig for specific file types.
#
#AddType application/x-gzip .tgz
#
# AddEncoding allows you to have certain browsers uncompress
# information on the fly. Note: Not all browsers support this.
#
#AddEncoding x-compress .Z
#AddEncoding x-gzip .gz .tgz
#
# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps


#
# AddHandler allows you to map certain file extensions to "handlers":
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
#
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
#AddHandler cgi-script .cgi

# For type maps (negotiated resources):
#AddHandler type-map var

#
# Filters allow you to process content before it is sent to the client.
#
# To parse .shtml files for server-side includes (SSI):
# (You will also need to add "Includes" to the "Options" directive.)
#
#AddType text/html .shtml
#AddOutputFilter INCLUDES .shtml
</IfModule>

# User home directories
   Include conf/extra/httpd-userdir.conf

다음으로 Apache를 시작시키기 위한 Alias를 등록하여 시작을 편리하게 할 수 있도록 한다.

$ vi ~/.profile

프로파일에 아래의 내용을 추가하고 저장하도록 한다.


 alias apache2ctl='sudo /opt/local/apache2/bin/apachectl'



3. PostgreSQL 설치

$ sudo port install postgresql91-server

위의 명령으로 PostgreSQL을 설치한다.

$ sudo mkdir -p /opt/local/var/db/postgresql90/defaultdb
$ sudo chown postgres:postgres /opt/local/var/db/postgresql90/defaultdb
$ sudo su postgres -c '/opt/local/lib/postgresql90/bin/initdb -D /opt/local/var/db/postgresql90/defaultdb'

위와 같이 3차례에 걸쳐서 명령을 실행한다. 다음으로 실제 서버를 스타트 하는 명령을 실행한다. 아래의 명령어는 2줄로 보이지만 1줄이다. 붙여서 명령을 실행시켜야 한다.

$ /opt/local/lib/postgresql90/bin/postgres -D /opt/local/var/db/postgresql90/defaultdb

위의 작업을 마치면 본격적으로 사용한 PostgreSQL 서버가 완성된다. 향후 PostgreSQL에 대해 외부에서 접근할 수 있도록 접근권한을 설정하기 위해서는 각 생성된 데이터베이스 내의 pg_hba.conf 파일에 접근권한이 있는 호스트를 등록하여야 접근이 가능하다.