+44 (791) 5698 086

Enable PHP short tags on nginx and apache

enable php short tag on nginxFirst 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 <?php

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: ‘;’

short_open_tag=on

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

or

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

Update:

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!

4 Responses to Enable PHP short tags on nginx and apache

  1. Hari KT

    In ubuntu 15.10 + I noticed it is `sudo service php5-fpm restart` .

    Thank you.

    • Nabtron

      Thanks for updating. Yes probably we have to mention the version of the php we’re using too in the command.

  2. Luke West

    If you’re running php 7.0 and getting “php-fpm: unrecognized service”

    Try running:

    service php7.0-fpm restart

    instead.

    Had my stumped for a minute or so.

    • Nabtron

      Thanks for updating Luke! I hope this really helps anyone else who’s unable to restart php-fpm via the above command as they’re using some specific version of it!

Leave a Reply

Your email address will not be published. Required fields are marked *

Who are we?

Nabtron team includes web, desktop software and mobile apps developers along with SEO professionals.

We are available 24 hours, 7 days a week. Contact us now for anything you need!

Join our mailing list

Lets become friend :) What's your name & email?