본문으로 건너뛰기

PHP의 short_open_tag 설정은 어떻게 하나요?

💡 요약 정리

  • PHP에서 <? 태그를 사용하려면 short_open_tag 옵션이 반드시 On이어야 합니다.
  • php.ini 설정 파일을 수정해 short_open_tag = On으로 변경해야 합니다.
  • 설정 변경 후 Apache를 재시작해야 적용됩니다.
  • 이 설정은 배포 환경에 따라 기본 Off로 되어 있을 수 있어 확인이 필요합니다.

1. 설치 환경

  • CentOS 5.x (64bit)
  • php-5.2.17
  • apache-2.2.23 설치위치: /home/APM/apache

2. short_open_tag 설정 방법

  • 대부분의 PHP 배포판은 기본적으로 short_open_tag = On 으로 설정되어 있지만, 간혹 Off로 설정되어 있는 배포판이 있습니다.

  • PHP를 설치한 후 phpinfo 등을 확인할 때 빈 페이지가 출력되거나, <?로 시작되는 PHP 구문이 그대로 출력되는 경우가 있습니다.

    이럴 때는 반드시 php.ini 설정에서 short_open_tag 항목을 On으로 설정해야 정상 동작합니다.

  • short_open_tagOn으로 설정하면 <?php로 시작하는 구문뿐만 아니라 <?로 시작하는 짧은 구문도 인식할 수 있게 됩니다.


3. 설정 변경 방법

[root@cafe24 htdocs]# vi /home/APM/apache/conf/php.ini
; Allow the <? tag.  Otherwise, only <?php and <script> tags are recognized.
; NOTE: Using short tags should be avoided when developing applications or
; libraries that are meant for redistribution, or deployment on PHP
; servers which are not under your control, because short tags may not
; be supported on the target server. For portable, redistributable code,
; be sure not to use short tags.

short_open_tag = On                       <-- On 으로 수정한다.

; Allow ASP-style <% %> tags.
asp_tags = Off

; The number of significant digits displayed in floating point numbers.
precision   = 12

; Enforce year 2000 compliance (will cause problems with non-compliant browsers)
y2k_compliance = On

; Output buffering allows you to send header lines (including cookies) even
; after you send body content, at the price of slowing PHP's output layer a
; bit.  You can enable output buffering during runtime by calling the output
; buffering functions.  You can also enable output buffering for all files by
; setting this directive to On.  If you wish to limit the size of the buffer
; to a certain size - you can use a maximum number of bytes instead of 'On', as
; a value for this directive (e.g., output_buffering=4096).

output_buffering = Off

변경 후 Apache를 재시작하여 적용합니다.

[root@cafe24 htdocs]# /home/APM/apache/bin/apachectl restart  <-- 아파치를 재시작 하여 적용한다