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.6
, php7.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.6
, php7.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.6
, php7.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.6
, php7.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.
In PHP 7.3 (and upper) directive can be double (in one more places) – be aware about that.