Allowing to Use PHP short tags in PHP7

By | April 15, 2020

If you are trying to use PHP7 for the first time, you might not know that is does not support short tags by default.

So if you are going to test the following code:

<? phpinfo(); ?>

it will not work and will be displayed as text. How to resolve this issue? There are at least 2 simple solutions:

The easiest one – always use “normal” tags:

<?php phpinfo(); ?>

Another way is to change an option in php.ini to continue using short tags (for example, if you have many files made with short tags).

Locate php.ini first. Go to command line and type

php -i | grep php.ini

You will get something like this:

[root@server ~]# php -i | grep php.ini
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini

Open php.ini file, and set the following directive:

short_open_tag = On

It should be Off by default, you need to change the value. You’re done! Save php.ini and restart your Apache/nginx to see short tags in action!

Leave a Reply

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