0

I've been hosting my site coded in PHP on one shared server. The site worked just fine. So recently I migrated it to a new web hosting service, after which the server started literally outputting contents of the php scripts/files to the web browser!

The .htaccess file was configured as such (to parse htm files as php):

<Files index.htm>
    AddType application/x-httpd-php .htm
</Files>

Any idea why it's not parsing them?

PS. I'm also curious how to prevent outputting of PHP scripts to the client browser in plain text in the future?

c00000fd
  • 20,994
  • 29
  • 177
  • 400
  • 1
    Check the server configuration on your new hosting service; either they don't support PHP, or they don't allow you to change the configuration in htaccess. – Elliott Frisch Oct 13 '14 at 17:20
  • `Allow Override` is not setup in such a way to give your user the ability to modify the `AddType` method, or the usage of an `.htaccess` is strictly prohibited. Also, while it shouldnt' be necessary, you can perform `AddHandler application/x-httpd-php .php`. – Ohgodwhy Oct 13 '14 at 17:24
  • @ElliottFrisch: Yes, it supports running PHP files (if they have `.php` extension.) – c00000fd Oct 13 '14 at 17:35

5 Answers5

0

Verify that your new web hosting service allows you to use .htaccess files. Some hosting companies disable that functionality for safety concerns.

Sylvain
  • 61
  • 7
0

Ensure that http.conf include the PHP MIME type. ie, make sure you have this line and thatit's not commented out:

AddType application/x-httpd-php .php

Also make sure AllowOverride is enabled

AllowOverride All

I wrestled a bear once.
  • 22,983
  • 19
  • 69
  • 116
0

Maybe your new hosting provider does not allow short open tags and you use them ?

If you put <? echo "Hello world"; ?> in hello.php the file is parsed or not ? If its not, try to replace <? with <?php and try again.

Alexandru Guzinschi
  • 5,675
  • 1
  • 29
  • 40
0
  1. Unless you want to parse only the index.htm you should not put the AddType directive inside the <Files index.htm>...</Files> directive.

  2. What you actually need is AddHandler not AddType.
    Place just this line in you .htaccess:

    AddHandler application/x-httpd-php .htm .html
    

    Note: application/x-httpd-php is both a content-type as well as a handler name for PHP

kums
  • 2,661
  • 2
  • 13
  • 16
  • Although yes, I do need it for the `index.htm` file only, I tried it the way you put it and it didn't work. It still output PHP script as plain text. – c00000fd Oct 14 '14 at 03:19
0

Just got this fixed. My .htaccess file should've been this:

<Files index.htm>
    AddType application/x-httpd-php52 .htm
</Files>

I didn't realize it had to be so specific.

c00000fd
  • 20,994
  • 29
  • 177
  • 400