- 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:
- 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:
- 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
- And restart your Apache server.
- To locate php.ini file,on comment line execute
you will get some thing like this,
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:
- 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
- IMPORTANT: then you must restart your php-fpm process so this can work!
and then finally restart your nginx/http server
As simple, as that, follow the following steps:
- go to php.ini file
- find, ‘short_open_tag’ and set it to on,
- 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:
You must edit config for your site, which can found in /etc/php-fpm.d/www.conf And write at end of file:
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
- /etc/php5/apache2/php.ini – this is for the pages loaded through your web server (Apache)
- /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