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

Posted on in Categories , , , , , , , , , , last updated June 29, 2016

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.

Configuration

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

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

11 comment

  1. [email protected] says:

    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

    regards,

  2. [email protected],

    Apache22 is for Apache version 2.2 under FreeBSD.

    HTH

  3. [email protected] says:

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

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

    pgtitle?>
    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').')' ; }?>
    
  5. 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…

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

Leave a Comment