PHP Not Accepting <? Tag; Only Accepting <?php and <script> Tag

I am using PHP along with the latest version of Apache web-server. Only <?php and <script> tags are recognized by my LAMP setup. Many of my scripts are broken. How do I allow the <? tag also?

You need to allow the <? tag by editing the php.ini file. Using short tags should be avoided when developing applications or libraries that are meant for redistribution, or deployment on PHP servers which are not under your control, because short tags may not be supported on the target server. For portable, redistributable code, be sure not to use short tags.


Open php.ini ( /etc/php.ini or /usr/local/etc/php.ini) using a text editor such as vi/nano, enter (your must be root user to edit php.ini file):
# vi php.ini
Set short_open_tag to On:
short_open_tag = On
Save and close the file. Restart the apache web-server (centos/rhel 6.x or older):
# service httpd restart
OR (FreeBSD)
# /usr/local/etc/rc.d/apache22 restart
OR (systemd centos/rhel 7)
# systemctl restart httpd.service

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 11 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
11 comments… add one
  • B!n@ry Oct 6, 2008 @ 16:20

    Hi Vivek,

    You have a typo mistake at the following line:
    # /usr/local/etc/rc.d/apache22 restart

    I think it should be:
    # /usr/local/etc/rc.d/apache2 restart


  • 🐧 nixCraft Oct 6, 2008 @ 21:35


    Apache22 is for Apache version 2.2 under FreeBSD.


  • peko Oct 7, 2008 @ 11:41

    Don’t you have a typo here :
    “You need to all the “You need to allow” ?

  • 🐧 nixCraft Oct 7, 2008 @ 16:41


    The post has been updated.

    I appreciate your post.

  • B!n@ry Oct 9, 2008 @ 0:06

    Aha, didn’t know that Vivek, thanks for the info :)

  • Gourine Khattib Dec 2, 2012 @ 11:54

    Please help
    This is what gives me your component on the screen when I apply it with joomla 1.5.23

    nbr_selection_fields) {?>
    nbr_selection_fields){ case 1: ?> title1 ?>
    sf1 ); $i 
    vertical){// disposicao vertical ?>
    title1 ?>
    sf1 ); $i 
    title2 ?>
    title1 ?>
    	title2 ?>
    sf1 ); $i  	
    vertical){// disposicao vertical ?>
    title1 ?>
    sf1 ); $i 
    title2 ?>
    title3 ?>
    title1 ?>
    	title2 ?>
    	title3 ?>
    sf1 ); $i  		
    vertical){// disposicao vertical ?>
    title1 ?>
    sf1 ); $i 
    title2 ?>
    title3 ?>
    title4 ?>
    title1 ?>
    	title2 ?>
    	title3 ?>
    	title4 ?>
    sf1 ); $i  			
    Button "view document"
    show_downloads) echo JText::_('Downloads: ').$this->download_count;?>
    '.JText::_('This Document Type does not exist!').'
    ('.JText::_('Probably recently deleted').')' ; }?>
  • Alastair Jan 17, 2013 @ 15:00

    Well how about that… I stopped using Apache2 predominantly a long time ago except maintenance for clients and had been using lighttpd since. Regardless, I never use PHP’s short opening tag but whether someone added it into what was mainly my code or I thought I’d be really tricky/lazy, one occurrence in one script was giving me 500’s claiming mis-matched loops-brackets.

    I didn’t know something so simple could cause so much frustration…thanks for the post!!! Now I know, I’ll hit anyone that I see who thinks the three-letter acronym (of the language they use to make a living) is too much to type…

  • Paulo Jul 17, 2015 @ 13:14

    Other possible file location /etc/php5/apache2/php.ini

  • Martin Gamboa Jun 29, 2016 @ 18:45

    i’m maintaining a website and use this of shortcode and with this solve a lot of problems XD

  • Lawerence Rosano Jul 31, 2016 @ 22:48

    However, this appears to not be working. In the root directory, I’ve created an .htaccess file with just the following line, but the short open tags are still being ignored. Simply put the server admin could have completely disabled this functionality and no matter what you add you will not be able to activate it. It’s best you ask your host and save yourself the pain.

  • cablop Dec 7, 2016 @ 23:17

    Please tell people that short tags are not recommended.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum