Can't enable phar writing

I had this same problem and pieced together from info on this thread, here's what I did in over-simplified explanation:

  1. in my PHP code that's generating this error, I added echo phpinfo(); (which displays a large table with all sort of PHP info) and in the first few rows verify the path of the php.ini file to make sure you're editing the correct php.ini.
  2. locate on the phpinfo() table where it says phar.readonly and note that it is On.
  3. open the php.ini file from step 1 and search for phar.readonly. Mine is on line 995 and reads ;phar.readonly = On
  4. Change this line to phar.readonly = Off. Be sure that there is no semi-colon at the beginning of the line.
  5. Restart your server
  6. Confirm that you're phar project is now working as expected, and/or search on the phpinfo()table again to see that the phar.readonly setting has changed.

phar.readonly can only be disabled in php.ini due to security reasons. If you want to check that it's is really not done using other method than php.ini then in terminal type this:-

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

If it will give you 1 means phar.readonly is On.
More on phar.configuration

Tags:

Php Ini

Phar