Is there way to use two PHP versions in XAMPP?

2019-01-07 03:34发布

We are running XAMPP with PHP 7.0 because our new products requires PHP 7.

But there are old project which use functions like mysql_connect, etc. Those are removed in PHP 7.0.

So is there way to easily change PHP versions in XAMPP.

Note : Please don't suggest to upgrade old project to compatible with new versions because I am not in a position to do it because that decisions I can't get as a developer (just an employee).

标签: php xampp
15条回答
SAY GOODBYE
2楼-- · 2019-01-07 03:59

Unless it has to be absolutely and definitely XAMPP, you can try to get what you want with WAMP. WAMP is pretty much the same thing in different package.

Once you have it installed, you can just switch between php versions here:

enter image description here

You can install as many versions of PHP as you need.

Here's how it is done in detail.

Just go here: WAMP download

Then select your base server, e.g. latest with php7.

Then, when WAMP 3 is installed, go to folder: addons and select php version (or versions) you are after. They offer php flavors starting from php 5.3.29, which should work with mysql_connect.

To install addon, during installation (double click exe file) just point to folder where you have your WAMP 3 installed.

Then you can use content of other folders, like: applications etc. to add more functionality

Everything's interfaced, so you can concentrate on coding and not hacking your environment.

查看更多
淡お忘
3楼-- · 2019-01-07 04:02

It's possible to have multiple versions of PHP set up with a single XAMPP installation. The instructions below are working for Windows.

  1. Install the latest XAMPP version for Windows (in my case it was with PHP 7.1)
  2. Make sure that Apache is not running from XAMPP Control Panel
  3. Rename the php directory in XAMPP install directory, such as C:\xampp\php become C:\xampp\php-7.1.11.
  4. Download the version of PHP you'd like to run in addition (Eg: PHP 5.4.45)
  5. Move the php directory from the version you downloaded to XAMPP install directory. Rename it so it includes the PHP version. Such as C:\xampp\php-5.4.45.

Now you need to edit XAMPP and Apache configuration :

  1. In C:\xampp\apache\conf\httpd.conf, locate the XAMPP settings for PHP, you should change it to something such as :

Where you have to comment (with #) the other PHP versions so only one Include will be interpreted at the time.

#XAMPP settings PHP 7
Include "conf/extra/httpd-xampp.conf.7.1"

#XAMPP settings PHP 5.4.45
#Include "conf/extra/httpd-xampp.conf.5.4.45"
  1. Now in C:\xampp\apache\conf\extra directory rename httpd-xampp.conf to httpd-xampp.conf.7.1 and add a new configuration file for httpd-xampp.conf.5.4.45. In my case, I copied the conf file of another installation of XAMPP for php 5.5 as the syntax may be slightly different for each version.

  2. Edit httpd-xampp.conf.5.4.45 and httpd-xampp.conf.7.1 and replace there all the reference to the php directory with the new php-X.X version. There are at least 10 changes to be made here for each file.

  3. You now need to edit php.ini for the two versions. For example for php 7.1, edit C:\xampp\php-7.1.11\php.ini where you will replace the path of the php directory for include_path, browscap, error_log, extension_dir..

And that's it. You can now start Apache from XAMPP Control Panel. And to switch from a version to another, you need only to edit C:\xampp\apache\conf\httpd.conf and change the included PHP version before restarting Apache.

查看更多
ら.Afraid
4楼-- · 2019-01-07 04:02

Follow this easy steps. I am currently running XAMPP on PHP 7.2 but needs PHP 5.6 to work on old projects

STEP 1

Download Thread Safe version of PHP on https://windows.php.net/download

Put files on your [Drive]:\xampp\php5.6

  • Rename the folder depending on Php version

STEP 2

Copy [Drive]:\xampp\apache\conf\extra\httpd-xampp.conf

Rename it to [Drive]:\xampp\apache\conf\extra\httpd-xampp5.6.confRename the file depending on Php version

STEP 3

Edit the newly created 'httpd-xampp5.6.conf'

basically you need to change All the PHP source and .dll

Before

LoadFile "C:/xampp/php/php7ts.dll"
LoadFile "C:/xampp/php/libpq.dll"
LoadModule php7_module "C:/xampp/php/php7apache2_4.dll"

After

LoadFile "C:/xampp/php5.6/php5ts.dll"
LoadFile "C:/xampp/php5.6/libpq.dll"
LoadModule php5_module "C:/xampp/php5.6/php5apache2_4.dll"

Here is my file: https://gist.github.com/mpalencia/f8a20c31bffb02fe20d371218c23d1ec

STEP 4

Edit the file [Drive]:\xampp\apache\conf\httpd.conf

Before

# XAMPP settings
Include "conf/extra/httpd-xampp.conf"

After

# XAMPP settings
Include "conf/extra/httpd-xampp5.6.conf"
  • You can just edit this line when switching to diffent version

STEP 5

Edit your PHP 5.6 configuration - php.ini

Add you extension directory: extension_dir = "C:\xampp\php5.6\ext"

STEP 6

Start Apache

STEP 7

Edit PHP environment variable path on Windows

查看更多
beautiful°
5楼-- · 2019-01-07 04:04

run this in Command Prompt windows (cmd.exe).

set PATH=C:\xampp\php;%PATH%

change it depending where you put the php 7 installation.

查看更多
再贱就再见
6楼-- · 2019-01-07 04:09

I would recommend using Docker, this allows you to split the environment into various components and mix and match the ones you want at any time.

Docker will allow you to run one container with MySQL, another with PHP. As they are separate images you can have two containers, one PHP 5 another PHP 7, you start up which ever one you wish and port 80 can be mapped to both containers.

https://hub.docker.com has a wide range of preconfigured images which you can install and run without much hassle.

I've also added portainer as an image, which allows you to manage the various aspects of your docker setup - from within a docker image (I did start this container on startup to save me having to use the command line). It doesn't do everything for you and sometimes it's easier to configure and launch the images for the first time from the command line, but once setup you can start and stop them through a web interface.

It's also possible to run both containers at the same time and map separate ports to each. So port 80 can be mapped to PHP 5 and 81 to PHP 81 (Or PHP 7 if your watching this in 2017).

There are various tutorials on how to install Docker( https://docs.docker.com/engine/installation/) and loads of other 'how to' type things. Try http://www.masterzendframework.com/docker-development-environment/ for a development environment configuration.

查看更多
【Aperson】
7楼-- · 2019-01-07 04:12

I needed to do the same thing, so I googled how and came to stack overflow, where the OP was having the same issue... So my findings.. I tried renaming files from all different directions AND my conclusion was basically it's taking me too long. SOOOO I ended up just installing version 7 from here:

https://www.apachefriends.org/index.html (kill services and quit out of xampp before attempting)

When asked where to put the directory name it like so (give it a different name):

enter image description here

and

DONEZO! Now just make sure to kill services and quit before swapping back and forth and you have 2 sterile XAMPP envs to play in..

Hooray! now I can actually get to work!

查看更多
登录 后发表回答