0

I have two PHP version(php 5.6 & php 7.3) installed in my xampp. I have two folders for these two version.

  • php
  • php73

php7.3 runs on port 8081 and php 5.6 runs on Port 8080.

I have installed composer for the php 5.6 version.

Now when I try to install latest laravel project using

laravel new project_name 

OR

composer create-project --prefer-dist laravel/laravel project_name

it installs the the previous version of php.

How can create a new laravel project with new php version?

nas
  • 2,289
  • 5
  • 32
  • 67
  • What OS are you using? I suppose windows? – CptKicks Jul 02 '19 at 10:52
  • You need to tell composer which PHP version to use. However, the use of PHP still comes from Apache, so long as you set apache to use the version you, you should have no issues. – Petay87 Jul 02 '19 at 10:52
  • @Petay87 not true. Composer uses the globally-installed PHP binary – CptKicks Jul 02 '19 at 10:53
  • I am using windows @CptChix – nas Jul 02 '19 at 10:54
  • I was not aware that XAMPP could have more than one PHP version installed at any one time – RiggsFolly Jul 02 '19 at 10:55
  • @RiggsFolly yes i found out it is possible only last week :) – nas Jul 02 '19 at 10:56
  • I also assume you mean that you have 2 versions of XAMPP and therefore 2 versions of Apache and one runs on port 8080 and the other on port 8081 – RiggsFolly Jul 02 '19 at 10:56
  • Nope I have only 1 xampp I just have 2 folders of php and do write some changes in httd.conf file – nas Jul 02 '19 at 10:57
  • I would be interested to see those changes or can you point me at the tutorial you found to set this up please – RiggsFolly Jul 02 '19 at 10:58
  • If you have ONE of the PHP folders on your windows PATH that will be the version of PHP CLI that is used when you do a `>php` on the command line. How do you get over this limitation? – RiggsFolly Jul 02 '19 at 11:00
  • Normally dont like it when people suggest other software to a Questioner, but WAMPServer is designed to have multiple versions of almost everything in the WAMP Stack. I run 4 versions of Apache, 10 versions of PHP, 5 versions fo MySQL and 3 versions of mariaDB using WAMPServer. Not all at the same time of course, but a couple of clicks and I have a different env running for whichever project I am working on today – RiggsFolly Jul 02 '19 at 11:08
  • @RiggsFolly can you suggest me better approach. – nas Jul 02 '19 at 11:09
  • Amalgamate that with a simple batch/cmd file to add whichever version of PHP temporarily (for the life of a command windows) to the PATH and you are incredibly flexible – RiggsFolly Jul 02 '19 at 11:09
  • As composer is run on PHP CLI, start by taking ALL the php folders out of the PATH. Then write a simple bat file [here is an example](https://stackoverflow.com/a/16289254/2310830) to set the path for the duration of a command window, run it whenever you want access to the PHP CLI – RiggsFolly Jul 02 '19 at 11:11
  • @RiggsFolly the way to deal with multiple versions is to rename the binary. php56, php73 and so on. Then add all of them and you can use them in the CLI as 'php56' and 'php73' instead of plain 'php' – CptKicks Jul 02 '19 at 12:15
  • One way @CptChix but not if I want 5 versions of php7.3 3 versions of 7.2 and 10 versions of 7.1:) – RiggsFolly Jul 02 '19 at 12:17
  • @CptChix Well, in this case, you may find Docker extremely useful. https://www.youtube.com/watch?v=Qw9zlE3t8Ko – CptKicks Jul 02 '19 at 14:49

1 Answers1

0

On Windows: You need to set your environment variables to the PHP binary you would like. Go into System Properties -> Environment Variables (on the Advanced tab at the bottom). There you should have a variable called 'Path'. Edit it and then look for the one that points to the 5.6 PHP binary (most probably, this is the case). Modify that to point to the PHP binary of your choice (7.3).

You can then open a new cmd and type php -v. It should say 7.3.

CptKicks
  • 441
  • 3
  • 15