• We have a web application on a Linux server which starts with <?
  • we needed to copy this application to a windows environment and everything is working fine except that an SQL statement is being rendered differently.
  • we don’t know if this has to do with the script beginning with <?php instead of <? because we don’t know from where to enable the <? from the PHP.ini so we changed it to <?php
  • we know that these 2 statements are supposed to mean the same but we need to test it with <? in order to ensure that the application is exactly the same.
  • This way we can eliminate another possibility.

  • This can be done by enabling short_open_tag in php.ini:
[pastacode lang=”php” manual=”%20short_open_tag%20%3D%20on%0A” message=”php code” highlight=”” provider=”manual”/]
  • If you don’t have access to the php.ini you can try to enable them trough the .htaccess file but it’s possible the hosting company disabled this if you are on shared hosting:
[pastacode lang=”php” manual=”php_value%20short_open_tag%201%0A” message=”php code” highlight=”” provider=”manual”/] [ad type=”banner”]
  • For the people thinking that short_open_tags are bad practice as of php 5.4 the <?= … ?> short tag will supported everywhere, regardless of the settings so there is no reason not to use them if you can control the settings on the server. Also said in this link: short_open_tag

  • Set in php.ini
[pastacode lang=”php” manual=”short_open_tag%3DOn%0A%0A” message=”php code” highlight=”” provider=”manual”/] [ad type=”banner”]
  • And restart your Apache server.

  • To locate php.ini file,on comment line execute
[pastacode lang=”php” manual=”php%20%E2%80%93ini%0A” message=”php code” highlight=”” provider=”manual”/]

you will get some thing like this,

[pastacode lang=”php” manual=”Configuration%20File%20(php.ini)%20Path%3A%20%2Fetc%0ALoaded%20Configuration%20File%3A%20%20%20%20%20%20%20%20%20%2Fetc%2Fphp.ini%0AScan%20for%20additional%20.ini%20files%20in%3A%20%2Fetc%2Fphp.d%0AAdditional%20.ini%20files%20parsed%3A%20%20%20%20%20%20%2Fetc%2Fphp.d%2Fcurl.ini%2C%0A%2Fetc%2Fphp.d%2Ffileinfo.ini%2C%0A%2Fetc%2Fphp.d%2Fgd.ini%2C%0A%2Fetc%2Fphp.d%2Fjson.ini%2C%0A%2Fetc%2Fphp.d%2Fmcrypt.ini%2C%0A%2Fetc%2Fphp.d%2Fmysql.ini%2C%0A%2Fetc%2Fphp.d%2Fmysqli.ini%2C%0A%2Fetc%2Fphp.d%2Fpdo.ini%2C%0A%2Fetc%2Fphp.d%2Fpdo_mysql.ini%2C%0A%2Fetc%2Fphp.d%2Fpdo_sqlite.ini%2C%0A%2Fetc%2Fphp.d%2Fphar.ini%2C%0A%2Fetc%2Fphp.d%2Fsqlite3.ini%2C%0A%2Fetc%2Fphp.d%2Fzip.ini%0A” message=”php code” highlight=”” provider=”manual”/]

See 2nd line from the comment output.The file will be in the mentioned path.

  • Open php.ini file and find short_open_tag. By default it is in off change it to on.
  • Restart the server,execute this comment

service http restart

  • To set short tags to open from a Vagrant install script on Ubuntu:
[pastacode lang=”php” manual=”sed%20-i%20%22s%2Fshort_open_tag%20%3D%20.*%2Fshort_open_tag%20%3D%20On%2F%22%20%2Fetc%2Fphp5%2Fapache2%2Fphp.ini%0A” message=”php code” highlight=”” provider=”manual”/]

  • 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
[pastacode lang=”php” manual=”%20Go%20to%20php.ini%20and%20set%20short_open_tag%20%3D%20On%0A” message=”php code” highlight=”” provider=”manual”/]
  • IMPORTANT: then you must restart your php-fpm process so this can work!
[pastacode lang=”php” manual=”sudo%20service%20php-fpm%20restart%0A” message=”php code” highlight=”” provider=”manual”/] [ad type=”banner”]

and then finally restart your nginx/http server

[pastacode lang=”php” manual=”%20%20sudo%20service%20nginx%20restart%0A” message=”php code” highlight=”” provider=”manual”/]

As simple, as that, follow the following steps:

  1. go to php.ini file
  2. find, ‘short_open_tag’ and set it to on,
  3. restart the server

so, short_open_tag = On

In CentOS 6(tested on Centos 7 too) you can’t set short_open_tag in /etc/php.ini for php-fpm. You will have error:

[pastacode lang=”php” manual=”ERROR%3A%20%5B%2Fetc%2Fphp.ini%3A159%5D%20unknown%20entry%20’short_open_tag’%0AERROR%3A%20Unable%20to%20include%20%2Fetc%2Fphp.ini%20from%20%2Fetc%2Fphp-fpm.conf%20at%20line%20159%0AERROR%3A%20failed%20to%20load%20configuration%20file%20’%2Fetc%2Fphp-fpm.conf’%0AERROR%3A%20FPM%20initialization%20failed%0A” message=”php code” highlight=”” provider=”manual”/]

You must edit config for your site, which can found in /etc/php-fpm.d/www.conf And write at end of file:

[pastacode lang=”php” manual=”php_value%5Bshort_open_tag%5D%20%3D%20%20On%0A” message=”php code” highlight=”” provider=”manual”/]

If you are using Ubuntu with Apache+php5, then on current versions there are 2 places where you need to change to short_open_tag = On

  1. /etc/php5/apache2/php.ini – this is for the pages loaded through your web server (Apache)
  2. /etc/php5/cli/php.ini – this configuration is used when you launch your php files from command line, like: php yourscript.php – that goes for manually or cronjob executed php files directly on the server.

If you are using xampp in windows then please do following

1.Open XAMPP control panel.

2.Click on CONFIG button.

3.Go to PHP (php.ini) option.

  • Find short_open_tag using ctrl+f utility

You will found ; short_open_tag

  • kindly remove the semicolon (;) from line.

and keep it as short_open_tag = on

Finally, restart your Apache server

[ad type=”banner”]

[pastacode lang=”php” manual=”%3B%20Default%20Value%3A%20On%0A%3B%20Development%20Value%3A%20Off%0A%3B%20Production%20Value%3A%20Off%0A%3B%20http%3A%2F%2Fphp.net%2Fshort-open-tag%0A%3Bshort_open_tag%3DOff%20%20%20%3C–Comment%20this%20out%0A%3B%20XAMPP%20for%20Linux%20is%20currently%20old%20fashioned%0Ashort_open_tag%20%3D%20On%20%20%20%3C–Uncomment%20this%0Ashareimprove%20this%20answer%0Aanswered%20Jan%209%20’14%20at%2011%3A38%0A” message=”php code” highlight=”” provider=”manual”/]

 

 

 

Categorized in: