我正在build立一个在CentOS 6上运行的Apache2,PHP 5.3.3服务器。我的web应用程序使用短标签<? 和<?= 。 我似乎无法获得启用短标签。 当我运行phpinfo()我看到short_open_tag = off ,但在/etc/php.ini我有这个: short_open_tag = on (和是的,我已经重新启动服务器)。
我也尝试使用<?php ini_set('short_open_tag','1'); ?> <?php ini_set('short_open_tag','1'); ?>在页面的开头,它仍然不parsing短代码的代码。
我唯一能想到的是另一个php.ini文件正在被使用,而不是在/etc/php.ini重写。
有什么build议?
我有一个相当默认的CentOS 6.3系统与PHP 5.3.3交手,并按预期工作。 改变/etc/php.ini中short_open_tags的值并重新启动httpd服务就可以了。
PHP也读取/etc/php.d的文件,检查其中一个文件是否被覆盖。
如果你想检查其他的php.ini文件
find / -name php.ini
更多的信息,short_open_tag的值也可以在.htaccess文件中设置
php_value short_open_tag On
最有可能的是,你有eAccelerator或类似的启用。 预编译页面不处理,所以只需清除eAcceleratorcaching,或(难看)卸载eAccelerator,重新启动Apache,重新安装eAccelerator,重新启动Apache ..
还要确保
.htaccess文件包含short_open_tag指令可能是冲突的(在我的情况下,这个文件在上层目录是问题的根源) 我可以看到上面的所有答案只是部分正确的。 实际上,所有21世纪的PHP应用程序都将具有FastCGIstream程pipe理器(php-fpm),因此,一旦将php-info()添加到test.php脚本中并检查了php.ini的正确path
Go to php.ini and set short_open_tag = On
重要提示:那么你必须重新启动你的php-fpm进程,这样才能工作!
sudo service php-fpm restart
然后最后重新启动你的nginx / http服务器
sudo service nginx restart
在centos6 /etc/php.ini应该是这个地方,确保它没有在文件中多次定义。
默认情况下,在“快速参考”部分中有对标记的描述:
; short_open_tag ; Default Value: On ; Development Value: Off ; Production Value: Off
不要在那里添加标签,因为它稍后会在“语言选项”部分中设置(这会覆盖您的设置):
; 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