Answers.Body: <p>The short answer is no. The long answer is sortof, if you’re running Craft 3.</p>
  
  <p>Since plugins are technically <a href="http://www.yiiframework.com/doc-2.0/guide-structure-modules.html" rel="nofollow noreferrer">modules</a> in Craft 3, you should be able to bootstrap a plugin onto the application just like any other module.</p>
  
  <p>To do that, update <code>config/app.php</code> with these <code>modules</code> and <code>bootstrap</code> sub-arrays:</p>
  
  
  
  <pre class="lang-php prettyprint-override"><code>return [
      'modules' =&gt; [
          'contact-form' =&gt; function() {
              $plugin = Craft::$app-&gt;plugins-&gt;createPlugin('contact-form');
              $plugin-&gt;setSettings([
                  'toEmail' =&gt; 'foo@bar.baz',
              ]);
              return $plugin;
          }
      ],
  
      'bootstrap' =&gt; [
          'contact-form',
      ],
  ];
  </code></pre>
  
  <p>Using <a href="https://github.com/craftcms/contact-form" rel="nofollow noreferrer">Contact Form</a> as an example. For a different plugin, replace all of the <code>'contact-form'</code> strings with the right plugin handle, and change the settings array to whatever the plugin is expecting. (You can find which settings keys the plugin supports by checking its Settings model – usually either <code>src/Settings.php</code> or <code>src/models/Settings.php</code>.)</p>
  
  <p>Some caveats off the top of my head, though:</p>
  
  <ul>
  <li>Craft won’t know that the plugin is installed, so it will still look like an uninstalled plugin in Settings → Plugins.</li>
  <li>You won’t be able to edit the plugin’s settings in the Control Panel; only from <code>config/app.php</code>.</li>
  <li>You won’t be able to update the plugin from the Control Panel; only via <code>composer update</code>.</li>
  <li>If the plugin has an <a href="https://github.com/craftcms/docs/blob/master/en/plugin-migrations.md#install-migrations" rel="nofollow noreferrer">install migration</a>, you will need to manually duplicate it as <a href="https://github.com/craftcms/docs/blob/master/en/content-migrations.md" rel="nofollow noreferrer">content migrations</a>. And whenever you update the plugin, you’ll need to check if it added any new migrations, and manually duplicate those as content migrations as well. (Any migrations that were there at the time you first installed the plugin, besides the Install migration, can be ignored.)</li>
  </ul>
  
  <p><strong>EDIT</strong></p>
  
  <p>If you just want to be able to install a plugin <em>programmatically</em>, but don’t mind if the plugin ends up getting a row in the <code>plugins</code> DB table, that’s easy. Just create a new <a href="https://github.com/craftcms/docs/blob/v3/en/content-migrations.md" rel="nofollow noreferrer">content migration</a>, with the following <code>safeUp()</code> function:</p>
  
  <pre class="lang-php prettyprint-override"><code>public function safeUp()
  {
      Craft::$app-&gt;plugins-&gt;installPlugin('plugin-handle');
  }
  </code></pre>
  
  <p>Then you just need to run the migration on each of your environments. You can either do that from Utilities → Migrations in the Control Panel, or by running the following CLI command:</p>
  
  <pre class="lang-php prettyprint-override"><code>./craft migrate/up
  </code></pre>
  
  <p>Maybe worth noting that you can also install plugins directly from the terminal, using this command:</p>
  
  <pre class="lang-php prettyprint-override"><code>./craft install/plugin &lt;plugin-handle&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-22T09:20:27.147Z
Answers.Text: Thanks for taking the time to answer Brandon - sounds it is possible like you say. I am just wondering if what I am trying to do would be possible with a migration just to add the record to the `plugins` table? There's probably a reason you haven't suggested this but that seems to be the only difference between an installed and uninstalled plugin?
Answers.UserDisplayName: Mike F
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-23T03:35:29.817Z
Answers.Text: @MikeF Sorry, I must have really misunderstood your question! Sounds like you just meant you want to install plugins _programatically_? Just added a second part to my answer for that.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-26T11:34:22.877Z
Answers.Text: Brandon - that's exactly what I was looking for! Thank you so much ❤️
Answers.UserDisplayName: Mike F
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-05T02:12:41.237Z
Answers.Text: content migration link is old, the new one: 
  https://docs.craftcms.com/v3/extend/migrations.html#creating-migrations
