> For the complete documentation index, see [llms.txt](https://notes.d15r.de/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.d15r.de/dev/php/laravel/deploy.md).

# Deploy

Ich habe ein [Package](https://github.com/danielsundermeier/laravel-deploy) programmiert, damit ich es nicht immer neu einrichten muss.

## Controller

DeploymentController

```
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;

class DeploymentController extends Controller
{
    public function store(Request $request)
    {
        $githubPayload = $request->getContent();
        $githubHash = $request->header('X-Hub-Signature');

        $localToken = config('app.deploy_secret');
        $localHash = 'sha1=' . hash_hmac('sha1', $githubPayload, $localToken, false);

        // if (! hash_equals($githubHash, $localHash))
        // {
        //     return abort(404);
        // }

        if (! $githubHash)
        {
            return abort(404);
        }

        $root_path = base_path();
        $process = new Process('cd ' . $root_path . '; sh ./deploy.sh');
        $process->run();

        // executes after the command finishes
        if (!$process->isSuccessful())
        {
            throw new ProcessFailedException($process);
        }

        echo $process->getOutput();
    }
}
```

## Skript

deploy.sh

```
#!/bin/sh

echo "Deploying..."

git stash
git pull
mv .env.production .env
php artisan migrate --force
php artisan queue:restart
composer install  > /dev/null 2>&1 & echo $! #--no-interaction --no-dev --prefer-dist
npm install > /dev/null 2>&1 & echo $!
npm run production > /dev/null 2>&1 & echo $!

echo "Deployed"
```

## CSRF Token

[Disabling CSRF for Specific Routes - Laravel 5](https://www.camroncade.com/disable-csrf-for-specific-routes-laravel-5/)

VerifyCsrfToken.php

```
<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;

class VerifyCsrfToken extends Middleware
{
    /**
     * Indicates whether the XSRF-TOKEN cookie should be set on the response.
     *
     * @var bool
     */
    protected $addHttpCookie = true;

    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'deploy',
    ];
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://notes.d15r.de/dev/php/laravel/deploy.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
