351

我在 Linux 服务器上有一个 Web 应用程序,它以<?

我需要将此应用程序复制到 Windows 环境中,并且一切正常,只是 SQL 语句的呈现方式不同。我不知道这是否与以开头的脚本有关,<?php而不是<?因为我不知道从哪里启用<?fromPHP.ini所以我将其更改为<?php

我知道这 2 条语句的含义应该相同,但我需要对其进行测试<?以确保应用程序完全相同。这样我就可以排除另一种可能性。

谢谢

4

21 回答 21

597

short_open_tag=On

php.ini中

并重新启动您的 Apache 服务器。

于 2010-02-02T15:45:29.353 回答
87

这可以通过在php.ini中启用short_open_tag来完成:

short_open_tag = on

如果您无权访问 php.ini,您可以尝试通过.htaccess文件启用它们,但如果您使用共享主机,托管公司可能会禁用此功能:

php_value short_open_tag 1

对于那些认为 short_open_tags从 php 5.4开始是不好的做法的人来说,无论设置如何, <?= ... ?>shorttag 都将受到支持,因此如果您可以控制服务器上的设置,就没有理由不使用它们。在此链接中还说:short_open_tag

于 2010-02-02T15:46:28.290 回答
23

这可以通过在 php.ini 中启用 short_open_tag 来完成:

1.找到php.ini文件,在注释行执行

 php --ini

你会得到这样的东西,

Configuration File (php.ini) Path: /etc
Loaded Configuration File:         /etc/php.ini
Scan for additional .ini files in: /etc/php.d
Additional .ini files parsed:      /etc/php.d/curl.ini,
/etc/php.d/fileinfo.ini,
/etc/php.d/gd.ini,
/etc/php.d/json.ini,
/etc/php.d/mcrypt.ini,
/etc/php.d/mysql.ini,
/etc/php.d/mysqli.ini,
/etc/php.d/pdo.ini,
/etc/php.d/pdo_mysql.ini,
/etc/php.d/pdo_sqlite.ini,
/etc/php.d/phar.ini,
/etc/php.d/sqlite3.ini,
/etc/php.d/zip.ini

请参阅注释输出的第二行。文件将位于上述路径中。

2.打开 php.ini 文件,找到short_open_tag. 默认情况下,off将其更改为on.

3.重启服务器,执行这条评论

service httpd restart

谢谢

于 2013-08-26T12:08:32.297 回答
18

要设置短标签以从 Ubuntu 上的 Vagrant 安装脚本打开:

sed -i "s/short_open_tag = .*/short_open_tag = On/" /etc/php5/apache2/php.ini
于 2014-01-16T02:18:58.330 回答
14

我可以看到上面所有的答案都是部分正确的。实际上,所有 21 世纪的 PHP 应用程序都将具有 FastCGI 进程管理器(php-fpm),因此一旦您将 php-info() 添加到 test.php 脚本并检查了 php.ini 的正确路径

Go to php.ini and set short_open_tag = On

重要提示:那么您必须重新启动您的 php-fpm 进程,这样才能正常工作!

sudo service php-fpm restart

然后最后重新启动你的 nginx/http 服务器

sudo service nginx restart
于 2014-07-03T11:00:41.923 回答
10

您需要打开 short_open_tags。

short_open_tag = On
于 2010-02-02T15:46:14.043 回答
10

就这么简单,请按照以下步骤操作:

  1. 转到php.ini文件
  2. 查找short_open_tag并将其设置为on

    short_open_tag = On
    
  3. 重启服务器

于 2013-02-10T11:11:00.153 回答
8

在 CentOS 6(也在 Centos 7 上测试过)你不能在 /etc/php.ini 中为 php-fpm 设置 short_open_tag。您将遇到错误:

ERROR: [/etc/php.ini:159] unknown entry 'short_open_tag'
ERROR: Unable to include /etc/php.ini from /etc/php-fpm.conf at line 159
ERROR: failed to load configuration file '/etc/php-fpm.conf'
ERROR: FPM initialization failed

您必须为您的站点编辑配置,可以在 /etc/php-fpm.d/www.conf 中找到并在文件末尾写入:

php_value[short_open_tag] =  On
于 2013-11-06T21:42:40.710 回答
7

