Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Borichon's avatar

Zend OPcache API is restricted by "restrict_api" configuration directive

Hi everyone,

I'm working on a web project using the Laravel 11 framework, and everything works perfectly fine on my local machine. However, when I try to deploy it on my hosting server, I encounter the following error:

Zend OPcache API is restricted by "restrict_api" configuration directive

My composer.json is : { "name": "laravel/laravel", "type": "project", "description": "The skeleton application for the Laravel framework.", "keywords": ["laravel", "framework"], "license": "MIT", "require": { "php": "^8.2", "barryvdh/laravel-dompdf": "^3.0", "laravel/framework": "^11.9", "laravel/tinker": "^2.9", "livewire/livewire": "^3.4", "livewire/volt": "^1.0", "openspout/openspout": "^4.28", "power-components/livewire-powergrid": "^v6.1.7" }, "require-dev": { "fakerphp/faker": "^1.23", "laravel/breeze": "^2.2", "laravel/pint": "^1.13", "laravel/sail": "^1.26", "mockery/mockery": "^1.6", "nunomaduro/collision": "^8.0", "phpunit/phpunit": "^11.0.1" }, "autoload": { "psr-4": { "App\": "app/", "Database\Factories\": "database/factories/", "Database\Seeders\": "database/seeders/" } }, "autoload-dev": { "psr-4": { "Tests\": "tests/" } }, "scripts": { "post-autoload-dump": [ "Illuminate\Foundation\ComposerScripts::postAutoloadDump", "@php artisan package:discover --ansi" ], "post-update-cmd": [ "@php artisan vendor:publish --tag=laravel-assets --ansi --force" ], "post-root-package-install": [ "@php -r "file_exists('.env') || copy('.env.example', '.env');"" ], "post-create-project-cmd": [ "@php artisan key:generate --ansi", "@php -r "file_exists('database/database.sqlite') || touch('database/database.sqlite');"", "@php artisan migrate --graceful --ansi" ] }, "extra": { "laravel": { "dont-discover": [] } }, "config": { "optimize-autoloader": true, "preferred-install": "dist", "sort-packages": true, "allow-plugins": { "pestphp/pest-plugin": true, "php-http/discovery": true } }, "minimum-stability": "stable", "prefer-stable": true }

I’ve tried searching for solutions online, but I’m still unsure about the exact cause of the issue. Could anyone help me understand where this error is coming from?

Additionally, is it possible to disable the OPcache system easily, or is there any specific configuration I should adjust to make the project run on the server as it does locally?

Any help or suggestions would be greatly appreciated!

Thank you in advance!

0 likes
2 replies
RemiM's avatar

If you’re getting the error "Zend OPcache API is restricted by restrict_api configuration directive", then your hosting provider has set a value for opcache.restrict_api—even if you didn’t configure it yourself.

If you have access to php.ini you can check the value of opcache.restrict_api.

To confirm if opcache.restrcit_api is set, run:

php -i | grep opcache.restrict_api

If it outputs something like:

opcache.restrict_api => /var/www/secure_path

Then only scripts inside /var/www/secure_path can use OPcache API functions.

Solution?

  • If you control php.ini, try setting opcache.restrict_api="" and restart PHP (service php-fpm restart).
  • If you’re on shared hosting, you likely cannot change this—disable OPcache management in Laravel to avoid errors.
  • Be sure to check the official configuration documentation as well: Laravel OPcache Configuration.
Borichon's avatar

@RemiM Hi, Thanks for your reply

Sadly i didn't have acces to the php.ini on my shared hosting.

On this line of phpinfo : opcache.restrict_api = /home/ovh/fmp8.2/opcache-status.php

I have try to disable OPcache management but with no success.

Thanks again.

Please or to participate in this conversation.