Enable PHP short open tags in PHP.ini

How to enable PHP short open tag (short_open_tag)?

Last updated on

PHP short open tags is deprecated feature of PHP and is strongly discouraged. It’s been recommended for several years that you not use the short tag “short cut” and instead to use the full <?php and ?> tag combination.

With the wide spread use of XML and use of these tags by other languages, the server can become easily confused and end up parsing the wrong code in the wrong context. But because this short cut has been a feature for such a long time, it’s currently still supported for backwards compatibility, but we recommend you don’t use them.

If you want to enable short open tags anyway:

Apache

Edit the PHP config. Replace php7.2 with your own version, e.g, php5.6php7.1, etc. (Use ls /etc/php/ if you are not sure which version is installed.)

sudo nano /etc/php/7.2/apache2/php.ini

Not there? If you are using PHP FPM, php.ini might be in /etc/php/7.2/fpm/php.ini

Search for short_open_tag = (Press CTRL + W to search in nano)

Change it to:

short_open_tag = On

Save changes and close nano (Press CTRL + X and then press y and ENTER)

Restart Apache.

sudo systemctl restart apache2

If you are using PHP-FPM, you must restart that service. Replace php7.2 with your own version, e.g, php5.6php7.1, etc.

sudo service php7.2-fpm restart

Nginx

Edit the PHP config. Replace php7.2 with your own version, e.g, php5.6php7.1, etc.

sudo nano /etc/php/7.2/fpm/php.ini

Search for short_open_tag = (Press CTRL + W to search in nano)

Change it to:

short_open_tag = On

Save changes and close nano (Press CTRL + X and then press y and ENTER)

Restart PHP-FPM. Replace php7.2 with your own version, e.g, php5.6php7.1, etc.

sudo service php7.2-fpm restart

short_open_tag

This setting tells PHP whether the short form (<? ?>) of PHP’s open tag should be allowed. If you want to use PHP in combination with XML, you can disable this option in order to use <?xml ?> inline. Otherwise, you can print it with PHP, for example: <?php echo '<?xml version="1.0"?>'; ?>. Also, if disabled, you must use the long form of the PHP open tag (<?php ?>).

Let me know in the comments if this helped. Follow me @DevAnswers or read more.

1 Star2 Stars3 Stars4 Stars5 Stars 4.67 (3 votes)

Feedback

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

We use Markdown to style comments, like on Github and Reddit.
To do a line break, type two spaces after the sentence.
You can add inline code by wrapping it in backticks: `code here`

    To do an entire block of code  
    type four spaces before the line
    and it will appear in a block like this.
    <-- four empty spaces