uuid: - value: 189d6034-5777-4ee1-93c1-20e255b6a32e langcode: - value: en type: - target_id: daily_email target_type: node_type target_uuid: 8bde1f2f-eef9-4f2d-ae9c-96921f8193d7 revision_timestamp: - value: '2025-06-27T09:02:29+00:00' revision_uid: - target_type: user target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849 revision_log: { } status: - value: true uid: - target_type: user target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849 title: - value: 'PHP and Nix shells' created: - value: '2025-06-24T09:01:52+00:00' changed: - value: '2025-06-27T09:02:29+00:00' promote: - value: false sticky: - value: false default_langcode: - value: true revision_translation_affected: - value: true path: - alias: /daily/2025/06/24/php-and-nix-shells langcode: en body: - value: |- What if you needed to run or test multiple versions of PHP? Would you use options like virtual machines or containers, which install full operating systems, just to get access to different versions of the same package? Would you need to create a different VM or container for each version of PHP? Another approach is to use Nix or, more specifically, nixpkgs - a package manager with more than 120,000 packages that can be installed on macOS or any Linux distribution. The [current stable release][0] (25.05) has 8.4.8, 8.3.22, 8.2.28 and 8.1.32 available, as well as other packages like PHPUnit and Phpactor. You can add any of these versions to a Nix configuration file, or create temporary shells with the version you need by running simple commands like `nix shell nixpkgs#php83`. In that shell, you have access to PHP 8.3. Once you leave it, you can re-run the command with a different version of PHP. And it works with other languages such as nodejs, by running similar commands like `nix shell nixpkgs#nodejs_22`, making it even more powerful. [0]: https://search.nixos.org/packages?channel=25.05&query=php format: markdown processed: |
What if you needed to run or test multiple versions of PHP?
Would you use options like virtual machines or containers, which install full operating systems, just to get access to different versions of the same package?
Would you need to create a different VM or container for each version of PHP?
Another approach is to use Nix or, more specifically, nixpkgs - a package manager with more than 120,000 packages that can be installed on macOS or any Linux distribution.
The current stable release (25.05) has 8.4.8, 8.3.22, 8.2.28 and 8.1.32 available, as well as other packages like PHPUnit and Phpactor.
You can add any of these versions to a Nix configuration file, or create temporary shells with the version you need by running simple commands like nix shell nixpkgs#php83
.
In that shell, you have access to PHP 8.3.
Once you leave it, you can re-run the command with a different version of PHP.
And it works with other languages such as nodejs, by running similar commands like nix shell nixpkgs#nodejs_22
, making it even more powerful.