1. 개요

얼마전 맑 님 께서 yum 을 이용한 php 설치를 설명해 주셔서 큰 도움 되었습니다. 오늘은 컴파일을 이용한 설치를 설명드릴까 합니다.

2. 설치

2-1. 소스 다운로드

php 소스는 php.net 사이트에서 다운로드 하시면 됩니다. 저는 5.5.11 을 선택했습니다.

(http://kr1.php.net/downloads.php)

2-2. configure

./configure \
  --prefix=/home/php5 \
  --with-apxs2=/home/apache22/bin/apxs

Configuring extensions
checking size of long... (cached) 8
checking size of int... (cached) 4
checking for int32_t... yes
checking for uint32_t... yes
checking for sys/types.h... (cached) yes
checking for inttypes.h... (cached) yes
checking for stdint.h... (cached) yes
checking for string.h... (cached) yes
checking for stdlib.h... (cached) yes
checking for strtoll... yes
checking for atoll... yes
checking for strftime... (cached) yes
checking which regex library to use... php
checking whether to enable LIBXML support... yes
checking libxml2 install dir... no
checking for xml2-config path...
configure: error: xml2-config not found. Please check your libxml2 installation.

역시 난관이 존재합니다.

결론은 libxml2-devel 을 설치해야 합니다. libxml2 만으로는 안됩니다.

물론 libxml2 만 설치해도 잘 되겠습니다만.. 아래처럼.

libxml2 2015 03 05 10.08.59

참고로 libxml2 는 xml parsing 을 위한 도구입니다.  devel 버전은 보통 header 와 library 가 포함된 버전이지요.

libxml2 devel 2015 03 05 11.34.31

그 후에  다시 한 번 configure 를 돌려보세요. 

......
Generating files configure: creating ./config.status creating main/internal_functions.c creating main/internal_functions_cli.c +--------------------------------------------------------------------+ | License: | | This software is subject to the PHP License, available in this | | distribution in the file LICENSE. By continuing this installation | | process, you are bound by the terms of this license agreement. | | If you do not agree with the terms of this license, you must abort | | the installation process at this point. | +--------------------------------------------------------------------+ Thank you for using PHP. config.status: creating php5.spec config.status: creating main/build-defs.h config.status: creating scripts/phpize config.status: creating scripts/man1/phpize.1 config.status: creating scripts/php-config config.status: creating scripts/man1/php-config.1 config.status: creating sapi/cli/php.1 config.status: creating sapi/cgi/php-cgi.1 config.status: creating ext/phar/phar.1 config.status: creating ext/phar/phar.phar.1 config.status: creating main/php_config.h config.status: executing default commands

2-3. make

저는 테스트 환경이 열악해서인지 시간은 좀 걸렸습니다.

특이사항이 없다면 다음과 같이 정상 종료될 듯 합니다.

......

Generating phar.php Generating phar.phar PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled. clicommand.inc invertedregexiterator.inc directorygraphiterator.inc pharcommand.inc directorytreeiterator.inc phar.inc Build complete. Don't forget to run 'make test'.

2-4. make install

역시 특이사항이 없다면 다음과 같이 끝나게 됩니다.

[PEAR] Archive_Tar    - installed: 1.3.11
[PEAR] Console_Getopt - installed: 1.3.1
warning: pear/PEAR requires package "pear/Structures_Graph" (recommended version 1.0.4)
warning: pear/PEAR requires package "pear/XML_Util" (recommended version 1.2.1)
[PEAR] PEAR           - installed: 1.9.4
Wrote PEAR system config file at: /home/php5/etc/pear.conf
You may want to add: /home/php5/lib/php to your php.ini include_path
[PEAR] Structures_Graph- installed: 1.0.4
[PEAR] XML_Util       - installed: 1.2.1
/Downloads/php/php-5.5.11/build/shtool install -c ext/phar/phar.phar /home/php5/bin
ln -s -f /home/php5/bin/phar.phar /home/php5/bin/phar
Installing PDO headers:          /home/php5/include/php/ext/pdo/

2-5. Apache HTTP Server 설정

Apache 의 httpd.conf 에 아래 내용을 추가해야 합니다.

# PHP settings
LoadModule php5_module  modules/libphp5.so
AddType application/x-httpd-php .php

2-6. php.ini

만일 특정 위치에서 php.ini 파일을 관리하고 싶다면 configure 시에 다음 옵션을 추가해야 합니다.

./configure \
  --prefix=/home/php5 \
  --with-config-file-path=/home/php5/conf

하지만 /home/php5/conf 아래에 자동으로 php.ini 가 생성되지는 않습니다. 

php.ini 파일은 php 설치 파일 내의 다음 파일들 중 선택하여 복사하면 됩니다.

  • php.ini-production
  • php.ini-development

그런데 위 두 파일 중 어느 파일이라도 php.ini 로 설정하게 되면 <? ?> 와 같은 태그는 더 이상 사용할 수 없게 됩니다.

; This directive determines whether or not PHP will recognize code between
;  tags as PHP source which should be processed as such. It is
; generally recommended that  should be used and that this feature
; should be disabled, as enabling it may result in issues when generating XML
; documents, however this remains supported for backward compatibility reasons.
; Note that this directive does not control the <?= shorthand tag, which can be
; used regardless of this directive.
; Default Value: On
; Development Value: Off
; Production Value: Off
; http://php.net/short-open-tag
short_open_tag = Off

short_open_tag 를 On 으로 설정해야 <? ?> 태그를 사용할 수 있습니다.