3

I'm setting up an Apache2, PHP 5.3.3 server running on CentOS 6. My web application uses the short tags <? and <?=. I can't seem to get the short tags enabled. When I run phpinfo() I see short_open_tag = off, however in /etc/php.ini I have this: short_open_tag = on (and yes I've restarted the server).

I've also tried using <?php ini_set('short_open_tag','1'); ?> at the start of a page and it still doesn't parse code in short tags.

The only thing I can think of is there's another php.ini file somewhere that is being used instead of, or overriding the one at /etc/php.ini.

Any advice?

2
  • For completeness would you mind letting us know what the problem was ?
    – user9517
    Sep 3, 2012 at 20:31
  • You can't fix the web application? Sep 3, 2012 at 20:54

5 Answers 5

2

I have a fairly default CentOS 6.3 system with PHP 5.3.3 to hand and it works as expected. Changing the value of short_open_tags in /etc/php.ini and restarting the httpd service just works.

PHP also reads the files in /etc/php.d so check that it's not being overridden in one of them.

If you want to check for other php.ini files then

find / -name php.ini 

A bit more information, the value of short_open_tag can be set in a .htaccess file too

php_value short_open_tag On
2

Most likely, you have eAccelerator or something similar enabled. Pre-compiled pages are not processed, so just clear eAccelerator cache, or (ugly) uninstall eAccelerator, restart Apache, re-install eAccelerator, restart Apache..

1

Make sure also that

  • no .htaccess file on the way to your script contains short_open_tag directive which might be conflicting (in my case this file in upper level directory was the source of problem)
1

I can see all answers above are partially correct only. In reality all 21st Century PHP apps will have FastCGI Process Manager(php-fpm) so once you have added php-info() into your test.php script and checked the correct path for php.ini

Go to php.ini and set short_open_tag = On

IMPORTANT: then you must restart your php-fpm process so this can work!

sudo service php-fpm restart

and then finally restart your nginx/http server

sudo service nginx restart
0

on centos6 /etc/php.ini should be the place, make sure it is not defined multiple times in the file.

By default, there is the description of tag in a "Quick Reference" section:

; short_open_tag
;   Default Value: On
;   Development Value: Off
;   Production Value: Off

don't add the tag there as it is set later on in a "Language Options" section (which would overwrite your setting):

; This directive determines whether or not PHP will recognize code between
; <? and ?> tags as PHP source which should be processed as such. It's been
; recommended for several years that you not use the short tag "short cut" and
; instead to use the full <?php and ?> tag combination. With the wide spread use
; of XML and use of these tags by other languages, the server can become easily
; confused and end up parsing the wrong code in the wrong context. But because
; this short cut has been a feature for such a long time, it's currently still
; supported for backwards compatibility, but we recommend you don't use them.
; Default Value: On
; Development Value: Off
; Production Value: Off
; http://www.php.net/manual/en/ini.core.php#ini.short-open-tag
short_open_tag = Off

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .