• Stars
    star
    131
  • Rank 266,498 (Top 6 %)
  • Language
    Nix
  • License
    MIT License
  • Created almost 3 years ago
  • Updated 9 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Nix shells for PHP development

GitHub stars Donate!

Nix shell

Tutorial

Description

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:

  • Composer,
  • Symfony CLI,
  • SQLite

Available stable PHP versions from 5.6 to 8.3. But also weekly builds from the following branches:

  • PHP-8.1
  • PHP-8.2
  • PHP-8.3
  • master (future 8.4)

To list the available PHP versions, run:

nix flake show github:loophp/nix-shell

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 the require and required-dev sections, using the flag --impure is required. Example:

nix shell github:loophp/nix-shell#php82 --impure

We 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-shell
cachix use php-src-nix

This project also provides a basic template for PHP projects, to use it, run:

nix flake init --template github:loophp/nix-shell#basic

Usage

While 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.

In a shell

To work with PHP 8.1 only:

nix shell github:loophp/nix-shell#php81

or with PHP 8.1 and a couple of useful tools:

nix shell github:loophp/nix-shell#env-php81

Since the 14th of November 2022, PHP is in NTS mode by default (see #154774).

To list the available PHP versions and environments, run:

nix flake show github:loophp/nix-shell

In another flake

Step 1

Import the input:

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    flake-utils.url = "github:numtide/flake-utils";
    phps.url = "github:loophp/nix-shell";
  };
Step 2

Import the overlay:

pkgs = import inputs.nixpkgs {
    inherit system;
    overlays = [
        inputs.phps.overlays.default
    ];
};
Step 3

Use the packages:

    # PHP 8.1 environment
    pkgs.env-php81

To create your own version of PHP, use the available API function buildPhpFromComposer.

With direnv

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 following line:

use flake github:loophp/nix-shell#env-php-master-snapshot --impure

And it's done.

Customize PHP

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 = 2048M

Then run:

nix shell github:loophp/nix-shell#php82 --impure

The --impure flag is important to make sure that your custom .user.ini file is correctly taken in account.

Contributing

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 are 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.

Thanks

Changelog

See CHANGELOG.md for a changelog based on git commits.

For more detailed changelogs, please check the release changelogs.

More Repositories

1

collection

A (memory) friendly, easy, lazy and modular collection class.
PHP
705
star
2

combinator

A curated list of combinators
PHP
96
star
3

phptree

An implementation of tree data structure
PHP
86
star
4

iterators

The missing PHP iterators.
PHP
33
star
5

fpt

Functional programming toolbox for PHP.
PHP
25
star
6

rust-shell

Nix shells for Rust development
Nix
20
star
7

dynamicobjects

Create PHP objects having dynamic classes and/or properties.
PHP
15
star
8

nix-php-composer-builder

A PHP builder for Composer based projects
Nix
13
star
9

memoize

Memoize a closure.
PHP
12
star
10

mock-soapclient

A fake and predictable SOAP client, useful for your unit tests.
PHP
12
star
11

repository-monadic-helper

Monadic Doctrine repositories helper classes and services.
PHP
11
star
12

launcher

Open a file or a resource with the default OS application.
PHP
10
star
13

phptree-ast-generator

Generates Abstrax Syntax Tree (AST) of a PHP script in DOT (Graphviz) or Image (PNG, JPG, SVG) formats.
PHP
8
star
14

unaltered-psr-http-message-bridge-bundle

Provide a PSR HTTP message bridge without altering query parameters.
PHP
5
star
15

tin

Taxpayer Identification Number (TIN) Validator
PHP
5
star
16

nanobench

A simple and lightweight benchmarking tool for PHP.
PHP
4
star
17

phposinfo

Try to guess the host operating system.
PHP
4
star
18

church-encoding

Church encoding in PHP
PHP
3
star
19

typed-generators

Generate random typed values and in any shape.
PHP
3
star
20

ci-detector

To detect whether we are in a CI or not
Nix
3
star
21

go-unfloc-yourself-bundle

Adds a specific header to every response to disable Google's usage of your site in it's FLoC tracking method.
PHP
3
star
22

flake-lock-update-workflow

Provide a 'ready-to-use' Github workflow to update 'flake.lock' file automatically.
Nix
2
star
23

grumphp-license-task

Provide the license task for GrumPHP.
PHP
2
star
24

nix-auto-changelog

A Nix flake to generating changelog files based on your git tags and commit history.
Nix
2
star
25

phpunit-iterable-assertions

Iterable assertions for PHPUnit
PHP
2
star
26

DockLatex

A multi-platform Docker-based LaTeX workspace for a quickstart and easy hands on.
TeX
1
star
27

php-src-nix

PHP builds for Nix, with Nix.
Nix
1
star
28

nix-phpstan

A Nix flake for PHPStan
Nix
1
star
29

psr-http-message-bridge-bundle

Register symfony/psr-http-message-bridge classes in your Symfony application.
PHP
1
star
30

php-semver-bin

PHP
1
star
31

phpspec-time

A PHPSpec extension providing matchers for measuring time in tests.
PHP
1
star
32

service-alias-autoregister-bundle

Auto register services aliases in the Symfony container.
PHP
1
star