PHP: Phing, Phar, and phar.readonly
Asked Answered
C

2

6

I'm using the PHP build system phing to create a phar archive file.

Is there any known science that will let me automatically set the phar.readonly to 0 (which will allow the creation of phar to know) during a run of phing, but leave it set to 0 at all other times?

Corene answered 1/1, 2016 at 0:2 Comment(3)
php -dphar.readonly=0 as interpreterAdamok
@Adamok +1 useful, but is there a way to use that with the phing.phar? Or a way to use it with vendor/bin/phing short of editing vendor/bin/phing?Corene
Often also works as shebang. Might make sense to use #!/.../bin/php -Cdphar.readonly=0 then. (If it's for distribution, I'd edit it in place. Otherwise defining a php or phing shell wrapper would be easiest.)Adamok
E
8

phar.readonly can only be set in PHP.INI

Their documentation says it can be set by ini_set() ("phar.readonly "1" PHP_INI_ALL"), but it cannot.

$ php -r "ini_set('phar.readonly',0);print(ini_get('phar.readonly'));" 1

Update from http://php.net/manual/en/phar.configuration.php

This setting can only be unset in php.ini due to security reasons. If phar.readonly is disabled in php.ini, the user may enable phar.readonly in a script or disable it later. If phar.readonly is enabled in php.ini, a script may harmlessly "re-enable" the INI variable, but may not disable it.

Elison answered 31/1, 2016 at 23:16 Comment(1)
Disable read only phar in php.ini : [Phar] phar.readonly = OffHenrion
S
1

short answer: You should set phar.readonly the parameter in your php.ini file from 1 to 0.

long answer: I have my PHP running on docker and for rewrite phar.readonly, I set an INI file in the dockerfile

RUN echo 'phar.readonly=0' >> /usr/local/etc/php/conf.d/docker-php-phar-readonly.ini

docker will read every INI file that you put in /usr/local/etc/php/conf.d/ folder and will rewrite php.ini with these parameters

Slob answered 19/6, 2020 at 12:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.