Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Phing, Phar, and phar.readonly

Tags:

php

phing

phar

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?

like image 672
Alan Storm Avatar asked Jan 01 '16 00:01

Alan Storm


2 Answers

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.

like image 139
AndovaBegarin Avatar answered Oct 23 '22 03:10

AndovaBegarin


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

like image 30
adnan ahmady Avatar answered Oct 23 '22 05:10

adnan ahmady