···99Several versions of PHP are available on Nix, each of which having a
1010wide variety of extensions and libraries available.
11111212-The attribute `php` refers to the version of PHP considered most
1313-stable and thoroughly tested in nixpkgs for any given release of
1414-NixOS. Note that while this version of PHP may not be the latest major
1515-release from upstream, any version of PHP supported in nixpkgs may be
1616-utilized by specifying the desired attribute by version, such as
1717-`php74`.
1212+The different versions of PHP that nixpkgs provides are located under
1313+attributes named based on major and minor version number; e.g.,
1414+`php74` is PHP 7.4.
18151916Only versions of PHP that are supported by upstream for the entirety
2017of a given NixOS release will be included in that release of
2118NixOS. See [PHP Supported
2219Versions](https://www.php.net/supported-versions.php).
23202121+The attribute `php` refers to the version of PHP considered most
2222+stable and thoroughly tested in nixpkgs for any given release of
2323+NixOS - not necessarily the latest major release from upstream.
2424+2525+All available PHP attributes are wrappers around their respective
2626+binary PHP package and provide commonly used extensions this way. The
2727+real PHP 7.4 package, i.e. the unwrapped one, is available as
2828+`php74.unwrapped`; see the next section for more details.
2929+2430Interactive tools built on PHP are put in `php.packages`; composer is
2531for example available at `php.packages.composer`.
2632···3036`php.extensions.opcache` and the third-party ImageMagick extension at
3137`php.extensions.imagick`.
32383333-The different versions of PHP that nixpkgs provides is located under
3434-attributes named based on major and minor version number; e.g.,
3535-`php74` is PHP 7.4 with commonly used extensions installed,
3636-`php74base` is the same PHP runtime without extensions.
3737-3838-#### Installing PHP with packages
3939+#### Installing PHP with extensions
39404041A PHP package with specific extensions enabled can be built using
4142`php.withExtensions`. This is a function which accepts an anonymous
4242-function as its only argument; the function should take one argument,
4343-the set of all extensions, and return a list of wanted extensions. For
4444-example, a PHP package with the opcache and ImageMagick extensions
4545-enabled:
4343+function as its only argument; the function should accept two named
4444+parameters: `enabled` - a list of currently enabled extensions and
4545+`all` - the set of all extensions, and return a list of wanted
4646+extensions. For example, a PHP package with all default extensions and
4747+ImageMagick enabled:
46484749```nix
4848-php.withExtensions (e: with e; [ imagick opcache ])
5050+php.withExtensions ({ enabled, all }:
5151+ enabled ++ [ all.imagick ])
4952```
50535151-Note that this will give you a package with _only_ opcache and
5252-ImageMagick, none of the other extensions which are enabled by default
5353-in the `php` package will be available.
5454+To exclude some, but not all, of the default extensions, you can
5555+filter the `enabled` list like this:
5656+5757+```nix
5858+php.withExtensions ({ enabled, all }:
5959+ (lib.filter (e: e != php.extensions.opcache) enabled)
6060+ ++ [ all.imagick ])
6161+```
54625555-To enable building on a previous PHP package, the currently enabled
5656-extensions are made available in its `enabledExtensions`
5757-attribute. For example, to generate a package with all default
5858-extensions enabled, except opcache, but with ImageMagick:
6363+To build your list of extensions from the ground up, you can simply
6464+ignore `enabled`:
59656066```nix
6161-php.withExtensions (e:
6262- (lib.filter (e: e != php.extensions.opcache) php.enabledExtensions)
6363- ++ [ e.imagick ])
6767+php.withExtensions ({ all, ... }: with all; [ opcache imagick ])
6468```
6969+7070+`php.withExtensions` provides extensions by wrapping a minimal php
7171+base package, providing a `php.ini` file listing all extensions to be
7272+loaded. You can access this package through the `php.unwrapped`
7373+attribute; useful if you, for example, need access to the `dev`
7474+output. The generated `php.ini` file can be accessed through the
7575+`php.phpIni` attribute.
65766677If you want a PHP build with extra configuration in the `php.ini`
6778file, you can use `php.buildEnv`. This function takes two named and
···73847485```nix
7586php.buildEnv {
7676- extensions = e: with e; [ imagick opcache ];
8787+ extensions = { all, ... }: with all; [ imagick opcache ];
7788 extraConfig = "memory_limit=256M";
7889}
7990```
···85968697```nix
8798let
8888- myPhp = php.withExtensions (e: with e; [ imagick opcache ]);
9999+ myPhp = php.withExtensions ({ all, ... }: with all; [ opcache imagick ]);
89100in {
90101 services.phpfpm.pools."foo".phpPackage = myPhp;
91102};
···94105```nix
95106let
96107 myPhp = php.buildEnv {
9797- extensions = e: with e; [ imagick opcache ];
108108+ extensions = { all, ... }: with all; [ imagick opcache ];
98109 extraConfig = "memory_limit=256M";
99110 };
100111in {
···105116##### Example usage with `nix-shell`
106117107118This brings up a temporary environment that contains a PHP interpreter
108108-with the extensions `imagick` and `opcache` enabled.
119119+with the extensions `imagick` and `opcache` enabled:
109120110121```sh
111111-nix-shell -p 'php.buildEnv { extensions = e: with e; [ imagick opcache ]; }'
122122+nix-shell -p 'php.withExtensions ({ all, ... }: with all; [ imagick opcache ])'
112123```
+50-50
nixos/doc/manual/release-notes/rl-2009.xml
···145145 </listitem>
146146 <listitem>
147147 <para>
148148- Since this release there's an easy way to customize your PHP install to get a much smaller
149149- base PHP with only wanted extensions enabled. See the following snippet installing a smaller PHP
150150- with the extensions <literal>imagick</literal>, <literal>opcache</literal> and
148148+ Since this release there's an easy way to customize your PHP
149149+ install to get a much smaller base PHP with only wanted
150150+ extensions enabled. See the following snippet installing a
151151+ smaller PHP with the extensions <literal>imagick</literal>,
152152+ <literal>opcache</literal>, <literal>pdo</literal> and
151153 <literal>pdo_mysql</literal> loaded:
152154153155 <programlisting>
154156environment.systemPackages = [
155155-(pkgs.php.buildEnv { extensions = pp: with pp; [
156156- imagick
157157- opcache
158158- pdo_mysql
159159- ]; })
157157+ (pkgs.php.withExtensions
158158+ ({ all, ... }: with all; [
159159+ imagick
160160+ opcache
161161+ pdo
162162+ pdo_mysql
163163+ ])
164164+ )
160165];</programlisting>
161166162162- The default <literal>php</literal> attribute hasn't lost any extensions -
163163- the <literal>opcache</literal> extension was added there.
167167+ The default <literal>php</literal> attribute hasn't lost any
168168+ extensions. The <literal>opcache</literal> extension has been
169169+ added.
164170165171 All upstream PHP extensions are available under <package><![CDATA[php.extensions.<name?>]]></package>.
166172 </para>
167173 <para>
168168- The updated <literal>php</literal> attribute is now easily customizable to your liking
169169- by using extensions instead of writing config files or changing configure flags.
170170-171171- Therefore we have removed the following configure flags:
174174+ All PHP <literal>config</literal> flags have been removed for
175175+ the following reasons:
172176173177 <itemizedlist>
174174- <title>PHP <literal>config</literal> flags that we don't read anymore:</title>
175175- <listitem><para><literal>config.php.argon2</literal></para></listitem>
176176- <listitem><para><literal>config.php.bcmath</literal></para></listitem>
177177- <listitem><para><literal>config.php.bz2</literal></para></listitem>
178178- <listitem><para><literal>config.php.calendar</literal></para></listitem>
179179- <listitem><para><literal>config.php.curl</literal></para></listitem>
180180- <listitem><para><literal>config.php.exif</literal></para></listitem>
181181- <listitem><para><literal>config.php.ftp</literal></para></listitem>
182182- <listitem><para><literal>config.php.gd</literal></para></listitem>
183183- <listitem><para><literal>config.php.gettext</literal></para></listitem>
184184- <listitem><para><literal>config.php.gmp</literal></para></listitem>
185185- <listitem><para><literal>config.php.imap</literal></para></listitem>
186186- <listitem><para><literal>config.php.intl</literal></para></listitem>
187187- <listitem><para><literal>config.php.ldap</literal></para></listitem>
188188- <listitem><para><literal>config.php.libxml2</literal></para></listitem>
189189- <listitem><para><literal>config.php.libzip</literal></para></listitem>
190190- <listitem><para><literal>config.php.mbstring</literal></para></listitem>
191191- <listitem><para><literal>config.php.mysqli</literal></para></listitem>
192192- <listitem><para><literal>config.php.mysqlnd</literal></para></listitem>
193193- <listitem><para><literal>config.php.openssl</literal></para></listitem>
194194- <listitem><para><literal>config.php.pcntl</literal></para></listitem>
195195- <listitem><para><literal>config.php.pdo_mysql</literal></para></listitem>
196196- <listitem><para><literal>config.php.pdo_odbc</literal></para></listitem>
197197- <listitem><para><literal>config.php.pdo_pgsql</literal></para></listitem>
198198- <listitem><para><literal>config.php.phpdbg</literal></para></listitem>
199199- <listitem><para><literal>config.php.postgresql</literal></para></listitem>
200200- <listitem><para><literal>config.php.readline</literal></para></listitem>
201201- <listitem><para><literal>config.php.soap</literal></para></listitem>
202202- <listitem><para><literal>config.php.sockets</literal></para></listitem>
203203- <listitem><para><literal>config.php.sodium</literal></para></listitem>
204204- <listitem><para><literal>config.php.sqlite</literal></para></listitem>
205205- <listitem><para><literal>config.php.tidy</literal></para></listitem>
206206- <listitem><para><literal>config.php.xmlrpc</literal></para></listitem>
207207- <listitem><para><literal>config.php.xsl</literal></para></listitem>
208208- <listitem><para><literal>config.php.zip</literal></para></listitem>
209209- <listitem><para><literal>config.php.zlib</literal></para></listitem>
178178+ <listitem>
179179+ <para>
180180+ The updated <literal>php</literal> attribute is now easily
181181+ customizable to your liking by using
182182+ <literal>php.withExtensions</literal> or
183183+ <literal>php.buildEnv</literal> instead of writing config files
184184+ or changing configure flags.
185185+ </para>
186186+ </listitem>
187187+ <listitem>
188188+ <para>
189189+ The remaining configuration flags can now be set directly on
190190+ the <literal>php</literal> attribute. For example, instead of
191191+192192+ <programlisting>
193193+php.override {
194194+ config.php.embed = true;
195195+ config.php.apxs2 = false;
196196+}
197197+ </programlisting>
198198+199199+ you should now write
200200+201201+ <programlisting>
202202+php.override {
203203+ embedSupport = true;
204204+ apxs2Support = false;
205205+}
206206+ </programlisting>
207207+ </para>
208208+ </listitem>
210209 </itemizedlist>
210210+211211 </para>
212212 </listitem>
213213 <listitem>
···339339 pg_tmp = ephemeralpg; # added 2018-01-16
340340341341 php-embed = throw ''
342342- php*-embed has been dropped, you can build the same package by using
343343- something similar with this following snippet:
344344- (php74.override { config.php.embed = true; config.php.apxs2 = false; })
342342+ php*-embed has been dropped, you can build something similar
343343+ with the following snippet:
344344+ php74.override { embedSupport = true; apxs2Support = false; }
345345 ''; # added 2020-04-01
346346 php72-embed = php-embed; # added 2020-04-01
347347 php73-embed = php-embed; # added 2020-04-01
348348 php74-embed = php-embed; # added 2020-04-01
349349350350 phpPackages-embed = throw ''
351351- php*Packages-embed has been dropped, you can build the same package by using
352352- something similar with this following snippet:
353353- (php74.override { config.php.embed = true; config.php.apxs2 = false; }).packages
351351+ php*Packages-embed has been dropped, you can build something
352352+ similar with the following snippet:
353353+ (php74.override { embedSupport = true; apxs2Support = false; }).packages
354354 ''; # added 2020-04-01
355355 php74Packages-embed = phpPackages-embed;
356356 php73Packages-embed = phpPackages-embed;
357357 php72Packages-embed = phpPackages-embed;
358358359359 php-unit = throw ''
360360- php*-unit has been dropped, you can build the same package by using
361361- something similar with this following snippet:
362362- (php74.override {
363363- config.php.embed = true;
364364- config.php.apxs2 = false;
365365- config.php.systemd = false;
366366- config.php.phpdbg = false;
367367- config.php.cgi = false;
368368- config.php.fpm = false; })
360360+ php*-unit has been dropped, you can build something similar with
361361+ the following snippet:
362362+ php74.override {
363363+ embedSupport = true;
364364+ apxs2Support = false;
365365+ systemdSupport = false;
366366+ phpdbgSupport = false;
367367+ cgiSupport = false;
368368+ fpmSupport = false;
369369+ }
369370 ''; # added 2020-04-01
370371 php72-unit = php-unit; # added 2020-04-01
371372 php73-unit = php-unit; # added 2020-04-01
372373 php74-unit = php-unit; # added 2020-04-01
373374374375 phpPackages-unit = throw ''
375375- php*Packages-unit has been dropped, you can build the same package by using
376376- something similar with this following snippet:
376376+ php*Packages-unit has been dropped, you can build something
377377+ similar with this following snippet:
377378 (php74.override {
378378- config.php.embed = true;
379379- config.php.apxs2 = false;
380380- config.php.systemd = false;
381381- config.php.phpdbg = false;
382382- config.php.cgi = false;
383383- config.php.fpm = false; }).packages
379379+ embedSupport = true;
380380+ apxs2Support = false;
381381+ systemdSupport = false;
382382+ phpdbgSupport = false;
383383+ cgiSupport = false;
384384+ fpmSupport = false;
385385+ }).packages
384386 ''; # added 2020-04-01
385387 php74Packages-unit = phpPackages-unit;
386388 php73Packages-unit = phpPackages-unit;