anon
anon

Reputation:

XAMPP problems with PHP5

I enabled PHP5 on my website and my webhost needs me to add the following to .htaccess files for PHP5 to work:

AddHandler application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml
AddType application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml

Locally, I am running XAMPP to develop code, but XAMPP does not want to work with the .htaccess file above.

I think it is an issue with XAMPP not recognizing php5 (but it does recognize php if I use "application/x-httpd-php" instead of "application/x-httpd-php5")

How do I resolve this?! I need the .htaccess files to look like above so they work with my webhost, but I need XAMPP to work locally with the same files without making changes!

Upvotes: 0

Views: 1977

Answers (3)

Steve Clay
Steve Clay

Reputation: 8781

Another simple solution: change the config file name at home. E.g. in httpd.conf:

<Directory />
    #existing stuff here...
    AccessFileName .htaccess.home
</Directory>

Now your home server will ignore your ".htaccess" files. You'll configure it with ".htaccess.home" files.

Upvotes: 0

Kornel
Kornel

Reputation: 100180

Apache has <IfDefine> directive. You can use it to hide AddType from your own server:

<IfDefine !MyServer>
AddType application/x-httpd-php5 .php5 …
…
</IfDefine>

And start apache with

apachectl -D MyServer

Upvotes: 3

Edward Z. Yang
Edward Z. Yang

Reputation: 26762

So, you're in kind of a tough place; ideally speaking your webhost should not need you to put extra gunk in your htaccess files. Not knowing XAMPP too well, I can't offer a specific solution, but I can give you some pointers:

  1. Your webhost is running a custom compiled version of PHP that uses application/x-httpd-php5; while it is totally possible to build PHP yourself or find a custom build that has the SAPI layer configured appropriately, you probably don't want to do this.

  2. Depending on how much leeway your host is giving htaccess files, it may be possible to use <IfDefine> or <IfModule> to only conditionally execute the PHP fudge code. I haven't tested, and your webhost may have disabled this functionality. Also, you will have to find an appropriate conditional to test against.

  3. My favorite answer would be to suck it up, and maintain separate htaccess files. I do this on my website; I have a .htaccess.in file which contains "global" declarations, and an htaccess.php file which generates the real .htaccess file based on configuration, etc.

Hope that helps.

Upvotes: 0

Related Questions