This package provides a Nix flake ready to use
for PHP development, using the Nix package manager
which can be installed on (almost) any operating system.
Each available environment provides the following tools:
- Custom
php.iniloading, - Composer,
- Git,
- Github CLi,
- Symfony CLi,
- GNU Make.
Available PHP versions from 5.6 to 8.2.
The PHP extensions to use are automatically inferred from the composer.json
file.
...8<...
"require": {
"ext-intl": "*",
},
"require-dev": {
"ext-xdebug": "*",
"ext-pcov": "*",
}
...>8...To load extensions from require and required-dev sections, using the flag
--impure is required. Exemple:
nix shell github:loophp/nix-shell#php82 --impureWe use Cachix to store binaries of the
built packages. Install it as described in its docs
and then add the cache using cachix use nix-shell if you want to avoid
building those PHP packages yourself.
cachix use nix-shellWhile being extremely stable for years, "flake" is an upcoming feature of the Nix package manager. In order to use it, you must explicitly enable it, please check the documentation to enable it, this is currently an opt-in option.
To work with PHP 8.1 only:
nix shell github:loophp/nix-shell#php81or with PHP 8.1 and a couple of useful tools:
nix shell github:loophp/nix-shell#env-php81Since the 14th of November 2022, PHP is in NTS mode by default (see
#154774).
Available PHP versions and environments are:
php56,env-php56php70,env-php70php71,env-php71php72,env-php72php73,env-php73php74,env-php74php80,env-php80php81,env-php81php82,env-php82
This package also provide development environments with some tools:
In order to use them, use the prefix env-:
nix shell github:loophp/nix-shell#env-php81Import the input:
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
phps.url = "github:loophp/nix-shell";
};Then each PHP environment will be available at
# PHP 8.1
phps.packages.${system}.php81or
# PHP 8.1 environment
phps.packages.${system}.env-php81You may also use the API to build your own custom version of PHP in your own flake:
{
description = "A very basic flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
nix-shell.url = "github:loophp/nix-shell";
};
outputs = { self, nixpkgs, flake-utils, nix-shell }:
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs {
inherit system;
};
php = (nix-shell.api.makePhp system {
php = "php81";
withExtensions = [ "pcov" "xdebug" ];
withoutExtensions = [ "sodium" ];
extraConfig = ''
memory_limit=-1
'';
flags = {
apxs2Support = false;
ztsSupport = false;
};
});
in
{
devShells = {
default = pkgs.mkShellNoCC {
name = "PHP project";
buildInputs = [
php
php.packages.composer
pkgs.mailhog
];
};
};
}
);
}direnv is an extension for your shell. It augments existing shells with a new
feature that can load and unload environment variables depending on the current
directory. You can use it within Nix (nix-direnv) and load a
development environment just by changing directory.
Edit the file .envrc and add the line:
use flake github:loophp/nix-shell#env-php81 --impure
And it's done !
To customize the PHP configuration, you can do it like this:
nix shell github:loophp/nix-shell#php81
php -c /path/to/the/config.ini <<command>>Another option would be to create a .user.ini file within your
current working directory before running the PHP environment,
as such:
max_execution_time = 0
memory_limit = 2048MThen run:
nix shell github:loophp/nix-shell#php81 --impureThe --impure flag is important to make sure that your custom
.user.ini file is correctly taken in account.
Feel free to contribute by sending pull requests. We are a usually very responsive team and we will help you going through your pull request from the beginning to the end.
For some reasons, if you can't contribute to the code and willing to help, sponsoring is a good, sound and safe way to show us some gratitude for the hours we invested in this package.
Sponsor me on Github and/or any of the contributors.
- Jan Tojnar for assisting me into incorporating his own package.
- Aaron Anderse for improving the code and giving some tips.
See CHANGELOG.md for a changelog based on git commits.
For more detailed changelogs, please check the release changelogs.
