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条回答
可以哭但决不认输i
2楼-- · 2019-01-07 04:14

This is probably the least technical answer to the question, but it's also the easiest to accomplish.

If you have two drives such as C: and D: you can install a separate instance of XAMPP on both drives with different php versions. This took me less than 10 mins to do and is least error prone.

I just create two desktop shortcuts to both xampp-control.exe and name the shortcuts after their php version. I hope this helps someone like me that prefers a very quick and dirty solution.

查看更多
放荡不羁爱自由
3楼-- · 2019-01-07 04:18

You can have two different versions of 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.
查看更多
forever°为你锁心
4楼-- · 2019-01-07 04:18

I use Uniserver.

It has this feature built in.

http://www.uniformserver.com/

It's that simple.

The Uniform Server is a free lightweight WAMP server solution for Windows. Less than 24MB, modular design, includes the latest versions of Apache2, Perl5, PHP (switch between PHP53, PHP54, PHP55 or PHP56), MySQL5 or MariaDB5, phpMyAdmin or Adminer4. No installation required! No registry dust! Just unpack and fire up!

It even runs off a flash drive. Has cron emulation, support for perl, mariaDB, a couple versions of Mysql, filezilla server and a few other things.

enter image description here

查看更多
何必那么认真
5楼-- · 2019-01-07 04:19

Yes you can. I assume you have a xampp already installed. So,

  • Close all xampp instances. Using task manager stop apache and mysqld.
  • Then rename the xampp to xampp1 or something after xampp name.
  • Now Download the other xampp version. Create a folder name xampp only. Install the downloaded xampp there.
  • Now depending on the xampp version of your requirement, just rename the target folder to xampp only and other folder to different name.

That's how I am working with multiple xampp installed

查看更多
Anthone
6楼-- · 2019-01-07 04:20

Why switch between PHP versions when you can use multiple PHP version at a same time with a single xampp installation? With a single xampp installation, you have 2 options:

  1. Run an older PHP version for only the directory of your old project: This will serve the purpose most of the time, you may have one or two old projects that you intend to run with older PHP version. Just configure xampp to run older PHP version only for those project directories.

  2. Run an older PHP version on a separate port of xampp: Sometimes you may be upgrading and old project to latest PHP version when you need to run the same project on new and older PHP version back and forth. Then you can set an older PHP version on a different port (say 8056) so when you go to http://localhost/any_project/ xampp runs PHP 7 and when you go to http://localhost:8056/any_project/ xampp runs PHP 5.6.

Lets set it up.

Step 1: Download PHP

So you have PHP 7 running under xampp, you want to add an older PHP version to it, say PHP 5.6. Download the nts (Non Thread Safe) version of PHP zip archive from here and extract the files under c:\xampp\php56. The thread safe version does not include php-cgi.exe.

Step 2: Configure php.ini

Open c:\xampp\php56\php.ini file in notepad. If the file does not exist copy php.ini-development to php.ini and open it in notepad. Then uncomment the following line:

extension_dir = "ext"

Step 3: Configure apache

Open xampp control panel, click config button for apache, and click Apache (httpd-xampp.conf). A text file will open up put the following settings at the bottom of the file:

ScriptAlias /php56 "C:/xampp/php56"
<Directory "C:/xampp/php56">
    AllowOverride None
    Options None
    Require all denied
    <Files "php-cgi.exe">
        Require all granted
    </Files>
</Directory>

Note: You can add more versions of PHP to your xampp installation following step 1 to 3 if you want.

Step 4 (option 1): [Add Directories to run specific PHP version]

Now you can set directories that will run in PHP 5.6. Just add the following at the bottom of the config file to set directories.

<Directory "C:\xampp\htdocs\my_old_project1">
    UnsetEnv PHPRC
    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php56
        Action application/x-httpd-php56 "/php56/php-cgi.exe"
    </FilesMatch>
</Directory>

<Directory "C:\xampp\htdocs\my_old_project2">
    UnsetEnv PHPRC
    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php56
        Action application/x-httpd-php56 "/php56/php-cgi.exe"
    </FilesMatch>
</Directory>

Step 4 (option 2): [Run older PHP version on a separate port]

Now to to set PHP v5.6 to port 8056 add the following code to the bottom of the config file.

Listen 8056
<VirtualHost *:8056>
    UnsetEnv PHPRC
    <FilesMatch "\.php$">
        php_flag engine off
        SetHandler application/x-httpd-php56
        Action application/x-httpd-php56 "/php56/php-cgi.exe"
    </FilesMatch>
</VirtualHost>

Finish: Save and Restart Apache

Save and close the config file, Restart apache from xampp control panel. If you went for option 2 you can see the additional port(8056) listed in your xampp control panel.

enter image description here

查看更多
祖国的老花朵
7楼-- · 2019-01-07 04:20

Maybe a bit late, but I am using a batch to rename the PHP folders (a slightly modified version of the phpswitch I found years ago).

You copy the different folders into your XAMPP installation. Each PHP folder (except for the active one) receives the version number as a suffix (eg. php_5.6.32). In ALL PHP folders, a file (PHP_VERSION) is created, which contains only the respective version number, so the Script can grab this information. But that's all described in the README.

Since PHP7 the httpd-xampp.conf loads the php7ts.dll instead of the php5ts.dll. So i had to extend the script (PHPSwitch.php) to rename these config-files too by following the same approach.

    $renameCur = new PHPSwitch_Rename($currInst['path'], $this->_cfg['phpInstallationsPath'] . $this->_cfg['phpDirName'] . '_' . $currInst['version']);
    $renameNew = new PHPSwitch_Rename($newInst['path'], $this->_cfg['phpInstallationsPath'] . $this->_cfg['phpDirName']);

    $apache_curent      = $this->_cfg["phpInstallationsPath"]."apache/conf/extra/httpd-xampp.conf";
    $apache_curent_rename   = $this->_cfg["phpInstallationsPath"]."apache/conf/extra/httpd-xampp_".$currInst['version'].".conf";
    $apache_new             = $this->_cfg["phpInstallationsPath"]."apache/conf/extra/httpd-xampp_".$newInst['version'].".conf";
    $apache_new_rename      = $this->_cfg["phpInstallationsPath"]."apache/conf/extra/httpd-xampp.conf";

    $renameCur_apache_conf = new PHPSwitch_Rename($apache_curent, $apache_curent_rename);
    $renameNew_apache_conf = new PHPSwitch_Rename($apache_new, $apache_new_rename);

    $transaction = new PHPSwitch_Rename_Transaction();
    $transaction->add($renameCur);
    $transaction->add($renameNew);
    $transaction->add($renameCur_apache_conf);
    $transaction->add($renameNew_apache_conf);
查看更多
登录 后发表回答