apache 扩展 PHP5 不在 XAMPP 中解析

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/460589/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 17:10:05  来源:igfitidea点击:

Extension PHP5 does not parse in XAMPP

phpapachexampp

提问by Tomasz Smykowski

I've installed XAMPP Apache server and put my website into htdocs. I've started Apache server. On my website I've got files with extension PHP and with extension PHP5.The difference is that when I type in into browser localhost/file.php - I see a parsed website.

我已经安装了 XAMPP Apache 服务器并将我的网站放入 htdocs。我已经启动了 Apache 服务器。在我的网站上,我有扩展名为 PHP 的文件和扩展名为 PHP5 的文件。不同之处在于,当我在浏览器中输入 localhost/file.php 时,我会看到一个已解析的网站。

But when I type localhost/file.php5 (i have this file on server), than browser asks me if I want to download or open this file. And if I choose open than I see PHP code of file.php5!

但是当我输入 localhost/file.php5(我在服务器上有这个文件)时,浏览器会问我是否要下载或打开这个文件。如果我选择打开,我会看到 file.php5 的 PHP 代码!

I've looked into configuration, so:

我已经研究了配置,所以:

  1. I dont have htaccess file
  2. PHPINFO() shows PHP 5
  3. c:\xampp\apache\conf\extra\httpd-xampp is included into configuration and has this on the beginning:

    AddType application/x-httpd-php-source .phps

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

  1. 我没有 htaccess 文件
  2. PHPINFO() 显示 PHP 5
  3. c:\xampp\apache\conf\extra\httpd-xampp 包含在配置中,并在开头有这个:

    添加类型应用程序/x-httpd-php-source .phps

    AddType 应用程序/x-httpd-php .php .php5 .php4 .php3 .phtml .phpt

I've tried also to put:

我也试过把:

AddHandler php5-script .php5
AddType text/html .php5

Into httpd.conf, but it does not work for me (no changes).

进入 httpd.conf,但它对我不起作用(没有变化)。

Could you please help me fixing it? I would like to have php5 and php extension files to be opened with php5 parser.

你能帮我修一下吗?我想用 php5 解析器打开 php5 和 php 扩展文件。

回答by

  1. Follow the path c:/xampp/apache/conf/extra/httpd-xammp

    Open httpd-xammp

  2. Find the area of the text that resembles this:

    <FilesMatch "\.php$"> 
       SetHandler application/x-httpd-php   
    </FilesMatch>
    <FilesMatch "\.phps$">
        SetHandler application/x-httpd-php-source
    </FilesMatch>
    
  3. replace the top line of the code with the following:

    <FilesMatch "\.php$|\.php5$|\.php4$|\.php3$|\.phtml$|\.phpt$"> 
    
  4. so the text resembles the following:

    <FilesMatch "\.php$|\.php5$|\.php4$|\.php3$|\.phtml$|\.phpt$"> 
        SetHandler application/x-httpd-php  
    </FilesMatch>
    <FilesMatch "\.phps$">
        SetHandler application/x-httpd-php-source
    </FilesMatch>
    
  1. 按照路径 c:/xampp/apache/conf/extra/httpd-xammp

    打开 httpd-xammp

  2. 找到与此类似的文本区域:

    <FilesMatch "\.php$"> 
       SetHandler application/x-httpd-php   
    </FilesMatch>
    <FilesMatch "\.phps$">
        SetHandler application/x-httpd-php-source
    </FilesMatch>
    
  3. 将代码的第一行替换为以下内容:

    <FilesMatch "\.php$|\.php5$|\.php4$|\.php3$|\.phtml$|\.phpt$"> 
    
  4. 所以文本类似于以下内容:

    <FilesMatch "\.php$|\.php5$|\.php4$|\.php3$|\.phtml$|\.phpt$"> 
        SetHandler application/x-httpd-php  
    </FilesMatch>
    <FilesMatch "\.phps$">
        SetHandler application/x-httpd-php-source
    </FilesMatch>
    

That worked for me.

那对我有用。

Good luck..

祝你好运..

回答by Grey Panther

XAMPP passes by default files with the following extensions to PHP: .php .php5.php4 .php3 .phtml .phpt (this was tested with XAMPP Lite 1.6.8).

