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 a deprecated feature of PHP and 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. But because this short cut has been a feature for such a long time, it’s currently still supported for backwards compatibility.

1. Locate php.ini

Firstly, you need to locate your php.ini file. In this example, our php.ini is located in /etc/php/7.2/apache2/php.ini, however, this may be different for you depending on your PHP version. If you are unsure, please read:

2. 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

3. Nginx or Apache with PHP-FPM

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

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. The short_open_tag 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 on Twitter, Facebook and YouTube.

p.s. I increased my AdSense revenue by 68% using AI 🤖. Read my Ezoic review to find out how.

1 Star2 Stars3 Stars4 Stars5 Stars 4.67 (3 votes)

Leave a Reply

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