Cms: Update Error: Zend OPcache API is restricted by "restrict_api" configuration directive

Created on 2 May 2018  路  32Comments  路  Source: craftcms/cms

Description

I'm seeing errors when updating to 3.0.5, the following is given:

[ipaddress][5][-][error][craft\controllers\BaseUpdaterController::actionComposerInstall] Error updating Composer requirements: Zend OPcache API is restricted by "restrict_api" configuration directive
Output: Loading composer repositories with package information
Updating dependencies
Package operations: 0 installs, 4 updates, 0 removals
  - Updating zendframework/zend-stdlib (3.1.1 => 3.2.0): Loading from cache
  - Updating craftcms/cms (3.0.4 => 3.0.5): Loading from cache
  - Updating yiisoft/yii2-swiftmailer (2.1.0 => 2.1.1): Loading from cache

If I refresh the page I'm taken back to the CP which now shows the version as 3.0.5, but the composer version is set to 3.0.3.1 even though I updated from 3.0.4

This leads to further errors when updating plugins (namely Redactor) such as this:

Response: <pre>OK: Craft CMS does not support backtracking to this version. Please update to Craft CMS 3.0.5 or later.</pre>

This problem is resolved by manually fixing the craftcms/cms version in composer.json and running composer update

Most helpful comment

I've also seen this error when installing fresh Craft 3 projects on environments running serverpilot. The issue seems to be serverpilot for me as I created the app to run on PHP 7.1, but there is a setting on PHP 7.2 forcing the opcache.restrict_api setting. I had to log in as root and then edit the file at /etc/php7.2-sp/conf.d/opcache.ini Here I saw the following:

# The value of opcache.restrict_api is the path prefix of scripts allowed to
# call opcache API functions: http://php.net/manual/en/ref.opcache.php
# Set the value as needed or comment out the line to allow all scripts to use
# the opcache API functions.
opcache.restrict_api=/restricted

I just commented out the final line and saved the file. I then ran sudo service php7.2-fpm-sp restart as root and attempted the Craft install again via composer. This time it all worked fine and without issue. All other versions of PHP didn't have this setting in, only 7.2 which I wasn't even using as I had selected 7.1. I hope that helps you though @lukeyouell and for that matter anybody else who is using serverpilot.

All 32 comments

Make sure your composer.json file has the correct permissions.

See: https://docs.craftcms.com/v3/installation.html#step-2-set-the-file-permissions

@seandelaney that's not the issue, something is setting the version of craft to 3.0.3.1

@lukeyouell Can you try searching for that error in storage/logs/ and send the full stack trace to [email protected] ?

Not sure why this is all-of-the-sudden an issue, but the error came from https://github.com/yiisoft/yii2-composer and has been [fixed] for its next release: https://github.com/yiisoft/yii2-composer/commit/884efe0ba2c1619e345da3388dead094ccbea616

What's odd is that code hasn't changed in ages: https://github.com/yiisoft/yii2-composer/blame/2.0.6/Installer.php#L161

Regardless, in the meantime, you can set your https://secure.php.net/manual/en/opcache.configuration.php#ini.opcache.restrict-api setting to "" to get around it.

@brandonkelly @angrybrad It looks like this error has reared it's ugly head again. We're encountering the issue when trying to update our installations to 3.0.13.2

Stack trace:

[x.x.x.x][5][-][error][craft\controllers\BaseUpdaterController::actionComposerInstall] Error updating Composer requirements: Zend OPcache API is restricted by "restrict_api" configuration directive
Output: Loading composer repositories with package information
Updating dependencies
Package operations: 0 installs, 5 updates, 0 removals
  - Updating zendframework/zend-feed (2.8.0 => 2.10.2): Loading from cache
  - Updating craftcms/cms (3.0.12 => 3.0.13.2): Loading from cache
  - Updating league/oauth2-client (2.2.1 => 2.3.0): Loading from cache
  - Updating yiisoft/yii2-queue (2.0.2 => 2.1.0): Loading from cache

