How to create phar file on Mac?
P粉593649715
2023-08-06 16:52:19
<p>I want to package my folder into a phar file</p>
<p><code>phar pack -f result.phar /Users/me/FolderToPack/</code></p>
<p>But on OSX the following error is returned - Creation of phar files is disabled via ini setting 'phar.readonly'. <br /><br />I tried changing the value of phar.readonly using the following code: </p><p><code></code></p>
<p><code>php -r "ini_set('phar.readonly',0);print(ini_get('phar.readonly'));"</code></p>
<p>But it doesn't work (the value of phar.readonly is still equal to 1). The PHP documentation says that changing this value is not allowed in the ini file. <br /><br />Besides installing additional libraries/programs, is there anything else I can do to create phar files on Mac? </p><p><code></code></p>
On macOS, the ability to create Phar files may be disabled due to security concerns. Changing the phar.readonly value using ini_set will have no effect because it is a PHP_INI_SYSTEM type configuration, meaning it can only be set in the php.ini file, or using other configuration methods such as .htaccess (if you are using PHP as an Apache module) .
Since you mentioned that you don't want to install additional libraries or programs, there is still a way to create a Phar file without modifying system-wide settings or installing anything extra. You can temporarily override the phar.readonly setting using the -d option when running the php command. Here's how to do it: