PHPackages                             brunonatali/install - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. brunonatali/install

ActiveLibrary

brunonatali/install
===================

Provide installation capability to a repository.

v1.4(5y ago)0461MITPHPPHP &gt;=7.3

Since Jun 23Pushed 5y ago1 watchersCompare

[ Source](https://github.com/brunonatali/install)[ Packagist](https://packagist.org/packages/brunonatali/install)[ RSS](/packages/brunonatali-install/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (2)Versions (11)Used By (1)

Install
=======

[](#install)

Provide installation capability to a repository.

**Table of Contents**

- [Before start](#first)
    - [Folder structure](#folder-structure)
- [Quickstart example](#quickstart-example)
    - [Individual](#individual)
    - [All apps](#all-apps)
- [Executable program](#executable-program)
- [Post install script](#post-install-script)
- [Use pid file](#use-pid-file)
- [Select shell to use](#select-shell-to-use)
- [Restart on failure](#restart-on-failure)
- [Kill child process](#kill-child-process)
- [Require app](#require-app)
- [Require service](#require-service)
- [After service](#after-service)
- [Install](#install)
- [License](#license)

Before start
------------

[](#before-start)

Before you begin, consider reviewing your code and understanding that this is a tool for automating the installation of an application made in PHP to run on the CLI or as a service in a Linux environment.

Observe that if service was instaled this component will update .service file and perform a daemon-reload, and if is active (runing) before install starts, service will be autoatically started after instalation is finished.

Note. Not supported on Windows.

### Folder structure

[](#folder-structure)

Prepare the folder structure as shown below:

```
+-- installation
|   +-- install.php
|   +-- install-instructions.json
+-- pbin
|   +-- my_program_executable
+-- src
|   +-- YourClass.php
+-- post-install
|   +-- myScript.sh
+-- composer.json
```

Note. If you are unsure how to create your 'my\_program\_executable' go to [Executable program](#executable-program).

Quickstart example
------------------

[](#quickstart-example)

### Individual

[](#individual)

A common use is the individual installation of the application, for that, consider having the folder structure as shown in `Folder structure`.

- Let's create a simple configuration file, "installation / install-instructions.json":

```
{
    "sys-bin-files" : [
        "my_program_executable"
    ],
    "service" : [
        {
            "name" : "My1stProgram",
            "bin" : "my_program_executable",
            "control-by-pid" : true,
            "restart-on-abort" : true
        }
    ],
    "require" : [
        "program1",
        "program2"
    ],
    "post-installation" : "/../post-install/myScript.sh"
}
```

- Let's add a script for auto installation "installation / install.php":

```
use BrunoNatali\Install\Factory;

$myApp = new Factory( ["dir" => __DIR__] );

$myApp->install();
```

- Finally perform the installation:

```
$ php vendor/myname/appname/installation/install.php
```

This will make the contents of the "pbin" folder become executable, as well as create a service on the system with the name "My1stProgram" that will execute the file "my\_program\_executable".
At the end will call script myScript.sh (under /post-install), to do some adjusts that you need, like call other aplication, change some file attribute or remove. [Learn more](#post-install-script)
An "require" is a array that tell which apps your app depends.
Note that a symlink is created in "/usr/sbin", that way you can run the application by typing in the terminal:

```
$ my_program_executable
```

### All apps

[](#all-apps)

In this example, it is assumed that the folder structure shown in `Folder structure` and at least the configuration file "install-instructions.json" is created within all the applications you intend to install.

Within the Factory class there is a static function to make the installation of several applications very easy:

```
\BrunoNatali\Install\Factory::installAll()
```

The simplest and most direct way to perform the installation of all applications is to run the following command on the terminal:

```
$ sudo php -r "require 'vendor/autoload.php'; \BrunoNatali\Install\Factory::installAll();"
```

Is possible to skip some app installation (partially or entirely).
To do this, you need to pass an array with app name in key, as follows:

```
/**
 * Installation will be made in basic mode, no services or post scripts
 *  are done in this mode
*/
\BrunoNatali\Install\Factory::installAll( null, array(
    'appToNotInstall' => true  // Don`t metter the value
) );

/**
 * Installation will be entirely skipped
*/
\BrunoNatali\Install\Factory::installAll( null, array(
    'appToNotInstall' => 'force'  // Set value to 'force'
) );
```

Note. The need to run as root, as it will interact with systemd and create / update processes within the system.

Executable program
------------------

[](#executable-program)

An executable program considered for this tool basically contains:

```
#!/usr/bin/php