2018-07-02 08:56:18 [x.x.x.x][5][-][error][yii\base\ErrorException:2] yii\base\ErrorException: Zend OPcache API is restricted by "restrict_api" configuration directive in /srv/users/serverpilot/apps/foobar/craft/vendor/yiisoft/yii2-composer/Installer.php:161
Stack trace:
#0 /srv/users/serverpilot/apps/foobar/craft/vendor/craftcms/cms/src/web/ErrorHandler.php(84): yii\base\ErrorHandler->handleError(2, 'Zend OPcache AP...', '/srv/users/serv...', 161)
#1 [internal function]: craft\web\ErrorHandler->handleError(2, 'Zend OPcache AP...', '/srv/users/serv...', 161, Array)
#2 /srv/users/serverpilot/apps/foobar/craft/vendor/yiisoft/yii2-composer/Installer.php(161): opcache_invalidate('/srv/users/serv...', true)
#3 /srv/users/serverpilot/apps/foobar/craft/vendor/yiisoft/yii2-composer/Installer.php(148): yii\composer\Installer->loadExtensions()
#4 /srv/users/serverpilot/apps/foobar/craft/vendor/yiisoft/yii2-composer/Installer.php(56): yii\composer\Installer->removePackage(Object(Composer\Package\CompletePackage))
#5 /srv/users/serverpilot/apps/foobar/craft/vendor/composer/composer/src/Composer/Installer/InstallationManager.php(193): yii\composer\Installer->update(Object(Composer\Repository\InstalledFilesystemRepository), Object(Composer\Package\CompletePackage), Object(Composer\Package\CompletePackage))
#6 /srv/users/serverpilot/apps/foobar/craft/vendor/composer/composer/src/Composer/Installer/InstallationManager.php(160): Composer\Installer\InstallationManager->update(Object(Composer\Repository\InstalledFilesystemRepository), Object(Composer\DependencyResolver\Operation\UpdateOperation))
#7 /srv/users/serverpilot/apps/foobar/craft/vendor/composer/composer/src/Composer/Installer.php(588): Composer\Installer\InstallationManager->execute(Object(Composer\Repository\InstalledFilesystemRepository), Object(Composer\DependencyResolver\Operation\UpdateOperation))
#8 /srv/users/serverpilot/apps/foobar/craft/vendor/composer/composer/src/Composer/Installer.php(227): Composer\Installer->doInstall(Object(Composer\Repository\InstalledFilesystemRepository), Object(Composer\Repository\CompositeRepository), Object(Composer\Repository\PlatformRepository), Array)
#9 /srv/users/serverpilot/apps/foobar/craft/vendor/craftcms/cms/src/services/Composer.php(139): Composer\Installer->run()
#10 /srv/users/serverpilot/apps/foobar/craft/vendor/craftcms/cms/src/controllers/BaseUpdaterController.php(132): craft\services\Composer->install(Array, Object(Composer\IO\BufferIO))
#11 [internal function]: craft\controllers\BaseUpdaterController->actionComposerInstall()
#12 /srv/users/serverpilot/apps/foobar/craft/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#13 /srv/users/serverpilot/apps/foobar/craft/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#14 /srv/users/serverpilot/apps/foobar/craft/vendor/craftcms/cms/src/web/Controller.php(103): yii\base\Controller->runAction('composer-instal...', Array)
#15 /srv/users/serverpilot/apps/foobar/craft/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('composer-instal...', Array)
#16 /srv/users/serverpilot/apps/foobar/craft/vendor/craftcms/cms/src/web/Application.php(273): yii\base\Module->runAction('updater/compose...', Array)
#17 /srv/users/serverpilot/apps/foobar/craft/vendor/craftcms/cms/src/web/Application.php(521): craft\web\Application->runAction('updater/compose...', Array)
#18 /srv/users/serverpilot/apps/foobar/craft/vendor/craftcms/cms/src/web/Application.php(257): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#19 /srv/users/serverpilot/apps/foobar/craft/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#20 /srv/users/serverpilot/apps/foobar/public/index.php(21): yii\base\Application->run()
#21 {main}

@lukeyouell have you set https://secure.php.net/manual/en/opcache.configuration.php#ini.opcache.restrict-api to ""?

Looks like the yii2-composer repo hasn't tagged a new release with the fix yet.

@angrybrad no we haven't, we didn't last time either and it hasn't been an issue again up until now. So I guess something must have changed.

We can definitely implement a workaround. I just thought I'd make yourselves aware as this is on a standard Serverpilot setup, so others will probably be seeing the same problem.

I've also seen this error when installing fresh Craft 3 projects on environments running serverpilot. The issue seems to be serverpilot for me as I created the app to run on PHP 7.1, but there is a setting on PHP 7.2 forcing the opcache.restrict_api setting. I had to log in as root and then edit the file at /etc/php7.2-sp/conf.d/opcache.ini Here I saw the following:

# The value of opcache.restrict_api is the path prefix of scripts allowed to
# call opcache API functions: http://php.net/manual/en/ref.opcache.php
# Set the value as needed or comment out the line to allow all scripts to use
# the opcache API functions.
opcache.restrict_api=/restricted

