<p>The error message you're getting indicates that the <a href="https://craftcms.com/docs/4.x/config/general.html#allowadminchanges" rel="nofollow noreferrer"><code>allowAdminChanges</code> configuration option</a> is set to <code>false</code>, which means no configuration changes are allowed. This is the default in a production environment. It's meant to ensure that no unsupervised changes happen in the production environment, so you can always cleanly deploy changes from your development environment.</p>
<p>You usually don't need to do anything to handle this in your plugin. Plugin installations are only allowed in environments where admin changes are allowed. If someone tries to install a plugin in an environment where admin changes are not allowed, getting this error message is the correct behaviour.</p>
<p>However, the installation hook also runs in the production environment, since some operations, like creating database tables, need to happen in all environments where the plugin is installed. But all configuration changes should have already been done in the development environment once the installation hook runs in the production environment. If your installation hook performs any configuration changes, those should indeed only happen when the plugin is installed in a development environment. You can check if admin changes are allowed using the general config service:</p>
<pre class="lang-php prettyprint-override"><code>if (\Craft::$app-&gt;config-&gt;general-&gt;allowAdminChanges) { }
</code></pre>
<p>If you're getting the error message in your development environment, change the configuration for this environment. You want to allow admin changes in development. The starter project uses <a href="https://github.com/craftcms/craft/blob/main/.env.example.dev" rel="nofollow noreferrer">environment variables</a> for changes that should differ between environments, so you can keep the configuration under version control and still have different settings depending on the environment.</p>

CC BY-SA 4.0
2023-01-24T13:54:43.053Z
2023-01-24T14:03:56.550Z
2023-01-24T14:03:56.550Z
MoritzLost
<p>I have written a plugin and it listens to different events to run some tasks. Now if the app is in &quot;read-only mode&quot;, I do not want some of these events to run:</p>
<pre class="lang-php prettyprint-override"><code>class MyPlugin extends Plugin
{
    public function init()
    {
        if (&lt;NOT in read-only mode&gt;) {
            Event::on(Plugins::class, Plugins::EVENT_AFTER_INSTALL_PLUGIN, function (PluginEvent $event) {
                // Do stuff when NOT in read-only mode
            });
        }

        // Always do this stuff
        Event::on(...., ..., fn () =&gt; ...);
    }
}
</code></pre>
<p>What's the value/setting to check for &quot;&lt;NOT in read-only mode&gt;&quot;?</p>

CC BY-SA 4.0
2023-01-24T09:33:05.787Z
What do you mean by read-only mode? There's [ephemeral mode](https://craftcms.com/docs/4.x/config/#craft-ephemeral) for when Craft is running on non-persistent file storage, in this case it doesn't write any files, do you mean that?
MoritzLost
CC BY-SA 4.0
2023-01-24T13:37:02.597Z
I'm getting an error from the environment it is ran on: `error: Changes to the project config are not possible while in read-only mode.`. I think it has to do with allowing changes by the admin? I guess ephemeral mode is also one to check in the same if-statement.
7ochem
<plugin-development><events><craft4>
How to check read-only mode in plugin?
# How to check read-only mode in plugin?

(Asked by: username_0 on 2023-01-24)

I have written a plugin and it listens to different events to run some tasks. Now if the app is in "read-only mode", I do not want some of these events to run:
class MyPlugin extends Plugin
{
    public function init()
    {
        if () {
            Event::on(Plugins::class, Plugins::EVENT_AFTER_INSTALL_PLUGIN, function (PluginEvent $event) {
                // Do stuff when NOT in read-only mode
            });
        }

        // Always do this stuff
        Event::on(...., ..., fn () => ...);
    }
}

What's the value/setting to check for ""?

**Tags:** plugin-development, events, craft4
> **Comments:**
> **username_1**: What do you mean by read-only mode? There's [ephemeral mode](https://craftcms.com/docs/4.x/config/#craft-ephemeral) for when Craft is running on non-persistent file storage, in this case it doesn't write any files, do you mean that?  
> **username_0**: I'm getting an error from the environment it is ran on: `error: Changes to the project config are not possible while in read-only mode.`. I think it has to do with allowing changes by the admin? I guess ephemeral mode is also one to check in the same if-statement.  

---

## 1 answers

### Answer by username_1 on 2023-01-24. Score: 3 | Accepted answer

The error message you're getting indicates that the allowAdminChanges configuration option is set to false, which means no configuration changes are allowed. This is the default in a production environment. It's meant to ensure that no unsupervised changes happen in the production environment, so you can always cleanly deploy changes from your development environment.
You usually don't need to do anything to handle this in your plugin. Plugin installations are only allowed in environments where admin changes are allowed. If someone tries to install a plugin in an environment where admin changes are not allowed, getting this error message is the correct behaviour.
However, the installation hook also runs in the production environment, since some operations, like creating database tables, need to happen in all environments where the plugin is installed. But all configuration changes should have already been done in the development environment once the installation hook runs in the production environment. If your installation hook performs any configuration changes, those should indeed only happen when the plugin is installed in a development environment. You can check if admin changes are allowed using the general config service:
if (\Craft::$app->config->general->allowAdminChanges) { }

If you're getting the error message in your development environment, change the configuration for this environment. You want to allow admin changes in development. The starter project uses environment variables for changes that should differ between environments, so you can keep the configuration under version control and still have different settings depending on the environment.


---

