我们使用PHP 7.0运行XAMPP,因为我们的新产品需要PHP 7。
但也有一些旧的项目使用mysql_connect等函数。这些在PHP 7.0中被删除。
那么,是否有一种方法可以轻松地在XAMPP中更改PHP版本?
注意:请不要建议将旧项目升级到与新版本兼容,因为我无法做到这一点 这些决定是我作为开发人员(只是一名员工)无法得到的。
我们使用PHP 7.0运行XAMPP,因为我们的新产品需要PHP 7。
但也有一些旧的项目使用mysql_connect等函数。这些在PHP 7.0中被删除。
那么,是否有一种方法可以轻松地在XAMPP中更改PHP版本?
注意:请不要建议将旧项目升级到与新版本兼容,因为我无法做到这一点 这些决定是我作为开发人员(只是一名员工)无法得到的。
当前回答
我知道这是旧的帖子,但我想分享有一个库仍然运行mysql_connect()在PHP 7。 它通过覆盖实际函数来工作(mysql_connect()被工作在这个库上的mysqli_connect()覆盖)。
我从这个视频https://www.youtube.com/watch?v=Eqd-jJu4sQ4中找到的
希望能有所帮助
其他回答
你可以像我一样下载并安装两个不同的xampps:(第一个是php7,第二个是php5)
如果你不想这样做,我建议你使用wamp并像这里显示的那样更改版本。
你可以下载你需要的任何版本的PHP,并把它们放在自己的目录中。
c: \ php5 \
c: \ php7 \
你所需要做的就是告诉你的web服务器(Apache)要使用哪个版本的PHP,这是通过加载适当的模块来完成的。在Apache中,你可以通过找到httpd.conf文件,然后编辑相应的行来做到这一点:
LoadModule php7_module c:\php7\libphp7.so
当然,你必须找出正确的路径——这只是为了说明。
保存httpd.conf并重新启动服务器。注意,如果您不重新启动它,更改将不会生效。
没有GUI开关可以做到这一点,你需要编辑.conf文件,然后重新启动Apache。这样做只需要几秒钟,你甚至可以注释掉一个版本,这样“切换”只需要几次按键,例如。
使用PHP 5:
LoadModule php5_module c:\php5\libphp5.so
#LoadModule php7_module c:\php7\libphp7.so
使用PHP 7:
#LoadModule php5_module c:\php5\libphp5.so
LoadModule php7_module c:\php7\libphp7.so
您不需要多个版本的XAMPP,也不需要双启动,也不需要使用不同的机器,也不需要任何其他提出复杂解决方案的“解决方案”。OP希望使用XAMPP,并告诉它使用哪个版本的PHP。这是最快和最有效的方法,并且只需要安装一次XAMPP。
Edit 1-Nov-2017: Apparently some people are saying there's no .so files on Windows. The answer I gave was adapted from how I have things set up on my Mac (which does use .so files instead of .dll). The principle of the answer however is still exactly correct. You are using Apache's configuration file, httpd.conf to specify where the PHP module (.so or .dll) is located on your system. So the only difference for Windows would be the file name and/or path location. The answer I've given is also correct for a vanilla installation of Apache/PHP (without XAMPP at all).
您可以有两个不同版本的XAMPP。
Download those files from https://www.apachefriends.org/download.html and install into a directory of your choice, for example in C:\5.6.31\xampp and C:\7.1.18\xampp. After every installation go to installed directory (ex. C:\5.6.31\xampp, C:\7.1.18\xampp) and start the "setup_xampp.bat" and you should see something like this. You can make shortcuts of "xampp-control.exe" on your desktop (right click on "xampp-control.exe" Send to -> Desktop) and rename shortcuts for ex. "xampp 5.6.31" and "xampp 7.1.8". Start XAMPP control panel with double-click on "xampp-control.exe" or previously created shortcut and start Apache and MySQL servers. To test installiation open your browser and type 127.0.0.1 or localhost in the location bar. You should see XAMPP start screen. Do not open more then one XAMPP control panel. XAMPP uninstall? Simply remove the "xampp" Directory. But before please shutdown the apache and mysql. That's all. You can use different php versions opening corresponding XAMPP control panel.
PHP的版本可以在.htaccess文件中指定。这意味着大多数项目可以在httpd.conf文件中保留默认的全局配置,特定的项目可以通过编辑.htaccess设置为不同的版本。
使用.htaccess的优点是不同的PHP版本可以用于不同的项目,而不需要不断修改httpd.conf来指定不同的项目目录需要哪个PHP。相反,只需编辑项目的.htaccess文件,就可以直接在项目内部进行更改。
所需的确切线条取决于您的设置。对于我来说,使用快速CGI,我只是在那些我想使用PHP 8 (PHP 7是我的服务器上的默认)的项目的.htaccess文件中添加以下一行。
FcgidWrapper "C:/xampp/php-8.0.6-nts-Win32-vs16-x64/php-cgi.exe -c C:/xampp/php-8.0.6-nts-Win32-vs16-x64" .php
字符串的第一部分引用PHP可执行文件,而-c选项用于所需PHP .ini文件的目录路径。如果省略此选项,将使用全局配置的php.ini。
遵循这些简单的步骤。我目前在PHP 7.2上运行XAMPP,但需要PHP 5.6来处理旧项目。
步骤1
在https://windows.php.net/download上下载线程安全版本的PHP
把文件放在[驱动器]:\xampp\php5.6
根据新的php版本重命名文件夹
步骤2
复制(驱动):\ xampp \ apache \ conf \额外\ httpd-xampp.conf
根据新的php版本重命名文件,并将其放在这里:[Drive]:\xampp\apache\conf\extra\httpd-xampp5.6.conf
步骤3
编辑新创建的“httpd-xampp5.6.conf”
基本上,您需要更改所有PHP源代码和.dll
之前
LoadFile "C:/xampp/php/php7ts.dll"
LoadFile "C:/xampp/php/libpq.dll"
LoadModule php7_module "C:/xampp/php/php7apache2_4.dll"
后
LoadFile "C:/xampp/php5.6/php5ts.dll"
LoadFile "C:/xampp/php5.6/libpq.dll"
LoadModule php5_module "C:/xampp/php5.6/php5apache2_4.dll"
这是我的文件:https://gist.github.com/mpalencia/f8a20c31bffb02fe20d371218c23d1ec
步骤4
编辑文件[Drive]:\xampp\apache\conf\httpd.conf
之前
# XAMPP settings
Include "conf/extra/httpd-xampp.conf"
后
# XAMPP settings
Include "conf/extra/httpd-xampp5.6.conf"
切换到不同版本时,可以编辑这一行
步骤5
编辑你的PHP 5.6配置- PHP .ini
添加您的扩展目录: extension_dir = "C:\xampp\php5.6\ext"
步骤6
启动Apache
步骤7
在Windows上编辑PHP环境变量路径