Answers.UserDisplayName: Visky Máté
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-21T19:09:10.790Z
Answers.LastActivityDate: 2018-01-23T03:34:01.033Z
Answers.LastEditDate: 2018-01-23T03:34:01.033Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>Is it possible to auto enable/install a plugin through config (or another way) rather than having to do this through the database?</p>
  
Tags: <plugins><config><craft3>
Title: Auto enable/install plugin through config
ThreadText: # Auto enable/install plugin through config
  
  (Asked by: username_0 on 2018-01-21)
  
  Is it possible to auto enable/install a plugin through config (or another way) rather than having to do this through the database?
  
  **Tags:** plugins, config, craft3
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-01-21. Score: 3 | Accepted answer
  
  The short answer is no. The long answer is sortof, if you’re running Craft 3.
  
  Since plugins are technically [modules](http://www.yiiframework.com/doc-2.0/guide-structure-modules.html) in Craft 3, you should be able to bootstrap a plugin onto the application just like any other module.
  
  To do that, update `config/app.php` with these `modules` and `bootstrap` sub-arrays:
  
  ```php
  return [
      'modules' => [
          'contact-form' => function() {
              $plugin = Craft::$app->plugins->createPlugin('contact-form');
              $plugin->setSettings([
                  'toEmail' => 'foo@bar.baz',
              ]);
              return $plugin;
          }
      ],
  
      'bootstrap' => [
          'contact-form',
      ],
  ];
  
  ```
  
  Using [Contact Form](https://github.com/craftcms/contact-form) as an example. For a different plugin, replace all of the `'contact-form'` strings with the right plugin handle, and change the settings array to whatever the plugin is expecting. (You can find which settings keys the plugin supports by checking its Settings model – usually either `src/Settings.php` or `src/models/Settings.php`.)
  
  Some caveats off the top of my head, though:
  
  * Craft won’t know that the plugin is installed, so it will still look like an uninstalled plugin in Settings → Plugins.
  * You won’t be able to edit the plugin’s settings in the Control Panel; only from `config/app.php`.
  * You won’t be able to update the plugin from the Control Panel; only via `composer update`.
  * If the plugin has an [install migration](https://github.com/craftcms/docs/blob/master/en/plugin-migrations.md#install-migrations), you will need to manually duplicate it as [content migrations](https://github.com/craftcms/docs/blob/master/en/content-migrations.md). And whenever you update the plugin, you’ll need to check if it added any new migrations, and manually duplicate those as content migrations as well. (Any migrations that were there at the time you first installed the plugin, besides the Install migration, can be ignored.)
  
  **EDIT**
  
  If you just want to be able to install a plugin *programmatically*, but don’t mind if the plugin ends up getting a row in the `plugins` DB table, that’s easy. Just create a new [content migration](https://github.com/craftcms/docs/blob/v3/en/content-migrations.md), with the following `safeUp()` function:
  
  ```php
  public function safeUp()
  {
      Craft::$app->plugins->installPlugin('plugin-handle');
  }
  
  ```
  
  Then you just need to run the migration on each of your environments. You can either do that from Utilities → Migrations in the Control Panel, or by running the following CLI command:
  
  ```php
  ./craft migrate/up
  
  ```
  
  Maybe worth noting that you can also install plugins directly from the terminal, using this command:
  
  ```php
  ./craft install/plugin <plugin-handle>
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks for taking the time to answer username_1 - sounds it is possible like you say. I am just wondering if what I am trying to do would be possible with a migration just to add the record to the `plugins` table? There's probably a reason you haven't suggested this but that seems to be the only difference between an installed and uninstalled plugin?  
  > **username_1**: @username_0 Sorry, I must have really misunderstood your question! Sounds like you just meant you want to install plugins _programatically_? Just added a second part to my answer for that.  
  > **username_0**: username_1 - that's exactly what I was looking for! Thank you so much ❤️  
  > **username_2**: content migration link is old, the new one:  https://docs.craftcms.com/v3/extend/migrations.html#creating-migrations  
  
  ---
  
  