2011-04-27

CentOS+Apache+PHP+CodeIgniter+PGSQL

예전에 Debian+Apache+PHP+CodeIgniter+MySQL 를 올린 적이 있다. 이번엔 CentOS에서 설치하는 법도 한 번 알아보도록 하자. DBMS 도 MySQL 이 아닌 PostgreSQL을 설치한다.


  • 아래의 설치방법은 CentOS 5.6 과 Scientific Linux 5.5 에서 적용 가능하다.

기본 프로그램 설치

# yum groupinstall "Development Tools"
# yum install git htop ntp

Apache + mod_php 설치

# yum install php

PostgreSQL 8.4.7 설치

  • 설치
    # yum install postgresql84 postgresql84-devel postgresql84-libs postgresql84-contrib postgresql84-server
  • DB 초기화
    # service postgresql initdb
    /var/lib/pgsql/data 에 초기화된 파일들이 생성된다.
  • 설정파일 위치 : /var/lib/pgsql/data
  • 시스템 부팅시 자동으로 실행되게 하려면, ntsysv 에서 postgresql 을 체크해주어야 한다.

사용자, DB 생성

  • 사용자, DB 생성
    # su - postgres
    # psql
    postgres=# CREATE USER 아이디 WITH PASSWORD '비밀번호';
    postgres=# CREATE DATABASE 디비이름 WITH ENCODING='utf-8' OWNER 아이디;
  • 계정으로 로그인할 수 있도록 연결설정
    # su -
    # cd /var/lib/pgsql/data/
    # vi pg_hba.conf
    모두 주석으로 막고 아래만 남김
    host    all         all         0.0.0.0           0.0.0.0           password
    local   all         postgres                                        trust
    local   all         all                                             password
    
    # vi postgresql.conf
    listen_addresses = '*'
    
    # /etc/init.d/postgresql restart
    # psql -d 디비이름 -U 아이디 -W

프로젝트 생성

$ mkdir -p /opt/project/프로젝트명/web
$ cd /opt/project/프로젝트명/web

Apache 설정

# cd /etc/httpd/conf
# vi httpd.conf
NameVirtualHost *:80

<VirtualHost *:80>
    ServerName 자신의도메인URL
    DocumentRoot /opt/project/프로젝트명/web
    <Directory />
        Options Indexes FollowSymLinks
        AllowOverride All
    </Directory>
</VirtualHost>

# /etc/init.d/httpd restart

CodeIgniter 설치

  1. http://codeigniter.com/download.php 에서 CodeIgniter_2.0.2.zip 다운로드한다.
  2. 압축을 풀고 /opt/project/프로젝트명/web 에 업로드 한다.
  3. /opt/project/프로젝트명/web 에.htaccess를 작성한다.
    RewriteEngine on
    RewriteCond $1 !^(index\.php|images|robots\.txt)
    RewriteRule ^(.*)$ /index.php/$1 [L]
  4. system/application/config/config.php 파일을 열어 기반url(base URL)을 세팅한다.
    $config['base_url'] = "자신의도메인URL";
  5. 데이터베이스를 사용한다면 application/config/database.php 파일을 열어서 데이터베이스 정보를 세팅한다.
    $db['default']['hostname'] = "localhost";
    $db['default']['username'] = "아이디";
    $db['default']['password'] = "비밀번호";
    $db['default']['database'] = "디비이름";
    $db['default']['dbdriver'] = "postgre";
  6. 마지막으로 보안을 위해서 system 디렉토리를 sys로 변경하고, index.php 의 $system_folder 변수를 변경해준다.
    $system_path = "sys";
    sys 대신 자신이 원하는 다른 것으로 변경하길 바란다.
  7. 웹브라우저에서 자신의도메인URL 로 접속해본다.

댓글 없음:

댓글 쓰기