默认情况下,XAMPP 将具有以下扩展名的文件传递给 PHP: .php .php5.php4 .php3 .phtml .phpt(已使用 XAMPP Lite 1.6.8 进行了测试)。

My suggestion would be to remove the "AddType text/html .php5" line from the XAMPP configuration. Alternatively, use a clean install of XAMPP and look at the differences (with something like WinMerge).

我的建议是从 XAMPP 配置中删除“AddType text/html .php5”行。或者,使用全新安装的 XAMPP 并查看差异(使用WinMerge 之类的东西)。

回答by Tom of Helatrobus

I had to figure out how to do this again when I switched to an Ubuntu OS. The file that needs to be modified is called php5.conf.

当我切换到 Ubuntu 操作系统时,我不得不弄清楚如何再次执行此操作。需要修改的文件称为php5.conf.

I installed apache 2, php5, phpmyadmin, mysql-server and rapache with the synaptic package manager (system> administration> synaptic package manager) and did not use XAMPP. If you have already installed XAMPP then the paths to php5.confwill be different, likely somewhere in the /opt/lamppfile.

我使用突触包管理器(系统 > 管理 > 突触包管理器)安装了 apache 2、php5、phpmyadmin、mysql-server 和 rapache,但没有使用 XAMPP。如果您已经安装了 XAMPP,那么路径php5.conf会有所不同,可能在/opt/lampp文件的某处。

With my install, the path to it is /etc/apache2/mods-avaible/php5.conf. Before it can be modified you must use the terminal to change the permissions to allow you to write to it. To get to it, open the terminal and type :

通过我的安装,它的路径是/etc/apache2/mods-avaible/php5.conf. 在可以修改它之前,您必须使用终端更改权限以允许您对其进行写入。要获得它,请打开终端并输入:

cd /etc/apache2/mods-available

and then line that changes the permissions:

然后更改权限的行:

sudo chmod a+w php5.conf

You can type the following to make sure the permissions have been changed:

您可以键入以下内容以确保权限已更改:

ls -l

You should see a long list of files with the permission notions. The line for php5.confshould look like this (with the exception of the date and time):

您应该会看到一长串带有权限概念的文件。for 行php5.conf应如下所示(日期和时间除外):

-rw-rw-rw- 1 root root  139 2009-12-06 22:35 php5.conf

This means everyone has read and write permissions. You can change the permissions back when you get done if you want. For now proceed to make the changes you need by typing:

这意味着每个人都有读写权限。如果需要,您可以在完成后更改权限。现在,通过键入以下内容继续进行所需的更改:

nano php5.conf

This opens the file in a kind of text editor. What you should see is this:

这会在一种文本编辑器中打开文件。你应该看到的是:

<IfModule mod_php5.c>
AddType application/x-httpd-php .php .phtml .php3
AddType application/x-httpd-php-source .phps
</IfModule>

Change the text to read as follows:

将文本更改为如下所示:

<IfModule mod_php5.c>
AddType application/x-httpd-php .php .phtml .php3 .php5
AddType application/x-httpd-php-source .phps
</IfModule>

Adding the .php5to after the first AddTypecommand.

.php5在第一个AddType命令之后添加to 。

Press ctrl+xto exit and y to save changes. Then restart the computer. And then your files with the .php5extensions should work!

ctrl+x退出,按y 保存更改。然后重新启动计算机。然后带有.php5扩展名的文件应该可以工作!

I can't believe that took me hours to figure out! Good luck!

我简直不敢相信我花了好几个小时才弄明白!祝你好运!

回答by Cody Caughlan

Adding:

添加:

AddType application/x-httpd-php .php .php5

worked for me under OS X and Apache 2.2.10, I cannot imagine it being different on XAMPP. I would undo all of your other changes/modifications to httpd.conf and then only have:

在 OS X 和 Apache 2.2.10 下对我来说有效,我无法想象它在 XAMPP 上会有所不同。我会撤消您对 httpd.conf 的所有其他更改/修改,然后只有:

LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php .php5

Then restart apache. Get rid of the AddHandler, the AddType, etc.

然后重启apache。去掉 AddHandler、AddType 等。