1{ lib, stdenv, fetchurl, composableDerivation, autoconf, automake, flex, bison
2, mysql, libxml2, readline, zlib, curl, postgresql, gettext
3, openssl, pkgconfig, sqlite, config, libjpeg, libpng, freetype
4, libxslt, libmcrypt, bzip2, icu, openldap, cyrus_sasl, libmhash, freetds
5, uwimap, pam, gmp, apacheHttpd }:
6
7let
8
9 generic =
10 { version, sha256 }:
11
12 let php7 = lib.versionAtLeast version "7.0"; in
13
14 composableDerivation.composableDerivation {} (fixed: {
15
16 inherit version;
17
18 name = "php-${version}";
19
20 enableParallelBuilding = true;
21
22 buildInputs = [ flex bison pkgconfig ];
23
24 configureFlags = ["EXTENSION_DIR=$(out)/lib/php/extensions"];
25
26 flags = {
27
28 # much left to do here...
29
30 # SAPI modules:
31
32 apxs2 = {
33 configureFlags = ["--with-apxs2=${apacheHttpd}/bin/apxs"];
34 buildInputs = [apacheHttpd];
35 };
36
37 # Extensions
38 imap = {
39 configureFlags = [
40 "--with-imap=${uwimap}"
41 "--with-imap-ssl"
42 ];
43 buildInputs = [ uwimap openssl pam ];
44 };
45
46 ldap = {
47 configureFlags = ["--with-ldap=${openldap}"];
48 buildInputs = [openldap cyrus_sasl openssl];
49 };
50
51 mhash = {
52 configureFlags = ["--with-mhash"];
53 buildInputs = [libmhash];
54 };
55
56 curl = {
57 configureFlags = ["--with-curl=${curl}"];
58 buildInputs = [curl openssl];
59 };
60
61 curlWrappers = {
62 configureFlags = ["--with-curlwrappers"];
63 };
64
65 zlib = {
66 configureFlags = ["--with-zlib=${zlib}"];
67 buildInputs = [zlib];
68 };
69
70 libxml2 = {
71 configureFlags = [
72 "--with-libxml-dir=${libxml2}"
73 ];
74 buildInputs = [ libxml2 ];
75 };
76
77 pcntl = {
78 configureFlags = [ "--enable-pcntl" ];
79 };
80
81 readline = {
82 configureFlags = ["--with-readline=${readline}"];
83 buildInputs = [ readline ];
84 };
85
86 sqlite = {
87 configureFlags = ["--with-pdo-sqlite=${sqlite}"];
88 buildInputs = [ sqlite ];
89 };
90
91 postgresql = {
92 configureFlags = ["--with-pgsql=${postgresql}"];
93 buildInputs = [ postgresql ];
94 };
95
96 pdo_pgsql = {
97 configureFlags = ["--with-pdo-pgsql=${postgresql}"];
98 buildInputs = [ postgresql ];
99 };
100
101 mysql = {
102 configureFlags = ["--with-mysql=${mysql.lib}"];
103 buildInputs = [ mysql.lib ];
104 };
105
106 mysqli = {
107 configureFlags = ["--with-mysqli=${mysql.lib}/bin/mysql_config"];
108 buildInputs = [ mysql.lib ];
109 };
110
111 mysqli_embedded = {
112 configureFlags = ["--enable-embedded-mysqli"];
113 depends = "mysqli";
114 assertion = fixed.mysqliSupport;
115 };
116
117 pdo_mysql = {
118 configureFlags = ["--with-pdo-mysql=${mysql.lib}"];
119 buildInputs = [ mysql.lib ];
120 };
121
122 bcmath = {
123 configureFlags = ["--enable-bcmath"];
124 };
125
126 gd = {
127 # FIXME: Our own gd package doesn't work, see https://bugs.php.net/bug.php?id=60108.
128 configureFlags = [
129 "--with-gd"
130 "--with-freetype-dir=${freetype}"
131 "--with-png-dir=${libpng}"
132 "--with-jpeg-dir=${libjpeg}"
133 ];
134 buildInputs = [ libpng libjpeg freetype ];
135 };
136
137 gmp = {
138 configureFlags = ["--with-gmp=${gmp}"];
139 buildInputs = [ gmp ];
140 };
141
142 soap = {
143 configureFlags = ["--enable-soap"];
144 };
145
146 sockets = {
147 configureFlags = ["--enable-sockets"];
148 };
149
150 openssl = {
151 configureFlags = ["--with-openssl=${openssl}"];
152 buildInputs = [openssl];
153 };
154
155 mbstring = {
156 configureFlags = ["--enable-mbstring"];
157 };
158
159 gettext = {
160 configureFlags = ["--with-gettext=${gettext}"];
161 buildInputs = [gettext];
162 };
163
164 intl = {
165 configureFlags = ["--enable-intl"];
166 buildInputs = [icu];
167 };
168
169 exif = {
170 configureFlags = ["--enable-exif"];
171 };
172
173 xsl = {
174 configureFlags = ["--with-xsl=${libxslt}"];
175 buildInputs = [libxslt];
176 };
177
178 mcrypt = let libmcrypt' = libmcrypt.override { disablePosixThreads = true; }; in {
179 configureFlags = ["--with-mcrypt=${libmcrypt'}"];
180 buildInputs = [libmcrypt'];
181 };
182
183 bz2 = {
184 configureFlags = ["--with-bz2=${bzip2}"];
185 buildInputs = [bzip2];
186 };
187
188 zip = {
189 configureFlags = ["--enable-zip"];
190 };
191
192 ftp = {
193 configureFlags = ["--enable-ftp"];
194 };
195
196 fpm = {
197 configureFlags = ["--enable-fpm"];
198 };
199
200 mssql = stdenv.lib.optionalAttrs (!stdenv.isDarwin) {
201 configureFlags = ["--with-mssql=${freetds}"];
202 buildInputs = [freetds];
203 };
204
205 zts = {
206 configureFlags = ["--enable-maintainer-zts"];
207 };
208
209 calendar = {
210 configureFlags = ["--enable-calendar"];
211 };
212 };
213
214 cfg = {
215 imapSupport = config.php.imap or true;
216 ldapSupport = config.php.ldap or true;
217 mhashSupport = config.php.mhash or true;
218 mysqlSupport = (!php7) && (config.php.mysql or true);
219 mysqliSupport = config.php.mysqli or true;
220 pdo_mysqlSupport = config.php.pdo_mysql or true;
221 libxml2Support = config.php.libxml2 or true;
222 apxs2Support = config.php.apxs2 or true;
223 bcmathSupport = config.php.bcmath or true;
224 socketsSupport = config.php.sockets or true;
225 curlSupport = config.php.curl or true;
226 curlWrappersSupport = (!php7) && (config.php.curlWrappers or true);
227 gettextSupport = config.php.gettext or true;
228 pcntlSupport = config.php.pcntl or true;
229 postgresqlSupport = config.php.postgresql or true;
230 pdo_pgsqlSupport = config.php.pdo_pgsql or true;
231 readlineSupport = config.php.readline or true;
232 sqliteSupport = config.php.sqlite or true;
233 soapSupport = config.php.soap or true;
234 zlibSupport = config.php.zlib or true;
235 opensslSupport = config.php.openssl or true;
236 mbstringSupport = config.php.mbstring or true;
237 gdSupport = config.php.gd or true;
238 intlSupport = config.php.intl or true;
239 exifSupport = config.php.exif or true;
240 xslSupport = config.php.xsl or false;
241 mcryptSupport = config.php.mcrypt or true;
242 bz2Support = config.php.bz2 or false;
243 zipSupport = config.php.zip or true;
244 ftpSupport = config.php.ftp or true;
245 fpmSupport = config.php.fpm or true;
246 gmpSupport = config.php.gmp or true;
247 mssqlSupport = (!php7) && (config.php.mssql or (!stdenv.isDarwin));
248 ztsSupport = config.php.zts or false;
249 calendarSupport = config.php.calendar or true;
250 };
251
252 configurePhase = ''
253 # Don't record the configure flags since this causes unnecessary
254 # runtime dependencies.
255 for i in main/build-defs.h.in scripts/php-config.in; do
256 substituteInPlace $i \
257 --replace '@CONFIGURE_COMMAND@' '(omitted)' \
258 --replace '@CONFIGURE_OPTIONS@' "" \
259 --replace '@PHP_LDFLAGS@' ""
260 done
261
262 iniFile=$out/etc/php-recommended.ini
263 [[ -z "$libxml2" ]] || export PATH=$PATH:$libxml2/bin
264 ./configure --with-config-file-scan-dir=/etc --with-config-file-path=$out/etc --prefix=$out $configureFlags
265 '';
266
267 installPhase = ''
268 unset installPhase; installPhase;
269 cp php.ini-production $iniFile
270 '';
271
272 src = fetchurl {
273 url = "http://www.php.net/distributions/php-${version}.tar.bz2";
274 inherit sha256;
275 };
276
277 meta = with stdenv.lib; {
278 description = "An HTML-embedded scripting language";
279 homepage = http://www.php.net/;
280 license = stdenv.lib.licenses.php301;
281 maintainers = with maintainers; [ globin ];
282 };
283
284 patches = if !php7 then [ ./fix-paths.patch ] else [ ./fix-paths-php7.patch ];
285
286 });
287
288in {
289
290 php55 = generic {
291 version = "5.5.32";
292 sha256 = "1vljdvyqsq0vas4yhvpqycqyxl2gfndbmak6cfgxn1cfvc4c3wmh";
293 };
294
295 php56 = generic {
296 version = "5.6.18";
297 sha256 = "1vgl2zjq6ws5cjjb3llhwpfwg9gasq3q84ibdv9hj8snm4llmkf3";
298 };
299
300 php70 = generic {
301 version = "7.0.2";
302 sha256 = "0di2vallv5kry85l67za25nq4f2hjr8fad5j0c06nb69v7xpa6wv";
303 };
304
305}