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).
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:
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.
It's possible to have multiple versions of PHP set up with a single XAMPP installation. The instructions below are working for Windows.
C:\xampp\php
becomeC:\xampp\php-7.1.11
.C:\xampp\php-5.4.45
.Now you need to edit XAMPP and Apache configuration :
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 oneInclude
will be interpreted at the time.Now in
C:\xampp\apache\conf\extra
directory renamehttpd-xampp.conf
tohttpd-xampp.conf.7.1
and add a new configuration file forhttpd-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.Edit
httpd-xampp.conf.5.4.45
andhttpd-xampp.conf.7.1
and replace there all the reference to thephp
directory with the newphp-X.X
version. There are at least 10 changes to be made here for each file.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 forinclude_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.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
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
After
Here is my file: https://gist.github.com/mpalencia/f8a20c31bffb02fe20d371218c23d1ec
STEP 4
Edit the file [Drive]:\xampp\apache\conf\httpd.conf
Before
After
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
run this in Command Prompt windows (cmd.exe).
change it depending where you put the php 7 installation.
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.
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):
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!