# Module installer actions by composer scripts

**URL:** <https://discourse.laminas.dev/t/module-installer-actions-by-composer-scripts/2839>\
**Category:** Components & MVC\
**Tags:** laminas-mvc, laminas-modulemanager\
**Created:** [March 29, 2022, 4:32am UTC](https://discourse.laminas.dev/t/module-installer-actions-by-composer-scripts/2839 "2022-03-29T04:32:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![voltan](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/voltan/32/710_2.png) [@voltan](https://discourse.laminas.dev/u/voltan)\
**Post date:** [March 29, 2022, 4:32am UTC](https://discourse.laminas.dev/t/module-installer-actions-by-composer-scripts/2839/1 "2022-03-29T04:32:33Z")

</div>

Hello people

I want to add some actions for installing/updating/removing modules by composer, for example when anyone installs a module by composer, the installer creates a database and imports access information for RBAC to the database. in update process do new changes in database and more and same

I see I can use composer script like this

```auto
  "scripts": {
    "post-install-cmd": [
      "php -r 'if (file_exists(\"bin/post-install.php\")) include \"bin/post-install.php\";'"
    ],
    "post-update-cmd": [
      "php -r 'if (file_exists(\"bin/post-update.php\")) include \"bin/post-update.php\";'"
    ],
    "post-package-uninstall": [
      "php -r 'if (file_exists(\"bin/post-remove.php\")) include \"bin/post-remove.php\";'"
    ]
  },

```

I have some questions:  
1- Do you have any plan to add features like this for managing modules in MVC?  
2- What is the best practice?  
3- In `bin/post-install.php`, I run PHP codes out of MVC, If I write installer service in my modules and want to call it in this PHP file, it’s very hard and I have to load most of my written class in the file. Does any shortcut or method available for doing it?

thanks

---

<div class="post-metadata">

**Author:** ![Tyrsson](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/tyrsson/32/1664_2.png) [@Tyrsson](https://discourse.laminas.dev/u/Tyrsson)\
**Post date:** [April 7, 2022, 2:31pm UTC](https://discourse.laminas.dev/t/module-installer-actions-by-composer-scripts/2839/2 "2022-04-07T14:31:47Z")

</div>

I have been thinking that I wanted to do something similar, but am now wondering if it would be easier to accomplish it via adding console support.

---

<div class="post-metadata">

**Author:** ![voltan](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/voltan/32/710_2.png) [@voltan](https://discourse.laminas.dev/u/voltan)\
**Post date:** [April 8, 2022, 6:34am UTC](https://discourse.laminas.dev/t/module-installer-actions-by-composer-scripts/2839/3 "2022-04-08T06:34:42Z")

</div>

It’s a good idea, I had a problem running scripts via composer, too many dependencies are necessary.

did you have time to test it? its work for you?

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [April 8, 2022, 6:38am UTC](https://discourse.laminas.dev/t/module-installer-actions-by-composer-scripts/2839/4 "2022-04-08T06:38:36Z")

</div>

> [@voltan](#):
>
> …too many dependencies are necessary.

Use [laminas-cli](https://docs.laminas.dev/laminas-cli/) and you can use the entire service container of your application.

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [April 8, 2022, 6:40am UTC](https://discourse.laminas.dev/t/module-installer-actions-by-composer-scripts/2839/5 "2022-04-08T06:40:30Z")

</div>

> [@voltan](#):
>
> 1. Do you have any plan to add features like this for managing modules in MVC?

The current plan is to use CLI commands.

> [@voltan](#):
>
> 1. What is the best practice?
> 2. In `bin/post-install.php`, I run PHP codes out of MVC, If I write installer service in my modules and want to call it in this PHP file, it’s very hard and I have to load most of my written class in the file.

Use laminas-cli. (see my previous comment)

---

<div class="post-metadata">

**Author:** ![voltan](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/voltan/32/710_2.png) [@voltan](https://discourse.laminas.dev/u/voltan)\
**Post date:** [April 8, 2022, 8:11am UTC](https://discourse.laminas.dev/t/module-installer-actions-by-composer-scripts/2839/6 "2022-04-08T08:11:18Z")

</div>

Thank you very much, I work on it in the next few days

We start work on some new simple applications with laminas and worked on writing (converting) some modules to laminas.

My plan is to publish all of them as open-source, then I want all of them to be a standard for general usage by everyone

Best

---

<div class="post-metadata">

**Author:** ![Tyrsson](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/tyrsson/32/1664_2.png) [@Tyrsson](https://discourse.laminas.dev/u/Tyrsson)\
**Post date:** [April 8, 2022, 7:00pm UTC](https://discourse.laminas.dev/t/module-installer-actions-by-composer-scripts/2839/7 "2022-04-08T19:00:08Z")

</div>

Sorry I was short of time when I replied earlier. As @froschdesign pointed out the cli loads like any other component so you have access to everything you will need. Ive only barely tested it but from the initial testing I did it will work exactly as you need it too. I am 100% certain it will meet my needs, which is pretty much the same as yours.

---

<div class="post-metadata">

**Author:** ![voltan](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/voltan/32/710_2.png) [@voltan](https://discourse.laminas.dev/u/voltan)\
**Post date:** [April 10, 2022, 5:53pm UTC](https://discourse.laminas.dev/t/module-installer-actions-by-composer-scripts/2839/8 "2022-04-10T17:53:39Z")

</div>

Thank you very much, In next week I will start work on writing the installer on CLI.  
I just read CLI docs very short and I see it’s very useful. I can handle some of my problems by using it

thank you very much for help me @Tyrsson @froschdesign , I will tell you result
