How to create phar files on Mac?

138 views Asked by At

I would like to pack my folder -

phar pack -f result.phar /Users/me/FolderToPack/

But OSX returns the following error - Creating phar files is disabled by ini setting 'phar.readonly'.

I tried to change phar.readonly value with

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

But it doesn't work (the phar.readonly value remains equal to 1). The PHP doc says that change of this value is not allowed in ini file.

What else could I do to create phar files on Mac (without installing additional libs/programs)?

1

There are 1 answers

0
Amine Hayani On BEST ANSWER

On macOS, creating Phar files might be disabled due to security considerations. Changing the phar.readonly value using ini_set will not work because it's a PHP_INI_SYSTEM type configuration, meaning it can only be set in the php.ini file or using other configuration methods like .htaccess (if you're using PHP as an Apache module).

Since you mentioned you don't want to install additional libraries or programs, there is still a way to create Phar files without modifying system-wide settings or installing anything extra. You can use the -d option when running the php command to override the phar.readonly setting temporarily. Here's how you can do it:

php -d phar.readonly=0 /path/to/phar pack -f result.phar /Users/me/FolderToPack/