{"title":"Manual Deploy","description":"","section":"deployment","version":"v1.5","path":"deployment/manual-deploy","canonical_url":"https://amberframework.org/docs/v1.5/deployment/manual-deploy","markdown_url":"https://amberframework.org/docs/v1.5/deployment/manual-deploy.md","inherited":true,"content_markdown":"# Manual Deploy\n\n## In your development machine:\n\n1. Open your production env file with `amber encrypt` then edit the database URL, and disable or enable logs. Also see [Encrypt](../cli/encrypt.md).\n2. If you have assets and you're using NPM, use `npm install . && npm run release` to compile/minify `.css` and `.js` files.\n\n## In your production machine:\n\n1. Install`crystal` and `shards` commands \\([See installation guide](https://crystal-lang.org/docs/installation/)\\). You can compile `bin/amber` tool using `shards build amber` in your production project to migrate your database.\n2. Then copy your project repository and ensure to setup `AMBER_ENCRYPTION_KEY` and `AMBER_ENV=production` in your environments variables. You can get your encryption key from `.encryption_key` file in your development machine. Then inside your project's folder, install your shards dependencies with `shards install --production` and compile your executable with `shards build <your-app> --release`.\n3. Finally run your project executable with `bin/<your-app>` .\n\n{% hint style=\"info\" %}\nAlso you can try to [cross-compile](https://crystal-lang.org/docs/syntax_and_semantics/cross-compilation.html) to avoid install these dependencies but this feature is a bit buggy on most OS.\n\n[Alpine Linux](https://store.docker.com/community/images/jrei/crystal-alpine) is great to use `crystal build --static` flag, though.\n{% endhint %}\n\n{% hint style=\"warning\" %}\nCompilation may take a while because `--release` enables compiler optimizations. You can avoid `--release` if you server is low end \\(less 256 RAM\\)\n\nAmber performance is still acceptable on non-release mode\n{% endhint %}\n\n{% hint style=\"danger\" %}\nYou may need sudo permission if you're using port 80 or ports &lt; 1000\n{% endhint %}\n\nYou can use `iptables` to redirect port 80 to 8080 or whatever port are you using in production.\n\n```text\niptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080\n```\n\nOptionally you can setup a system service to monitor your app very easy, and configure a `.git/hook/post-receive` to deploy like Heroku using `git push production` . Amber Team is already using a [systemd service ](https://github.com/amberframework/amberframework.org#systemd-service)to manage [Amber Framework Website](https://amberframework.org/) and the`post-receive` hook below to manage deployment using git.\n\n```bash\n#!/bin/bash\nset -e\n\nexport AMBER_ENV=production\n\nif [ \"$GIT_DIR\" = \".\" ]; then\n  # The script has been called as a hook; chdir to the working copy\n  cd ..\n  unset GIT_DIR\nfi\n\n# try to obtain the usual system PATH\nif [ -f /etc/profile ]; then\n  PATH=$(source /etc/profile; echo $PATH)\n  export PATH\nfi\n\n# get the current branch\nhead=\"$(git symbolic-ref HEAD)\"\n\n# read the STDIN to detect if this push changed the current branch\nwhile read oldrev newrev refname\ndo\n  [ \"$refname\" = \"$head\" ] && break\ndone\n\n# abort if there's no update, or in case the branch is deleted\nif [ -z \"${newrev//0}\" ]; then\n  exit\nfi\n\n# check out the latest code into the working copy\numask 002\ngit reset --hard\n\nlogfile=log/deploy.log\n\nif [ -z \"${oldrev//0}\" ]; then\n  # this is the first push; this branch was just created\n  mkdir -p log tmp bin\n  chmod 0775 log tmp bin\n  touch $logfile\n  chmod 0664 $logfile\n\n  # init submodules\n  git submodule update --recursive --init 2>&1 | tee -a $logfile\nelse\n  # log timestamp\n  echo ==== $(date) ==== >> $logfile\n\n  ################################################################################\n  ####  BEGIN: Amberframework specific Code                                  #####\n  ################################################################################\n\n  shards install\n\n  if [ -f bin/amber ]; then\n    echo \"amber already installed\"\n  else\n    crystal build lib/amber/src/amber/cli.cr -o bin/amber --stats\n  fi\n\n  echo \"Migrating...\"\n  ./bin/amber db create migrate || true\n  echo \"Building application in release mode\"\n  crystal build src/amberframework.cr -o bin/amberframework --release --stats\n  systemctl status amberframework\n  sudo systemctl restart amberframework\n  systemctl status amberframework\nfi\n```\n\nThen add your production repository to your development machine using `git remote add`\n\n```text\ngit remote add production <user>@<ip>:/home/<user>/<repository>\n```\n\n* `<user>` is a valid user with your public ssh key inside `~/.ssh/authorized_keys`\n* `<ip>` is your production machine IP \\(you can use a domain as well\\).\n* `<repository>` is your project with your`.git` folder inside."}