···9Several versions of PHP are available on Nix, each of which having a
10wide variety of extensions and libraries available.
1112-The attribute `php` refers to the version of PHP considered most
13-stable and thoroughly tested in nixpkgs for any given release of
14-NixOS. Note that while this version of PHP may not be the latest major
15-release from upstream, any version of PHP supported in nixpkgs may be
16-utilized by specifying the desired attribute by version, such as
17-`php74`.
1819Only versions of PHP that are supported by upstream for the entirety
20of a given NixOS release will be included in that release of
21NixOS. See [PHP Supported
22Versions](https://www.php.net/supported-versions.php).
2300000000024Interactive tools built on PHP are put in `php.packages`; composer is
25for example available at `php.packages.composer`.
26···30`php.extensions.opcache` and the third-party ImageMagick extension at
31`php.extensions.imagick`.
3233-The different versions of PHP that nixpkgs provides is located under
34-attributes named based on major and minor version number; e.g.,
35-`php74` is PHP 7.4 with commonly used extensions installed,
36-`php74base` is the same PHP runtime without extensions.
37-38-#### Installing PHP with packages
3940A PHP package with specific extensions enabled can be built using
41`php.withExtensions`. This is a function which accepts an anonymous
42-function as its only argument; the function should take one argument,
43-the set of all extensions, and return a list of wanted extensions. For
44-example, a PHP package with the opcache and ImageMagick extensions
45-enabled:
04647```nix
48-php.withExtensions (e: with e; [ imagick opcache ])
049```
5051-Note that this will give you a package with _only_ opcache and
52-ImageMagick, none of the other extensions which are enabled by default
53-in the `php` package will be available.
000005455-To enable building on a previous PHP package, the currently enabled
56-extensions are made available in its `enabledExtensions`
57-attribute. For example, to generate a package with all default
58-extensions enabled, except opcache, but with ImageMagick:
5960```nix
61-php.withExtensions (e:
62- (lib.filter (e: e != php.extensions.opcache) php.enabledExtensions)
63- ++ [ e.imagick ])
64```
00000006566If you want a PHP build with extra configuration in the `php.ini`
67file, you can use `php.buildEnv`. This function takes two named and
···7374```nix
75php.buildEnv {
76- extensions = e: with e; [ imagick opcache ];
77 extraConfig = "memory_limit=256M";
78}
79```
···8586```nix
87let
88- myPhp = php.withExtensions (e: with e; [ imagick opcache ]);
89in {
90 services.phpfpm.pools."foo".phpPackage = myPhp;
91};
···94```nix
95let
96 myPhp = php.buildEnv {
97- extensions = e: with e; [ imagick opcache ];
98 extraConfig = "memory_limit=256M";
99 };
100in {
···105##### Example usage with `nix-shell`
106107This brings up a temporary environment that contains a PHP interpreter
108-with the extensions `imagick` and `opcache` enabled.
109110```sh
111-nix-shell -p 'php.buildEnv { extensions = e: with e; [ imagick opcache ]; }'
112```
···9Several versions of PHP are available on Nix, each of which having a
10wide variety of extensions and libraries available.
1112+The different versions of PHP that nixpkgs provides are located under
13+attributes named based on major and minor version number; e.g.,
14+`php74` is PHP 7.4.
0001516Only versions of PHP that are supported by upstream for the entirety
17of a given NixOS release will be included in that release of
18NixOS. See [PHP Supported
19Versions](https://www.php.net/supported-versions.php).
2021+The attribute `php` refers to the version of PHP considered most
22+stable and thoroughly tested in nixpkgs for any given release of
23+NixOS - not necessarily the latest major release from upstream.
24+25+All available PHP attributes are wrappers around their respective
26+binary PHP package and provide commonly used extensions this way. The
27+real PHP 7.4 package, i.e. the unwrapped one, is available as
28+`php74.unwrapped`; see the next section for more details.
29+30Interactive tools built on PHP are put in `php.packages`; composer is
31for example available at `php.packages.composer`.
32···36`php.extensions.opcache` and the third-party ImageMagick extension at
37`php.extensions.imagick`.
3839+#### Installing PHP with extensions
000004041A PHP package with specific extensions enabled can be built using
42`php.withExtensions`. This is a function which accepts an anonymous
43+function as its only argument; the function should accept two named
44+parameters: `enabled` - a list of currently enabled extensions and
45+`all` - the set of all extensions, and return a list of wanted
46+extensions. For example, a PHP package with all default extensions and
47+ImageMagick enabled:
4849```nix
50+php.withExtensions ({ enabled, all }:
51+ enabled ++ [ all.imagick ])
52```
5354+To exclude some, but not all, of the default extensions, you can
55+filter the `enabled` list like this:
56+57+```nix
58+php.withExtensions ({ enabled, all }:
59+ (lib.filter (e: e != php.extensions.opcache) enabled)
60+ ++ [ all.imagick ])
61+```
6263+To build your list of extensions from the ground up, you can simply
64+ignore `enabled`:
006566```nix
67+php.withExtensions ({ all, ... }: with all; [ opcache imagick ])
0068```
69+70+`php.withExtensions` provides extensions by wrapping a minimal php
71+base package, providing a `php.ini` file listing all extensions to be
72+loaded. You can access this package through the `php.unwrapped`
73+attribute; useful if you, for example, need access to the `dev`
74+output. The generated `php.ini` file can be accessed through the
75+`php.phpIni` attribute.
7677If you want a PHP build with extra configuration in the `php.ini`
78file, you can use `php.buildEnv`. This function takes two named and
···8485```nix
86php.buildEnv {
87+ extensions = { all, ... }: with all; [ imagick opcache ];
88 extraConfig = "memory_limit=256M";
89}
90```
···9697```nix
98let
99+ myPhp = php.withExtensions ({ all, ... }: with all; [ opcache imagick ]);
100in {
101 services.phpfpm.pools."foo".phpPackage = myPhp;
102};
···105```nix
106let
107 myPhp = php.buildEnv {
108+ extensions = { all, ... }: with all; [ imagick opcache ];
109 extraConfig = "memory_limit=256M";
110 };
111in {
···116##### Example usage with `nix-shell`
117118This brings up a temporary environment that contains a PHP interpreter
119+with the extensions `imagick` and `opcache` enabled:
120121```sh
122+nix-shell -p 'php.withExtensions ({ all, ... }: with all; [ imagick opcache ])'
123```
+50-50
nixos/doc/manual/release-notes/rl-2009.xml
···145 </listitem>
146 <listitem>
147 <para>
148- Since this release there's an easy way to customize your PHP install to get a much smaller
149- base PHP with only wanted extensions enabled. See the following snippet installing a smaller PHP
150- with the extensions <literal>imagick</literal>, <literal>opcache</literal> and
00151 <literal>pdo_mysql</literal> loaded:
152153 <programlisting>
154environment.systemPackages = [
155-(pkgs.php.buildEnv { extensions = pp: with pp; [
156- imagick
157- opcache
158- pdo_mysql
159- ]; })
000160];</programlisting>
161162- The default <literal>php</literal> attribute hasn't lost any extensions -
163- the <literal>opcache</literal> extension was added there.
0164165 All upstream PHP extensions are available under <package><![CDATA[php.extensions.<name?>]]></package>.
166 </para>
167 <para>
168- The updated <literal>php</literal> attribute is now easily customizable to your liking
169- by using extensions instead of writing config files or changing configure flags.
170-171- Therefore we have removed the following configure flags:
172173 <itemizedlist>
174- <title>PHP <literal>config</literal> flags that we don't read anymore:</title>
175- <listitem><para><literal>config.php.argon2</literal></para></listitem>
176- <listitem><para><literal>config.php.bcmath</literal></para></listitem>
177- <listitem><para><literal>config.php.bz2</literal></para></listitem>
178- <listitem><para><literal>config.php.calendar</literal></para></listitem>
179- <listitem><para><literal>config.php.curl</literal></para></listitem>
180- <listitem><para><literal>config.php.exif</literal></para></listitem>
181- <listitem><para><literal>config.php.ftp</literal></para></listitem>
182- <listitem><para><literal>config.php.gd</literal></para></listitem>
183- <listitem><para><literal>config.php.gettext</literal></para></listitem>
184- <listitem><para><literal>config.php.gmp</literal></para></listitem>
185- <listitem><para><literal>config.php.imap</literal></para></listitem>
186- <listitem><para><literal>config.php.intl</literal></para></listitem>
187- <listitem><para><literal>config.php.ldap</literal></para></listitem>
188- <listitem><para><literal>config.php.libxml2</literal></para></listitem>
189- <listitem><para><literal>config.php.libzip</literal></para></listitem>
190- <listitem><para><literal>config.php.mbstring</literal></para></listitem>
191- <listitem><para><literal>config.php.mysqli</literal></para></listitem>
192- <listitem><para><literal>config.php.mysqlnd</literal></para></listitem>
193- <listitem><para><literal>config.php.openssl</literal></para></listitem>
194- <listitem><para><literal>config.php.pcntl</literal></para></listitem>
195- <listitem><para><literal>config.php.pdo_mysql</literal></para></listitem>
196- <listitem><para><literal>config.php.pdo_odbc</literal></para></listitem>
197- <listitem><para><literal>config.php.pdo_pgsql</literal></para></listitem>
198- <listitem><para><literal>config.php.phpdbg</literal></para></listitem>
199- <listitem><para><literal>config.php.postgresql</literal></para></listitem>
200- <listitem><para><literal>config.php.readline</literal></para></listitem>
201- <listitem><para><literal>config.php.soap</literal></para></listitem>
202- <listitem><para><literal>config.php.sockets</literal></para></listitem>
203- <listitem><para><literal>config.php.sodium</literal></para></listitem>
204- <listitem><para><literal>config.php.sqlite</literal></para></listitem>
205- <listitem><para><literal>config.php.tidy</literal></para></listitem>
206- <listitem><para><literal>config.php.xmlrpc</literal></para></listitem>
207- <listitem><para><literal>config.php.xsl</literal></para></listitem>
208- <listitem><para><literal>config.php.zip</literal></para></listitem>
209- <listitem><para><literal>config.php.zlib</literal></para></listitem>
210 </itemizedlist>
0211 </para>
212 </listitem>
213 <listitem>
···145 </listitem>
146 <listitem>
147 <para>
148+ Since this release there's an easy way to customize your PHP
149+ install to get a much smaller base PHP with only wanted
150+ extensions enabled. See the following snippet installing a
151+ smaller PHP with the extensions <literal>imagick</literal>,
152+ <literal>opcache</literal>, <literal>pdo</literal> and
153 <literal>pdo_mysql</literal> loaded:
154155 <programlisting>
156environment.systemPackages = [
157+ (pkgs.php.withExtensions
158+ ({ all, ... }: with all; [
159+ imagick
160+ opcache
161+ pdo
162+ pdo_mysql
163+ ])
164+ )
165];</programlisting>
166167+ The default <literal>php</literal> attribute hasn't lost any
168+ extensions. The <literal>opcache</literal> extension has been
169+ added.
170171 All upstream PHP extensions are available under <package><![CDATA[php.extensions.<name?>]]></package>.
172 </para>
173 <para>
174+ All PHP <literal>config</literal> flags have been removed for
175+ the following reasons:
00176177 <itemizedlist>
178+ <listitem>
179+ <para>
180+ The updated <literal>php</literal> attribute is now easily
181+ customizable to your liking by using
182+ <literal>php.withExtensions</literal> or
183+ <literal>php.buildEnv</literal> instead of writing config files
184+ or changing configure flags.
185+ </para>
186+ </listitem>
187+ <listitem>
188+ <para>
189+ The remaining configuration flags can now be set directly on
190+ the <literal>php</literal> attribute. For example, instead of
191+192+ <programlisting>
193+php.override {
194+ config.php.embed = true;
195+ config.php.apxs2 = false;
196+}
197+ </programlisting>
198+199+ you should now write
200+201+ <programlisting>
202+php.override {
203+ embedSupport = true;
204+ apxs2Support = false;
205+}
206+ </programlisting>
207+ </para>
208+ </listitem>
00000209 </itemizedlist>
210+211 </para>
212 </listitem>
213 <listitem>