I just commented out the final line and saved the file. I then ran sudo service php7.2-fpm-sp restart as root and attempted the Craft install again via composer. This time it all worked fine and without issue. All other versions of PHP didn't have this setting in, only 7.2 which I wasn't even using as I had selected 7.1. I hope that helps you though @lukeyouell and for that matter anybody else who is using serverpilot.

@matt-adigital yeah don't get me wrong I know how to fix it, I just think that installing/updating craft on serverpilot shouldn't require you to start messing with the default php settings. Serverpilot is the setup of choice for a lot of people.

This hasn't been a problem since 3.0.5 until now, so something must have changed.

They tagged a new release with this fix, so in most cases, it should be as simple as running composer update from the command line from your project's root to pull in the fixed dependency.

@angrybrad No joy. The error is still thrown.

For anyone else running into this issue with Serverpilot the quick solution without having to change your PHP settings is to use php 7.1 to run composer, like so:

composer7.1-sp update

Both suggestions worked for me. Thank you all for opening this thread and contributing. It's been a great help.

I'm running php7.2 using a SeverPilot setup. I followed what @lukeyouell said, and I ran composer7.2-sp update It seems to work after modifying the composer.json file to use the latest version of craftcms3. The command line still shows the error when running the update, since I did not bother to modify the PHP settings as @matt-adigital pointed out. From what I gathered on the web is that changing the setting could possibly not be in the best interest for security reasons. But ultimately I decided to just go ahead with changing the settings since I'm on a staging server right now and I'd like to use the update feature from the Craft dashboard without any issues.

@angrybrad @brandonkelly is there any update with this?

Not only does this error mean that we can't update the CMS from the CP, but running composer update now reverts our version of Craft back to 3.0.12 from 3.0.13.2

image

Running composer update again returns Nothing to install or update even though the latest version is 3.0.16.1

It looks like the whole Zend OPcache issue has messed up the composer.json files in our installations.

@lukeyouell Can you share your project's composer.json file? You can send it to [email protected] if you don't want to share it publicly.

@angrybrad I don't mind sharing here, it looks like this issue is helping others out so it might provide some use!

Project 1: Issue when installing

So, this is the composer.json file from my local environment:

{
  "name": "foobar",
  "description": "",
  "version": "1.2.1",
  "keywords": [
    "craft",
    "cms",
    "craftcms",
    "project"
  ],
  "license": "MIT",
  "type": "project",
  "require": {
    "craftcms/cms": "^3.0.0",
    "vlucas/phpdotenv": "^2.4.0",
    "craftcms/mailgun": "^1.2.0",
    "craftcms/redactor": "2.1.2",
    "craftcms/aws-s3": "^1.0.8",
    "craftcms/contact-form": "2.2.2",
    "verbb/expanded-singles": "^1.0.3",
    "craftcms/contact-form-honeypot": "^1.0.2",
    "nystudio107/craft-minify": "1.2.9",
    "nystudio107/craft-typogrify": "1.1.11",
    "ether/simplemap": "v3.3.3",
    "verbb/super-table": "2.0.7",
    "dukt/twitter": "^2.0.1",
    "rias/craft-width-fieldtype": "1.0.5",
    "lukeyouell/craft-emailvalidator": "1.0.4",
    "verbb/image-resizer": "2.0.3",
    "rias/craft-position-fieldtype": "1.0.13"
  },
  "autoload": {
    "psr-4": {
      "modules\\": "modules/"
    }
  },
  "config": {
    "optimize-autoloader": true,
    "platform": {
      "php": "7.0"
    }
  },
  "scripts": {
    "post-root-package-install": [
      "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
      "@php craft setup/welcome",
      "@php marlo welcome"
    ]
  }
}

I then uploaded the project to the Serverpilot app running PHP 7.2 before running composer install which throws this error:

image

Running composer7.1-sp install uses PHP 7.1 and works as expected.

Project 2: Issue when updating from the CP

Due to updating via the CP the craftcms/cms value is 3.0.12 (no ^) which means that running composer update has no effect without editing composer.json first.