如果您使用Ubuntuwith Apache+php5,那么在当前版本中有 2 个地方需要更改为short_open_tag = On

  1. /etc/php5/apache2/php.ini- 这适用于通过您的 Web 服务器 (Apache) 加载的页面
  2. /etc/php5/cli/php.ini- 当您从命令行启动 php 文件时使用此配置,例如:php yourscript.php- 用于手动或 cronjob 直接在服务器上执行的 php 文件。
于 2015-01-21T09:51:52.653 回答
6

如果您编辑 php.ini 文件,请记住重新启动您的服务(apache2 等)以使对 php.ini 的编辑生效

于 2011-04-27T12:54:45.437 回答
6

对于 Wamp Server 用户,有更简单的方法:您可以启用该设置,只需(左)单击 WampServer 图标一次,选择 PHP -> PHP settings -> short open tag。稍等片刻,WampServer 将自动重新启动您的 PHP 及其 Web 服务。

最初来自:http ://osticket.com/forums/showthread.php?t=3149

于 2012-09-21T15:26:17.450 回答
5
; Default Value: On
; Development Value: Off
; Production Value: Off
; http://php.net/short-open-tag
;short_open_tag=Off   <--Comment this out
; XAMPP for Linux is currently old fashioned
short_open_tag = On   <--Uncomment this
于 2014-01-09T11:38:42.843 回答
2

您可以按照以下步骤操作:

1-> 转到您的php.ini内部/etc/php/7.3/apache2或内部的PHP version文件

2-> 查找short_open_tag并将其设置为On;从开始中删除。

short_open_tag = On

3->重启服务器

sudo service apache2 restart
于 2021-05-22T20:20:48.183 回答
1

如果使用 xampp,您会注意到 php.ini 文件有两次提到 short_open_tag 。启用第二个到 short_open_tag = On 。第一个被注释掉,您可能想取消注释并编辑它,但它被第二个 short_open_tag 覆盖

于 2013-12-04T05:33:51.583 回答
1

如果您在 Windows 中使用 xampp,请执行以下操作

  1. 打开 XAMPP 控制面板。
  2. 单击配置按钮。
  3. 转到 PHP (php.ini) 选项。

使用 ctrl+f 实用程序查找 short_open_tag

你会发现;short_open_tag

请从行中删除分号(;)

并保持为short_open_tag = on

最后,重新启动您的 Apache 服务器

于 2014-11-21T09:11:33.303 回答
1
sed -i "s/short_open_tag = .*/short_open_tag = On/" /etc/php/7.2/apache2/php.ini

这适用于 ubuntu 16 上的 php7.2,与 Bradley Flood 的上述答案相同,尽管存储配置文件的目录已更改。

您还可以更改 php 字符串中的版本以匹配您当前安装的版本。

于 2018-07-18T00:56:23.793 回答
0

对于 docker 将此步骤添加到 Dockerfile

  ARG phpIniPath=/path/to/your/php.ini

  RUN sed -i -e 's/^short_open_tag\s*=.*/short_open_tag = On/' $phpIniPath  
于 2021-01-27T16:21:13.007 回答
-1

要使用 php-fpm 为特定域启用 short_open_tag,您必须编辑:

/etc/php5/fpm/pool.d/xxxxxxxxxx.conf

其中 xxxxx 是域的套接字号。

并添加: php_value[short_open_tag] = On

于 2017-03-13T10:46:28.373 回答
-1
 short_open_tag = On

php.ini 重新启动您的 Apache 服务器。

于 2018-01-11T13:24:51.170 回答
-2

我在我的 aws centos 7 实例和 php7(PHP 7.0.33 (cli) (built: Dec 6 2018 22:30:44) (NTS)) 上将 short_open_tag Off 更改为 On,但它没有反映 php 信息页面和代码。因此,我参考了可能的文档并为我的案例找到了解决方案。在 short_open_tag 之后添加一个额外的行 as asp_tags = On之后重新启动 Apache 它适用于代码,我可以正确输出

php.ini 文件

engine = On

; This directive determines whether or not PHP will recognize code between
; <? and ?> tags as PHP source which should be processed as such. It is
; generally recommended that <?php and ?> 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 = On

; Allow ASP-style <% %> tags   
; http://php.net/asp-tags
asp_tags = On
于 2019-04-26T08:57:08.807 回答
-5

在两个文件中设置andasp_tags = On然后 重新启动 apache 服务器。short_open_tag = On\apache\Apache2.2.21\bin\php.ini\bin\php\php5.3.8\php.ini

于 2012-03-14T07:20:53.773 回答