First of all, if you need to turn on short tags on your nginx or apache based server (linux or mac or windows or any other) for just one single tag, please do yourself a favor and change the single
<? it to
However if you need it turned on for sure, then continue with the tutorial. This will turn on the short tags for all types of short codes related to php including the <?= $variabletoecho ?> too.
How to enable PHP short tags on apache and nginx server
To turn on the php short tags on apache server (on any distribution – linux, windows or mac os x) (or on any setup like lamp, xampp or mamp, etc) simply locate your php.ini file (find the one that’s practical on your server environment, os and distro etc) and uncomment or add (uncommenting means removing this sign before the line: ‘;’
If it has the value arealy make sure it says “on” and not “off”.
Another way, if php is running as apache module, specially when you don’t have access to php.ini file, you can do it via .htaccess using:
php_flag short_open_tag on
php_value short_open_tag 1
The method works on IIS too.
Note: most probably location for your php.ini is: /etc/php5/apache2/php.ini (however confirm the one specific to yours)
You can use php –ini (on command line) to locate the loaded configuration file too.
Tip: On WAMP server you can trn it on by right clicking the icon> PHP> PHP settings > short open tag and voila!
Tip: On XAMPP server goto xampp control panel > config button > PHP (pnp.ini) option
Restart your server / service after php.ini update
Don’t forget to restart your nginx or apache server after making these changes. If you know how to restart the service thats perfect too!
You can restart the php-fpm service on nginx by:
sudo service php-fpm restart
You need to include the version of php you’re using in some cases if the command php-fpm doesn’t identify your running php service. It should look something like this:
sudo service php5-fpm restart
sudo service php7.0-fpm restart
You can restart nginx from command line via:
sudo service nginx restart
(doing both above steps might be required on nginx server, let me know your feedback!)
This might help you turn on the short tags for your php code files!