简体   繁体   English

PHP5的XAMPP问题

[英]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: 我在网站上启用了PHP5,并且我的虚拟主机需要我将以下内容添加到.htaccess文件中,PHP5才能正常工作:

AddHandler application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml AddHandler应用程序/ x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml
AddType application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml AddType应用程序/ 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. 在本地,我正在运行XAMPP来开发代码,但是XAMPP不想使用上面的.htaccess文件。

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") 我认为这是XAMPP无法识别php5的问题(但如果我使用“ application / x-httpd-php”而不是“ application / x-httpd-php5”,它确实可以识别php)

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! 我需要.htaccess文件看起来像上面那样,以便它们可以与我的Web主机一起使用,但是我需要XAMPP在本地使用相同的文件而无需进行更改!

Apache has <IfDefine> directive. Apache具有<IfDefine>指令。 You can use it to hide AddType from your own server: 您可以使用它从您自己的服务器中隐藏AddType

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

And start apache with 然后开始

apachectl -D MyServer

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. 理想情况下,您的网络主机不需要您在htaccess文件中添加多余内容。 Not knowing XAMPP too well, I can't offer a specific solution, but I can give you some pointers: 不太了解XAMPP,我无法提供特定的解决方案,但是我可以给您一些提示:

  1. Your webhost is running a custom compiled version of PHP that uses application/x-httpd-php5; 您的网络主机正在运行使用application / x-httpd-php5的PHP的自定义编译版本; 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. 而这是完全可能建立自己的PHP或发现有适当配置的SAPI层自定义生成,你可能希望这样做。

  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. 根据您的主机提供htaccess文件的空间,可以使用<IfDefine>或<IfModule>仅有条件地执行PHP软糖代码。 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. 我最喜欢的答案是将其吸收,并维护单独的htaccess文件。 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. 我有一个.htaccess.in文件,其中包含“全局”声明,还有一个htaccess.php文件,该文件根据配置等生成实际的.htaccess文件。

Hope that helps. 希望能有所帮助。

Another simple solution: change the config file name at home. 另一个简单的解决方案:在家更改配置文件名 Eg in httpd.conf: 例如在httpd.conf中:

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

Now your home server will ignore your ".htaccess" files. 现在您的家庭服务器将忽略您的“ .htaccess”文件。 You'll configure it with ".htaccess.home" files. 您将使用“ .htaccess.home”文件对其进行配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM