Giter Club home page Giter Club logo

Comments (3)

cafferata avatar cafferata commented on June 12, 2024 2

@rquadling I saw your question and thought I would share my knowledge. Are you familiar with the Symfony CLI? This solves (among other things) the issue of PHP switching.

There are two options:

  1. .php-version
    https://symfony.com/doc/current/setup/symfony_server.html#selecting-a-different-php-version
  2. Composer platform php configuration:
    https://getcomposer.org/doc/06-config.md#platform

Locally I have the three PHP 8.x versions installed:

symfony local:php:list
+---------+-------------------------------------+---------+---------------------------------+--------------------------------+---------+---------+
| Version |              Directory              |   PHP   |               PHP               |              PHP               | Server  | System? |
|         |                                     |   CLI   |               FPM               |              CGI               |         |         |
+---------+-------------------------------------+---------+---------------------------------+--------------------------------+---------+---------+
| 8.1.27  | /usr/local/Cellar/[email protected]/8.1.27_1  | bin/php | sbin/php-fpm                    | bin/php-cgi                    | PHP FPM |         |
| 8.2.16  | /usr/local/Cellar/[email protected]/8.2.16_1  | bin/php | sbin/php-fpm                    | bin/php-cgi                    | PHP FPM |         |
| 8.3.3   | /usr/local                          | bin/php | Cellar/php/8.3.3_1/sbin/php-fpm | Cellar/php/8.3.3_1/bin/php-cgi | PHP FPM | *       |
+---------+-------------------------------------+---------+---------------------------------+--------------------------------+---------+---------+

The current PHP version is selected from default version in $PATH

To control the version used in a directory, create a .php-version file that contains the version number (e.g. 7.2 or 7.2.15),
or define config.platform.php inside composer.json.
If you're using Platform.sh or Upsun, the version can also be specified in their configuration files.

Example (with .php-version)

mkdir project-1
echo "8.2" > project-1/.php-version
mkdir project-2
echo "8.3" > project-2/.php-version
cd project-1
symfony php -v
PHP 8.2.16 (cli) (built: Feb 13 2024 15:22:59) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.16, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.16, Copyright (c), by Zend Technologies
cd ../project-2
symfony php -v
PHP 8.3.3 (cli) (built: Feb 13 2024 15:41:14) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.3, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.3, Copyright (c), by Zend Technologies

To avoid having to think about the command symfony php locally, I set up an Bash alias:

#!/usr/bin/env bash
alias php='symfony php'

If you use Composer, you can also send this via the Symfony binary so that Composer works with the correct PHP version. Of course I have also set a local Bash alias for this:

#!/usr/bin/env bash
alias composer='symfony composer'

The example above also works the same when you configure PHP within Composer:

composer config platform.php "8.1"

I hope this helps you (or others). ☺️

from homebrew-php.

rquadling avatar rquadling commented on June 12, 2024 1

This was VERY interesting and immediately useful. And I think covers my requirements perfectly. As soon as I'd realised Symfony-CLI wasn't a PHP application/library!

Considering everything I needed is covered, I'm going to close this issue.

Thank you!!

from homebrew-php.

rquadling avatar rquadling commented on June 12, 2024

Oh! One word to add about all of this. The Homebrew setting of HOMEBREW_NO_INSTALL_CLEANUP=1 is VERY VERY much needed!

from homebrew-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.