Deploy from Git
Custom PHP, Laravel, Node.js and static applications can be deployed from a Git repository. Each deploy builds a new release on the server and switches the application to it in one step. Earlier releases are kept, so you can roll back.
Open the application and go to Deployments in its menu. Other application types don’t have this section. Once a repository is connected, the Deploy button at the top of the application’s page deploys the latest commit of the branch.
Connect a repository
Section titled “Connect a repository”- Click Connect a repository.
- Choose the Provider: GitHub, GitLab or Bitbucket.
- Under Repository address, paste the repository’s SSH address, such as
git@github.com:owner/repository.git. Its HTTPS address works too: Netkeel still fetches the code over SSH with the deploy key. The address must be on the provider you chose. - Type the Branch to deploy, such as
main. - Check the Preset. It starts from the application’s type and fills in the fields below. You can change any of them:
- Publish directory: the folder visitors are served from, such as
publicordist. Leave it empty for the repository root. A Laravel application always needs one, normallypublic. - Releases to keep: 2 to 10. It starts at 5, or at 3 on a server with 25 GB of disk or less. Older releases are removed; you can roll back to the ones kept.
- Build commands: one per line, up to 10. They run in the new release, as the application’s own user, before it goes live.
- Shared paths: one per line, up to 20. Files and folders kept between releases, such as uploads,
.envorstorage. - Build variables: one per line, up to 50. The names of environment variables your build commands need. Builds always see
VITE_*,NEXT_PUBLIC_*,NUXT_PUBLIC_*,PUBLIC_*,APP_ENVandNODE_ENV; list any other variable here. Its value comes from the application’s environment variables.
- Publish directory: the folder visitors are served from, such as
- Click Connect repository.
Netkeel sets up the repository on the server and creates its deploy key. Until your first deploy, the application keeps serving the files it already had. Those files are kept as Files from before Git deploy in Deployment history, so you can roll back to them. On the first deploy, any shared paths (such as .env or storage) that already exist in them are carried into the shared folder.
Which presets each type offers
Section titled “Which presets each type offers”- PHP and Laravel applications: PHP or Laravel.
- Node.js applications: Node.js.
- Static applications: Static.
On PHP, Laravel and static applications, Node.js is available to the build when a build command uses npm, npx or node. A Node.js application builds with its own Node.js version.
What each preset fills in
Section titled “What each preset fills in”| Preset | Build commands | Shared paths | Publish directory |
|---|---|---|---|
| Static | None | None | Repository root |
| PHP | None | None | Repository root |
| Laravel | composer install --no-dev --optimize-autoloader --no-interaction, if [ -f package.json ]; then npm ci; fi, if [ -f package.json ]; then npm run build --if-present; fi |
.env, storage |
public |
| Node.js | npm ci, npm run build --if-present |
.env |
Repository root |
A Node.js repository without package-lock.json (or npm-shrinkwrap.json) runs npm install instead of npm ci, and the deploy log says so. Only a build command that is exactly npm ci is replaced; a command such as npm ci && npm run build runs as written and needs a lockfile.
The Laravel preset also builds your front-end assets, such as Vite’s: when the repository has a package.json, the two npm lines install its packages and run its build script after Composer. Without a package.json they do nothing. If the app has no front-end build, for example because you commit public/build or don’t use npm, you can delete the two npm lines.
With the Laravel preset you can also choose what runs under Before and after each deploy: Run php artisan migrate --force before the switch (off at first) and Cache config, routes and views before the switch (on at first).
Every preset except Node.js also has Check the application answers after the switch (on at first): Netkeel loads / after the switch and goes back to the previous release if it answers with a server error (5xx). The Static preset adds Single-page app, which answers index.html for paths that are not files.
Add the deploy key to your repository
Section titled “Add the deploy key to your repository”Once the repository is set up, the Deploy key card appears under Deployments, below the Repository card. The server uses this key to fetch your code and only needs to read the repository. Each application has its own deploy key.
- Click Copy key.
- Click Open the deploy key settings on GitHub (or GitLab, or Bitbucket).
- Add the key:
- GitHub: Settings › Deploy keys › Add deploy key. Give it a title, such as Netkeel, and leave Allow write access unticked.
- GitLab: Settings › Repository › Deploy keys › Add new key. Leave Grant write permissions to this key unticked.
- Bitbucket: Repository settings › Access keys › Add key. Access keys are always read-only.
Add the key to the same repository as the one on the Repository card.
Deploy
Section titled “Deploy”Under Deploy, click Deploy now. Netkeel builds the latest commit of the branch. To deploy a particular commit, type its hash (7 to 40 characters) under Commit first.
While it runs, the card shows each step: Fetching code, Running build commands, Running migrations (only when switched on), Caching config, routes and views (Laravel, when switched on), Switching to the new release, Checking the new release responds and Removing old releases. Click View log to follow the output.
If a build command, a migration or Laravel’s caches fail, the application stays on the release it was on. After the switch, a Node.js release must answer on the app’s health check path (see Node.js), and any other release must answer / without a server error; otherwise the application goes back to the previous release.
On a Laravel application with the queue worker on, the worker restarts on the new release after each deploy and rollback.
Deploy automatically on push
Section titled “Deploy automatically on push”Push to deploy builds and switches to each commit you push to the branch, with no click in Netkeel. It is off until you set it up.
- Under Push to deploy, click Create webhook.
- Copy the Webhook address and the Secret (on GitLab, the Secret token). The secret is shown only this once; if you lose it, click Replace webhook to get a new address and secret.
- Click Open the webhook settings on GitHub (or GitLab, or Bitbucket) and add the webhook:
- GitHub: Settings › Webhooks › Add webhook. Paste the address under Payload URL, choose application/json as the Content type, paste the secret under Secret, choose Just the push event and click Add webhook.
- GitLab: Settings › Webhooks › Add new webhook. Paste the address under URL and the secret under Secret token, tick Push events (you can limit them to your branch), keep SSL verification on and click Add webhook.
- Bitbucket: Repository settings › Webhooks › Add webhook. Give it a title, such as Netkeel, paste the address under URL and the secret under Secret, choose Repository push as the trigger and click Save.
- Click Done, then turn on Auto-deploy on push to your branch.
From then on, each push to the branch deploys its latest commit. Pushes to other branches, tags and other repositories are ignored. If you push while a deployment is running, Netkeel waits for it to finish, then deploys the newest commit of the branch once, however many pushes came in between.
Deployments started by a push show Push as their trigger in Deployment history, with the name of the person who pushed.
Recent deliveries
Section titled “Recent deliveries”Recent deliveries lists the last 20 messages your Git provider sent, with the time, event, branch, commit and what Netkeel did:
- Deployment started, then the deployment’s own status: Deploying, Deployed, Deployment failed or Deployment cancelled.
- Queued after the running deploy: a deployment was already running; the newest commit of the branch deploys when it finishes. These deliveries then show that deployment’s status, or Refused with the reason if it could not start.
- Ignored: not a push to your branch (a test delivery, a tag, another branch or repository), Auto-deploy on push is off, or the push is older than what is already live (for example a late or repeated delivery). The reason is shown under it.
- Refused: the push could not deploy now, for example while the server is being upgraded, the application is being moved, many deployments started in the last few minutes, or too many deliveries arrived in a minute. The reason is shown under it. Push again, click Deploy now, or redeliver it from your Git provider once the cause is gone: a refused delivery is tried again.
A push always deploys the newest commit of your branch and never takes the application back to an older one. To go back, use Roll back to this release in Deployment history, or deploy an older commit with Deploy now.
GitHub, GitLab and Bitbucket send a test delivery when you add the webhook. It shows here as Ignored, which means the webhook works.
Turn it off or replace the webhook
Section titled “Turn it off or replace the webhook”- Turn off Auto-deploy on push to stop deploying on push. Deliveries are still listed.
- Click Replace webhook if the address or secret may have leaked. The old ones stop working at once; update the webhook on your Git provider with the new ones.
- Click Remove to delete the webhook from Netkeel, then delete it on your Git provider too.
An application restored after it was deleted, or after its server was lost, doesn’t keep its webhook. Once the repository is set up again, create a new one.
Deployment history
Section titled “Deployment history”Deployment history lists every deploy with its commit, trigger (Manual, Push, Rollback, or Connected for the files from before Git deploy), start time, duration and status. The current release shows Live; earlier successful ones show Succeeded, and ones that did not go live show Failed. Live, with a warning means the release went live but a step after the switch failed; open its log to see which.
- Click Log to read a deploy’s output.
- Click Roll back to this release to switch the application back to an earlier successful deploy whose release is still kept. Nothing is rebuilt and no migrations run. For an older release, deploy its commit again instead. Database changes made by later deployments stay. If the older code needs the older database, use Restore database on the deployment whose migrations changed it.
Restore the database
Section titled “Restore the database”When migrations are switched on, Netkeel copies the application’s database before they run. On a Laravel application, open Database › Database restores and click Restore database on the copy you want. On a Custom PHP application using the Laravel preset, click Restore database on that deployment in Deployment history. Everything written to the database since then is lost, and a copy of the database as it is now is taken first. The live code doesn’t change; roll back too if it needs the older database.
Environment variables
Section titled “Environment variables”The Owner and Super admins can set environment variables once the repository is set up, on the Environment page of the type’s group: PHP › Environment, Laravel › Environment (.env), Node.js › Environment or Static site › Environment. They are written to .env in the shared folder of every release, and build commands can read them. A Node.js app restarts with them when you save. PHP and Laravel code reads the new file on its next request; with Laravel’s configuration cache on, saving rebuilds that cache. A static site uses them from the next deployment. Saving changes only the variables listed here; other lines already in shared/.env are kept.
Saved values are never shown again. To keep a value, leave it empty when you edit the list. Names use capital letters, numbers and underscores, and don’t start with a number. Each value is one line. You can set up to 100 variables. A few names, such as PATH and HOME, are set by the server and can’t be changed.
Change settings or disconnect
Section titled “Change settings or disconnect”Click Edit settings on the Repository card to change the branch, preset or any other field, then click Save settings.
Click Disconnect to stop deploying. The application keeps serving its current files. The deploy key is deleted from the server and the deployment history is removed from Netkeel. A Node.js application’s environment variables go back to the app itself, under Node.js › Environment.
Troubleshooting
Section titled “Troubleshooting”When a deploy fails, its error is shown under Deployment history. Click Log next to it to read the full output, including Git’s and your build’s own messages.
“Could not fetch branch” or “Permission denied (publickey)”
Section titled ““Could not fetch branch” or “Permission denied (publickey)””The deploy fails with Could not fetch branch main; check the repository address, the branch and that the deploy key is added to the repository. The log usually shows one of these messages from Git:
Permission denied (publickey): the repository doesn’t have this application’s deploy key.Repository not found: the repository address is wrong, or the key was added to a different repository.
To fix it:
- Go to Deployments and click Copy key on the Deploy key card.
- Click Open the deploy key settings on GitHub (or GitLab, or Bitbucket). Check that the page is for the repository shown on the Repository card, not another one.
- Check that the key listed there is the one on the Deploy key card. If it isn’t there, or is different, add the copied key.
- Click Deploy now again.
On GitHub, a deploy key belongs to one repository, and GitHub won’t let you add a key that is already used on another repository. Each Netkeel application has its own key, so if two applications deploy the same repository, add both applications’ keys to it.
Branch not found
Section titled “Branch not found”If the log shows couldn't find remote ref followed by the branch name, the branch doesn’t exist in the repository. Branch names are case sensitive. Click Edit settings, correct the Branch and click Save settings, or push the branch first.
Commit not found
Section titled “Commit not found”Commit … was not found in the repository means the hash under Commit isn’t in the repository. Check that the commit is pushed, or leave Commit empty to deploy the latest commit of the branch.
A build command failed
Section titled “A build command failed”A build command failed (exit 1): npm run build names the command that stopped the build. The application stays on the release it was on. Read the log to see why, run the same command on your computer, fix the problem in the repository, push it and deploy again.
A build that runs longer than 15 minutes, or runs out of memory, stops with The deploy stopped before it finished (time limit, memory limit or a crash).
The publish directory is not in the release
Section titled “The publish directory is not in the release”The publish directory dist is not in the release means the folder named under Publish directory doesn’t exist after the build. Check its name, and that a build command creates it.
Not enough free disk space
Section titled “Not enough free disk space”Not enough free disk space to unpack the release means the server’s disk is nearly full. Free up space or upgrade the server to a size with a bigger disk.
Laravel migrations can’t reach the database
Section titled “Laravel migrations can’t reach the database”If php artisan migrate failed says to use DB_HOST=localhost and DB_SOCKET=/run/mysqld/mysqld.sock, your DB_HOST is 127.0.0.1, which doesn’t work. Change it under Laravel › Environment (.env), or remove your DB_* variables so Netkeel adds the application’s own database settings. See Laravel.
A Node.js release did not pass its health check
Section titled “A Node.js release did not pass its health check”The history shows the deploy as Failed with Not switched to: the previous release is still live. The log ends with the health check’s result and the app’s last output. See Node.js.
Setting up the repository failed
Section titled “Setting up the repository failed”The Repository card shows why. A common reason is a releases or shared folder with files in it already in the application’s htdocs: rename or move it with the file manager. Then click Edit settings and Save settings to try again.
After restoring an application
Section titled “After restoring an application”An application restored after it was deleted, or after its server was lost, gets a new deploy key. The Repository card says Restored from a backup: save the settings to set Git deploy up again, then add the new deploy key to the repository. Click Edit settings, then Save settings, and add the new key from the Deploy key card.
Pushes don’t deploy
Section titled “Pushes don’t deploy”Check Recent deliveries under Push to deploy:
- Nothing is listed: your Git provider can’t reach Netkeel, or its webhook has the wrong address or secret. Open the webhook’s delivery log on your Git provider. A 404 answer means the address or the secret is wrong: click Replace webhook and paste the new address and secret into the webhook on your Git provider. On GitHub, the webhook must have a secret.
- Ignored, Auto-deploy on push is off: turn on Auto-deploy on push to your branch.
- Ignored, A push to …, not …: the push went to another branch. Push to the branch on the Repository card, or change the branch with Edit settings.
- Refused: read the reason under it, then push again or click Deploy now.
Submodules and large files
Section titled “Submodules and large files”Git submodules are not fetched, and files stored with Git LFS are not downloaded. Commit what the application needs to the repository itself, or install it with your build commands, for example with Composer or npm.