Comments (3)
@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:
.php-version
https://symfony.com/doc/current/setup/symfony_server.html#selecting-a-different-php-version- 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.
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.
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)
- php 7.4 & icu4c HOT 1
- I don't switch among version shivammathur/php HOT 3
- macOS Sonoma? HOT 2
- PHP 7.4.33 and 8.2.12 crash after libsodium update HOT 2
- How can we enable SOAP,CURL and OpenSSL Extenstions?? HOT 1
- compatibility curl and interbase HOT 2
- library libsodium missing, php will not start HOT 1
- pg_connect crash when connecting to PostgreSQL HOT 2
- Homebrew PHP 8.1 install: PHP dependency re2c can't find Python interpreter HOT 1
- [email protected]: Failed to download resource "[email protected]" HOT 5
- PHP 7.4 and 8.0 no longer work after updating to php8.3 on Mac Sonoma (terminal using rosetta) HOT 8
- install php8.2 show icu4c version error HOT 7
- MacOS 11.5 install [email protected] is slow ? HOT 1
- Problem with library icu4c HOT 2
- Cannot install 7.4 in Catalina HOT 1
- Mac Sonoma 14.4.1 unable to install [email protected] HOT 5
- macOS: 11.7.10-x86_64 install php8.0 农田、
- macOS: 11.7.10-x86_64 Installing shivammathur/php/[email protected] dependency: llvm HOT 1
- MacOS 11 big sur not work HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from homebrew-php.