user1032531
user1032531

Reputation: 26331

Enable PHP short tags using .htaccess

I have Apache set up on my own Centos server with several virtual web servers, and I wish to enable PHP short tags for only one of those web servers which is located at /var/www/ostickets/html. I can successfully enable short tags by adding short_open_tag=On to php.ini, however, I don't wish to globally do so, but only the one site. I've tried the following, however, nothing is displayed. I've looked at various logs, and cannot detect any errors. Is it possible that I inadvertently disabled the ability to do so and if so how do I allow it (reference "If you don't have access to the php.ini you can try to enable them trough the .htaccess file but it's possible the hosting company disabled this if you are on shared hosting:").

[root@vps html]# pwd
/var/www/ostickets/html
[root@vps html]# ls -la .hta*
-rw-r--r-- 1 root root 60 Oct  1 07:38 .htaccess
[root@vps html]# cat .htaccess
# php_flag short_open_tag on

php_value short_open_tag 1



[root@vps html]# cat test.php
<? echo('Hello World');?>
[root@vps html]#

Upvotes: 4

Views: 10019

Answers (2)

Koryonik
Koryonik

Reputation: 2768

Have you Apache directive AllowOverride All configured for this directory ?

Upvotes: 4

Krishnadas PC
Krishnadas PC

Reputation: 6539

Sometimes when we don't have access to modify configurations on server like in php.ini file and we still need to enable short tags for our php code. We can do it by .htaccess file. If you have not created any .htaccess file yet, create one in root directory of your website and add

php_value short_open_tag 1

That's it for .htaccess file.

Now if you want to enable that using php.ini and if you can...

just set

 short_open_tag=On

in php.ini at server and you are done..

If still it is not enabled contact your hosting support.

Upvotes: 2

Related Questions