{
  "name": "craftcms/craft",
  "description": "Craft CMS",
  "keywords": [
    "craft",
    "cms",
    "craftcms",
    "project"
  ],
  "license": "MIT",
  "homepage": "https://craftcms.com/",
  "type": "project",
  "support": {
    "email": "[email protected]",
    "issues": "https://github.com/craftcms/cms/issues",
    "forum": "https://craftcms.stackexchange.com/",
    "source": "https://github.com/craftcms/cms",
    "docs": "https://craftcms.com/docs",
    "rss": "https://craftcms.com/changelog.rss"
  },
  "require": {
    "php": ">=7.0.0",
    "craftcms/cms": "3.0.12",
    "vlucas/phpdotenv": "^2.4.0",
    "roave/security-advisories": "dev-master",
    "craftcms/mailgun": "1.2.0",
    "craftcms/contact-form": "2.1.1",
    "craftcms/aws-s3": "1.0.8",
    "craftcms/redactor": "2.1.0",
    "ether/simplemap": "3.3.3",
    "lukeyouell/craft-sentry": "1.3.3"
  },
  "autoload": {
    "psr-4": {
      "modules\\": "modules/"
    }
  },
  "config": {
    "optimize-autoloader": true,
    "platform": {
      "php": "7.0"
    }
  },
  "scripts": {
    "post-root-package-install": [
      "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
      "@composer dump-autoload -o",
      "@php craft setup/welcome"
    ]
  }
}

Updating from the CP gives the following error:

image

Hopefully this helps!

@lukeyouell

Project 1

Installing yiisoft/yii2-composer (2.0.7)

That's our dependency that was causing the issue and 2.0.7 is the release with the fix in it (https://github.com/yiisoft/yii2-composer/releases/tag/2.0.7), so my guess is you've got a plugin installed that either directly or indirectly has a dependency with the exact same issue? You could search your entire project (including dependencies) for opcache* and see if there are any calls to things like opcache_invalidate that aren't suppressing PHP errors with an @ in front of it (i.e. @opcache_invalidate).

Project 2

Guessing if you change your requires section to this:

"require": {
    "php": ">=7.0.0",
    "craftcms/cms": "^3.0.12",
    "vlucas/phpdotenv": "^2.4.0",
    "craftcms/mailgun": "^1.2.0",
    "craftcms/contact-form": "^2.1.1",
    "craftcms/aws-s3": "^1.0.8",
    "craftcms/redactor": "^2.1.0",
    "ether/simplemap": "^3.3.3",
    "lukeyouell/craft-sentry": "^1.3.3"
  },

Then run composer update from the command line, it won't be an issue for you going forward.

Just ran in to this today installing Craft on a new ServerPilot server, running PHP 7.1.

composer7.1-sp install seems to have worked.

@angrybrad I couldn't find any external plugin/package files that use opcache

image

@lukeyouell any chance you could send some CP/SSH access to that box over to [email protected] so we can poke around a bit?

I'm still getting this problem - ServerPilot set to use PHP 7.1. The fix above about commenting out the restricted line in the php7.2 folder works, but I'm presuming this isn't the way it's meant to work?

For anyone else running into this issue with Serverpilot the quick solution without having to change your PHP settings is to use php 7.1 to run composer, like so:

composer7.1-sp update

This thread was a lifesaver. Still getting this error on SP

Still happening on ServerPilot, PHP 7.1. Can I give any more info to anyone to help fix it?

@darylknight I'm not familiar with how ServerPilot has set things up, but the gist of it is whatever php.ini file the version of PHP you're trying to run needs to have https://secure.php.net/manual/en/opcache.configuration.php#ini.opcache.restrict-api set to an empty string ""

Ok, thanks Brad!

running into this issue now too

I just ran into this issue as well. Running composer7.1-sp update worked for me.

I got running php7.2 with modifying /etc/php7.2-sp/conf.d/opcache.ini works.
But php7.3 with modifying /etc/php7.3-sp/conf.d/opcache.ini errors.

@watarutmnh Did you restart the service after changing the file?

sudo service php7.3-fpm-sp restart

Works for me after a restart.

Excuse me not responding for long time.
sudo service php7.3-fpm-sp restart doesn't work for me still..

Mine works immediately without restarting. If you're getting errors, you may have a syntax error in the change you made. Here's my opcache.ini:

```zend_extension=opcache.so
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=0
opcache.validate_permission=1
opcache.huge_code_pages=1

The value of opcache.restrict_api is the path prefix of scripts allowed to

call opcache API functions: http://php.net/manual/en/ref.opcache.php

Set the value as needed or comment out the line to allow all scripts to use

the opcache API functions.

opcache.restrict_api=/restricted

```

Is there nothing P&T can do about this? I don't really like having to change default PHP settings every time we start a new project, or we update the PHP version on an old one. I'm assuming opcache.restrict_api is there for a reason.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RitterKnightCreative picture RitterKnightCreative  路  3Comments

davist11 picture davist11  路  3Comments

timkelty picture timkelty  路  3Comments

angrybrad picture angrybrad  路  3Comments

mattstein picture mattstein  路  3Comments