{"id":3410,"date":"2017-04-02T13:25:48","date_gmt":"2017-04-02T07:55:48","guid":{"rendered":"https:\/\/www.wikitechy.com\/technology\/?p=3410"},"modified":"2017-04-02T13:25:48","modified_gmt":"2017-04-02T07:55:48","slug":"enable-php-short-tags","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/technology\/enable-php-short-tags\/","title":{"rendered":"[ Solved -10 Answers] PHP How to enable PHP short tags"},"content":{"rendered":"<p><label class=\"label label-warning\">PROBLEM:<\/label><\/p>\n<ul>\n<li>We have a web application on a Linux server which starts with <?<\/li>\n<li>we needed to copy this application to a windows environment and everything is working fine except that an SQL statement is being rendered differently.<\/li>\n<li>we don\u2019t know if this has to do with the script beginning with <?php instead of <? because we don\u2019t know from where to enable the <? from the PHP.ini so we changed it to <?php<\/li>\n<li>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.<\/li>\n<li>This way we can eliminate another possibility.<\/li>\n<\/ul>\n<p><label class=\"label label-info\">SOLUTION 1:<\/label><\/p>\n<ul>\n<li>This can be done by enabling short_open_tag in php.ini:<\/li>\n<\/ul>\n[pastacode lang=\u201dphp\u201d manual=\u201d%20short_open_tag%20%3D%20on%0A\u201d message=\u201dphp code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<ul>\n<li>If you don\u2019t have access to the php.ini you can try to enable them trough the .htaccess file but it\u2019s possible the hosting company disabled this if you are on shared hosting:<\/li>\n<\/ul>\n[pastacode lang=\u201dphp\u201d manual=\u201dphp_value%20short_open_tag%201%0A\u201d message=\u201dphp code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n[ad type=\u201dbanner\u201d]\n<ul>\n<li>For the people thinking that short_open_tags are bad practice as of php 5.4 the <?= \u2026 ?> 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<\/li>\n<\/ul>\n<p><label class=\"label label-info\">SOLUTION 2:<\/label><\/p>\n<ul>\n<li>Set\u00a0in php.ini<\/li>\n<\/ul>\n[pastacode lang=\u201dphp\u201d manual=\u201dshort_open_tag%3DOn%0A%0A\u201d message=\u201dphp code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n[ad type=\u201dbanner\u201d]\n<ul>\n<li>And restart your Apache server.<\/li>\n<\/ul>\n<p><label class=\"label label-info\">SOLUTION 3:<\/label><\/p>\n<ul>\n<li>To locate php.ini file,on comment line execute<\/li>\n<\/ul>\n[pastacode lang=\u201dphp\u201d manual=\u201dphp%20%E2%80%93ini%0A\u201d message=\u201dphp code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<p>you will get some thing like this,<\/p>\n[pastacode lang=\u201dphp\u201d manual=\u201dConfiguration%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\u201d message=\u201dphp code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<p>See 2nd line from the comment output.The file will be in the mentioned path.<\/p>\n<ul>\n<li>Open php.ini file and find short_open_tag. By default it is in off change it to on.<\/li>\n<li>Restart the server,execute this comment<\/li>\n<\/ul>\n<p>service http restart<\/p>\n<p><label class=\"label label-info\">SOLUTION 4:<\/label><\/p>\n<ul>\n<li>To set short tags to open from a Vagrant install script on Ubuntu:<\/li>\n<\/ul>\n[pastacode lang=\u201dphp\u201d manual=\u201dsed%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\u201d message=\u201dphp code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<p><label class=\"label label-info\">SOLUTION 5:<\/label><\/p>\n<ul>\n<li>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<\/li>\n<\/ul>\n[pastacode lang=\u201dphp\u201d manual=\u201d%20Go%20to%20php.ini%20and%20set%20short_open_tag%20%3D%20On%0A\u201d message=\u201dphp code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<ul>\n<li>IMPORTANT: then you must restart your php-fpm process so this can work!<\/li>\n<\/ul>\n[pastacode lang=\u201dphp\u201d manual=\u201dsudo%20service%20php-fpm%20restart%0A\u201d message=\u201dphp code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n[ad type=\u201dbanner\u201d]\n<p>and then finally restart your nginx\/http server<\/p>\n[pastacode lang=\u201dphp\u201d manual=\u201d%20%20sudo%20service%20nginx%20restart%0A\u201d message=\u201dphp code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<p><label class=\"label label-info\">SOLUTION 6:<\/label><\/p>\n<p>As simple, as that, follow the following steps:<\/p>\n<ol>\n<li>go to php.ini file<\/li>\n<li>find, \u2018short_open_tag\u2019 and set it to on,<\/li>\n<li>restart the server<\/li>\n<\/ol>\n<p>so, short_open_tag = On<\/p>\n<p><label class=\"label label-info\">SOLUTION 7:<\/label><\/p>\n<p>In CentOS 6(tested on Centos 7 too) you can\u2019t set short_open_tag in \/etc\/php.ini for php-fpm. You will have error:<\/p>\n[pastacode lang=\u201dphp\u201d manual=\u201dERROR%3A%20%5B%2Fetc%2Fphp.ini%3A159%5D%20unknown%20entry%20\u2019short_open_tag\u2019%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\u2019%2Fetc%2Fphp-fpm.conf\u2019%0AERROR%3A%20FPM%20initialization%20failed%0A\u201d message=\u201dphp code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<p>You must edit config for your site, which can found in \/etc\/php-fpm.d\/www.conf And write at end of file:<\/p>\n[pastacode lang=\u201dphp\u201d manual=\u201dphp_value%5Bshort_open_tag%5D%20%3D%20%20On%0A\u201d message=\u201dphp code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<p><label class=\"label label-info\">SOLUTION 8:<\/label><\/p>\n<p>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<\/p>\n<ol>\n<li>\/etc\/php5\/apache2\/php.ini \u2013 this is for the pages loaded through your web server (Apache)<\/li>\n<li>\/etc\/php5\/cli\/php.ini \u2013 this configuration is used when you launch your php files from command line, like: php yourscript.php \u2013 that goes for manually or cronjob executed php files directly on the server.<\/li>\n<\/ol>\n<p><label class=\"label label-info\">SOLUTION 9:<\/label><\/p>\n<p>If you are using xampp in windows then please do following<\/p>\n<p>1.Open XAMPP control panel.<\/p>\n<p>2.Click on CONFIG button.<\/p>\n<p>3.Go to PHP (php.ini) option.<\/p>\n<ul>\n<li>Find short_open_tag using ctrl+f utility<\/li>\n<\/ul>\n<p>You will found ; <b>short_open_tag<\/b><\/p>\n<ul>\n<li>kindly remove the semicolon (;) from line.<\/li>\n<\/ul>\n<p>and keep it as <b>short_open_tag<\/b><b> = on<\/b><\/p>\n<p>Finally, restart your Apache server<\/p>\n[ad type=\u201dbanner\u201d]\n<p><label class=\"label label-info\">SOLUTION 10:<\/label><\/p>\n[pastacode lang=\u201dphp\u201d manual=\u201d%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\u2013Comment%20this%20out%0A%3B%20XAMPP%20for%20Linux%20is%20currently%20old%20fashioned%0Ashort_open_tag%20%3D%20On%20%20%20%3C\u2013Uncomment%20this%0Ashareimprove%20this%20answer%0Aanswered%20Jan%209%20\u201914%20at%2011%3A38%0A\u201d message=\u201dphp code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<p>\u00a0<\/p>\n<p>\u00a0<\/p>\n<p>\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to enable PHP short tags -If you don&#8217;t have access to the php.ini you can try to enable them trough the .htaccess file<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[6310,6303,6304,6311,6308,6307,6312,6305,6309,6306],"class_list":["post-3410","post","type-post","status-publish","format-standard","hentry","category-php","tag-not-being-rendered-as-php","tag-are-php-short-tags-acceptable-to-use","tag-enable-short-open-tag-without-php-ini-file","tag-find-and-replace-php-short-tags-exclude-xml-and-in-netbeans","tag-how-to-enable-short-tags-in-iis-7-5","tag-is-it-now-safe-to-use-php-echo-short-tags","tag-issues-when-include-a-php-file-using-short-tags","tag-tags-not-working-in-php-5-3-1","tag-what-does-the-tag-mean","tag-why-are-echo-short-tags-permanently-enabled-as-of-php-5-4"],"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/3410","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/comments?post=3410"}],"version-history":[{"count":0,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/3410\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media?parent=3410"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/categories?post=3410"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/tags?post=3410"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}