Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

PHP.txt 15 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
  1. = PHP Packaging Guidelines
  2. Fedora Packaging Guidelines for PHP addon modules
  3. [#types]
  4. == Different types of PHP packages
  5. There are basically 4 different kinds of PHP modules, which are packaged for Fedora:
  6. * https://pecl.php.net[PECL] (PHP Extension Community Library) modules,
  7. which are PHP modules usually written in C
  8. and are dynamically loaded by the PHP interpreter on startup.
  9. * https://pear.php.net[PEAR] (PHP Extension and Application Repository) modules,
  10. which are reusable components written in PHP, usually classes,
  11. which can be used in your own PHP applications and scripts
  12. by using e.g. the `+include()+` directive.
  13. * Composer registered libraries,
  14. which are reusable components written in PHP,
  15. usually PSR-0 compliant classes,
  16. registered on a package registry,
  17. most often on https://packagist.org/[Packagist].
  18. * CHANNEL : packages which register a channel.
  19. A channel is a repository which provides PHP extensions.
  20. * Other packages providing a PHP extension not handled by PEAR/PECL mechanisms.
  21. While upstream uses the same package and distribution format for PECL and PEAR,
  22. creating RPMs has to take some differences into account.
  23. 3 channels are defined on installation of `+php-pear+`:
  24. * `+pear.php.net+` (alias `+pear+`) :
  25. the default channel for PHP Extension and Application Repository
  26. * `+pecl.php.net+` (alias `+pecl+`) :
  27. the default channel for PHP Extension Community Library
  28. * `+__uri+` :
  29. Pseudo-channel for static packages
  30. Other channels must be configured at RPM build time
  31. and at at RPM installation time.
  32. [#naming-scheme]
  33. == Naming scheme
  34. * PECL packages from standard pecl channel should be named
  35. `+php-pecl-PECLPackageName-%{version}-%{release}.%{arch}.rpm+`.
  36. * PEAR packages from standard pear channel should be named
  37. `+php-pear-PEARPackageName-%{version}-%{release}.noarch.rpm+`.
  38. * CHANNEL packages should be named
  39. `+php-channel-ChannelAlias-%{version}-%{release}.noarch.rpm+`
  40. * Packages from another channel should be named
  41. `+php-ChannelAlias-PackageName-%{version}-%{release}.noarch.rpm+`
  42. * Composer enabled packages
  43. (referenced in packagist.org or another registry)
  44. should be named
  45. `+php-vendor-library-%{version}-%{release}.noarch.rpm+`
  46. (where `+vendor/library+` is the known packagist name,
  47. `+name+` attribute in `+composer.json+`).
  48. When `+vendor+` equals `+library+`, one can be dropped
  49. (ex `+symfony/symfony+` can be named `+php-symfony+`).
  50. * Other packages should be named
  51. `+php-PackageName-%{version}-%{release}.%{arch}.rpm+`;
  52. `+%{arch}+` can be `+noarch+` where appropriate.
  53. Please make sure that a pure PHP package (PEAR, packagist...)
  54. is correctly being built for `+noarch+`.
  55. As for other packages,
  56. name should only use lowercase, underscore and slash replaced by dash.
  57. The `+PECLPackageName+` and the `+PEARPackageName+` should be consistent
  58. with the upstream naming scheme.
  59. The Crack PHP Extension would thus be named `+php-pecl-crack+`
  60. with the resulting packages being
  61. `+php-pecl-crack-0.4-1.i386.rpm+` and `+php-pecl-crack-0.4-1.src.rpm+`.
  62. Note that applications that happen to be written in PHP
  63. do not belong under the `+php-*+` namespace.
  64. [#file-placement]
  65. == File Placement
  66. Non-PEAR PHP software which provides shared libraries
  67. should put its PHP source files for such shared libraries
  68. in a subfolder of `+%{_datadir}/php+`,
  69. named according to the name of the software.
  70. For example, a library called _Whizz_Bang_
  71. (with a RPM called `+php-something-Whizz-Bang+`)
  72. would put the PHP source files for its shared libraries
  73. in `+%{_datadir}/php/Whizz_Bang+`.
  74. A PSR-0 footnote:[https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md[PSR-0]] compliant library
  75. would put its PHP files in `+%{_datadir}/php/+`
  76. A PSR-4 footnote:[https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md[PSR-4]] compliant library
  77. would put its PHP files in `+%{_datadir}/php/+`
  78. in a PSR-0 compliant tree.
  79. PEAR documentation provided by upstream are installed in `+%{pear_docdir}+`,
  80. should stay there,
  81. and must be marked as `+%doc+`.
  82. PECL documentation provided by upstream is installed in `+%{pecl_docdir}+`,
  83. should stay there,
  84. and must be marked as `+%doc+`.
  85. The `+composer.json+` file is not used,
  86. and should be installed as `+%doc+`
  87. as it provides useful information about the package and its dependencies.
  88. [#requires-provides]
  89. == Requires and Provides
  90. [#requires-provides-pear]
  91. === PEAR Packages from the standard channel/repository
  92. A PEAR package *MUST* have:
  93. ....
  94. BuildRequires: php-pear(PEAR)
  95. Requires: php-pear(PEAR)
  96. Requires(post): %{__pear}
  97. Requires(postun): %{__pear}
  98. Provides: php-pear(foo) = %{version}
  99. ....
  100. The virtual provide should match exactly upstream name,
  101. including case and underscore, ex: `+php-pear(Text_Wiki)+`
  102. A PEAR package must have all its dependencies available as PEAR packages,
  103. so should only requires those using the `+php-pear(foo)+` virtual provides.
  104. Known exception for unbundled libraries
  105. (which are often bundled because not available in any PEAR channel).
  106. [#requires-provides-channel]
  107. === Packages for CHANNEL (repository) configuration
  108. A CHANNEL package *MUST* have :
  109. ....
  110. Requires: php-pear(PEAR)
  111. Requires(post): %{__pear}
  112. Requires(postun): %{__pear}
  113. Provides: php-channel(channelname)
  114. ....
  115. [#requires-provides-pear-nonstandard]
  116. === PEAR Packages from a non standard channel/repository
  117. A PEAR package *MUST* have:
  118. ....
  119. BuildRequires: php-channel(channelname)
  120. BuildRequires: php-pear(PEAR)
  121. Requires: php-pear(PEAR)
  122. Requires(post): %{__pear}
  123. Requires(postun): %{__pear}
  124. Requires: php-channel(channelname)
  125. Provides: php-pear(channelname/foo) = %{version}
  126. ....
  127. [#requires-provides-composer]
  128. === Composer registered Packages
  129. Each package registered on https://packagist.org/[Packagist]
  130. (which is the most widely used registry,
  131. so defined as the implicit one)
  132. *MUST* have
  133. ....
  134. Provides: php-composer(vendor/library) = %{version}
  135. ....
  136. Package registered on another registry *MUST* have
  137. ....
  138. Provides: php-composer(registry_url/vendor/library) = %{version}
  139. ....
  140. The virtual provide should match exactly upstream name,
  141. including underscore,
  142. ex: `+php-composer(pear/console_table)+`
  143. Packages moved from PEAR to Composer/Packagist
  144. should also Provide `+php-pear(foo)+`
  145. when needed (used by other PEAR packages).
  146. Packages must not Require any `+php-pear(foo)+`,
  147. but should use `+php-composer(pear/foo)+`.
  148. `+composer.json+` useful attributes
  149. (see https://getcomposer.org/doc/04-schema.md[Composer schema documentation])
  150. * `+name+`
  151. * `+description+` : 1 line, could be used as RPM summary attribute
  152. * `+homepage+` : could be used as RPM URL attribute
  153. * `+license+`
  154. * `+require+` :
  155. describes mandatory dependencies
  156. PHP version,
  157. PHP extensions
  158. or other composer libraries,
  159. those must be required by the RPM package as `+php-composer(foo)+`
  160. * `+require-dev+` :
  161. describes development dependencies,
  162. usually useful a build time (ex: to run unit test),
  163. so could appear as BuidRequires
  164. * `+suggest+` :
  165. describes optional dependencies,
  166. so could appear as Requires (packager choice)
  167. * `+conflict+` : as RPM Conflicts
  168. * `+replace+` : as RPM Obsoletes
  169. * `+provide+` :
  170. for additional virtual provides,
  171. must also be in RPM Provides as `+php-composer(foo)+`
  172. [#requires-provides-c]
  173. === C extensions (PECL and others)
  174. To be certain that a binary extension will run correctly
  175. with a particular version of PHP,
  176. it is necessary to check that a particular package
  177. has both API and ABIs matching the installed version of PHP.
  178. The mechanism for doing this is as follows:
  179. ....
  180. BuildRequires: php-devel
  181. Requires: php(zend-abi) = %{php_zend_api}
  182. Requires: php(api) = %{php_core_api}
  183. ....
  184. [#requires-provides-pecl]
  185. === PECL Packages
  186. PECL extension *MUST* have ABI check
  187. (see xref:requires-provides-c[C extensions] above).
  188. A PECL package *MUST* also have:
  189. ....
  190. Provides: php-pecl(foo) = %{version}
  191. Provides: php-pecl(foo)%{?_isa} = %{version}
  192. ....
  193. [#requires-provides-pecl-nonstandard]
  194. === PECL Packages from a non standard channel/repository
  195. A PECL package from a non standard channel MUST have
  196. (instead of previous provides)
  197. ....
  198. Requires: php-channel(channelname)
  199. Provides: php-pecl(channelname/foo) = %{version}
  200. Provides: php-pecl(channelname/foo)%{?_isa} = %{version}
  201. ....
  202. [#requires-provides-other]
  203. === Other Packages
  204. PHP addons which are neither PEAR nor PECL
  205. should require what makes sense
  206. (either a base PHP version or a `+php-api+`, `+php(zend-abi)+` as necessary).
  207. [#requires-provides-httpd]
  208. === Apache requirement
  209. A PHP library must not have an explicit Requires on `+php+` or `+httpd+`,
  210. since these libraries could be used with any webserver
  211. or any SAPI (`+php-cli+`, `+php-cgi+`, `+php-fpm+`, ...).
  212. Only a PHP web application,
  213. which provides a specific Apache httpd configuration,
  214. should have a Requires on `+httpd+` and `+mod_php+`.
  215. [#requires-provides-extensions]
  216. === Extensions Requires
  217. PHP extensions must have a Requires on all of the dependent extensions
  218. (`+php-date+`, `+php-gd+`, `+php-mbstring+`, ...).
  219. These extensions are virtual Provides of the php sub-packages.
  220. [#requires-provides-min-php]
  221. === Requiring a Minimum PHP version
  222. If you need to specify a minimum PHP version,
  223. the recommended method is to add a Requires: `+php(language) >= $VERSION+`
  224. (where `+$VERSION+` is the minimum PHP version).
  225. [#c-pecl-config-file]
  226. == C extension and PECL package configuration files
  227. Each extension should drop a configuration file
  228. in `+%{php_inidir}+` and/or `+%{php_ztsinidir}+`
  229. to enable the extension.
  230. This file must contain the name of the loaded extension.
  231. The file must use a numeric prefix to ensure correct load order:
  232. * range 00-19 is reserved for zend_extensions
  233. (ex: `+10-opcache.ini+`, `+15-xdebug.ini+`, ...)
  234. * range 20-39 is reserved for extensions from php sources
  235. (ex: `+20-pdo.ini+`, `+30-pdo_pgsql.ini+`, ...)
  236. * range 40-99 is available for other extensions
  237. (ex: `+40-zip.ini+`, ...)
  238. [#macros-scriptlets]
  239. == Macros and scriptlets
  240. [#macros-scriptlets-zts]
  241. === PHP ZTS extension
  242. When the Apache HTTPD is run in worker mode (instead of prefork mode),
  243. the ZTS (Zend Thread Safe) version of PHP is used.
  244. If an extension maintainer wants to provide a ZTS version of this extension,
  245. the maintainer must ensure that:
  246. * the extension is thread safe
  247. * the libraries used by the extension are thread safe
  248. The `+php-devel+` package provides the necessary files
  249. to build ZTS modules
  250. and provides several helper macros:
  251. For standard (NTS) extensions
  252. ....
  253. %{__php} %{_bindir}/php
  254. %{php_extdir} %{_libdir}/php/modules
  255. %{php_inidir} %{_sysconfdir}/php.d
  256. %{php_incldir %{_includedir}/php
  257. ....
  258. For ZTS extensions
  259. ....
  260. %{__ztsphp} %{_bindir}/zts-php
  261. %{php_ztsextdir} %{_libdir}/php-zts/modules
  262. %{php_ztsinidir} %{_sysconfdir}/php-zts.d
  263. %{php_ztsincldir %{_includedir}/php-zts/php
  264. ....
  265. `+php-devel+` provides the executables needed during the build of a ZTS extension,
  266. which are:
  267. * `+zts-phpize+`
  268. * `+zts-php-config+`
  269. * `+zts-php+` (which is only useful to run the test suite during build)
  270. [#macros-scriptlets-channel]
  271. === Packages for CHANNEL (repository) configuration
  272. Here are some recommended scriptlets
  273. for properly registering and unregistering the channel:
  274. ....
  275. %post
  276. if [ $1 -eq 1 ] ; then
  277. %{__pear} channel-add %{pear_xmldir}/%{name}.xml > /dev/null || :
  278. else
  279. %{__pear} channel-update %{pear_xmldir}/%{name}.xml > /dev/null ||:
  280. fi
  281. %postun
  282. if [ $1 -eq 0 ] ; then
  283. %{__pear} channel-delete %{channelname} > /dev/null || :
  284. fi
  285. ....
  286. [#macros-scriptlets-pear]
  287. === PEAR Modules
  288. The `+php-pear+` package provides several useful macros:
  289. * `+%{pear_phpdir}+`
  290. * `+%{pear_docdir}+` (This evaluates to `+%{_docdir}/pear+`.)
  291. * `+%{pear_testdir}+`
  292. * `+%{pear_datadir}+`
  293. * `+%{pear_xmldir}+`
  294. * `+%{pear_metadir}+` (This evaluates to `+/var/lib/pear+`.)
  295. These definitions for the .spec should be of interest:
  296. ....
  297. BuildRequires: php-pear >= 1:1.4.9-1.2
  298. Provides: php-pear(PackageName) = %{version}
  299. Requires: php-common >= 4.3, php-pear(PEAR)
  300. Requires(post): %{_bindir}/pear
  301. Requires(postun): %{_bindir}/pear
  302. ....
  303. Be sure you delete any PEAR metadata files at the end of `+%install+`:
  304. ....
  305. rm -rf %{buildroot}/%{pear_metadir}/.??*
  306. ....
  307. Here are some recommended scriptlets for properly registering the module:
  308. ....
  309. %post
  310. %{_bindir}/pear install --nodeps --soft --force --register-only %{pear_xmldir}/%{name}.xml >/dev/null ||:
  311. ....
  312. And here are some recommended scriptlets for properly unregistering the module,
  313. from the standard channel:
  314. ....
  315. %postun
  316. if [ "$1" -eq "0" ] ; then
  317. %{_bindir}/pear uninstall --nodeps --ignore-errors --register-only Foo_Bar >/dev/null ||:
  318. fi
  319. ....
  320. From a non standard channel (`+pear+` command requires the channel):
  321. ....
  322. %postun
  323. if [ "$1" -eq "0" ] ; then
  324. %{_bindir}/pear uninstall --nodeps --ignore-errors --register-only Foo_channel/Foo_Bar >/dev/null ||:
  325. fi
  326. ....
  327. [#macros-scriptlets-pecl]
  328. === PECL Modules
  329. The `+php-pear+` package provides several useful macros:
  330. * `+%{pecl_phpdir}+`
  331. * `+%{pecl_docdir}+`
  332. * `+%{pecl_testdir}+`
  333. * `+%{pecl_datadir}+`
  334. * `+%{pecl_xmldir}+`
  335. You may need to define a few additional macros
  336. to extract some information from PHP.
  337. It is recommended that you use the following:
  338. ....
  339. %global php_apiver %((echo 0; php -i 2>/dev/null | sed -n 's/^PHP API => //p') | tail -1)
  340. %{!?__pecl: %{expand: %%global __pecl %{_bindir}/pecl}}
  341. %{!?php_extdir: %{expand: %%global php_extdir %(php-config --extension-dir)}}
  342. ....
  343. Module (un)registration is handled automatically
  344. by file triggers in the `+php-pear+` package.
  345. For older releases,
  346. here are some recommended scriptlets
  347. for properly registering and unregistering a module:
  348. ....
  349. BuildRequires: php-pear
  350. Requires(post): %{__pecl}
  351. Requires(postun): %{__pecl}
  352. %post
  353. %{pecl_install} %{pecl_xmldir}/%{name}.xml >/dev/null || :
  354. %postun
  355. if [ $1 -eq 0 ] ; then
  356. %{pecl_uninstall} %{pecl_name} >/dev/null || :
  357. fi
  358. ....
  359. [#macros-scriptlets-other]
  360. === Other Modules
  361. If your module includes compiled code,
  362. you may need to define some macros
  363. to extract some information from PHP.
  364. It is recommended that you user the following:
  365. ....
  366. %global php_apiver %((echo 0; php -i 2>/dev/null | sed -n 's/^PHP API => //p') | tail -1)
  367. %global php_extdir %(php-config --extension-dir 2>/dev/null || echo "undefined")
  368. %global php_version %(php-config --version 2>/dev/null || echo 0)
  369. ....
  370. [#hints]
  371. == Additional Hints for Packagers
  372. [#hints-pear-pecl]
  373. === PEAR & PECL Packages
  374. The source archive contains a `+package.xml+` outside any directory,
  375. so you have to use use
  376. ....
  377. %setup -q -c
  378. ....
  379. in your `+%prep+` section to avoid writing files to the build root.
  380. [#hints-pear]
  381. === PEAR Packages
  382. To create your initial specfile,
  383. you can use the default template provided by the `+rpmdevtools+` package:
  384. ....
  385. rpmdev-newspec -t php-pear php-pear-Foo
  386. ....
  387. Or you can generate one;
  388. make sure you have the `+php-pear-PEAR-Command-Packaging+` package installed:
  389. ....
  390. pear make-rpm-spec Foo.tgz
  391. ....
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...