How to deploy Vapor app on Ubuntu 16.04 and run it in production

$ cd your-vapor-app-folder
$ git init
$ git remote add origin https://<your_name>@gitlab.com/<your_name>/vapor-app.git
$ git add .
$ git commit -m "Initial commit"
$ git push -u origin master
$ sudo apt-get install -y supervisor nginx
$ adduser <username>
Adding user `myappuser' ...Adding new group `myappuser' (1000) ...Adding new user `myappuser' (1000) with group `myappuser' ...Creating home directory `/home/myappuser' ...Copying files from `/etc/skel' ...
$ visudo
root    ALL=(ALL:ALL) ALL
root    ALL=(ALL:ALL) ALL
<username> ALL=(ALL:ALL) ALL
$ sudo adduser <username> www-data
$ sudo chown -R www-data:www-data /home/<username>/vapor-app
$ sudo chmod -R g+rwX /home/<username>/vapor-app
$ git clone https://<your_name>@gitlab.com/<your_name>/vapor-app.git
$ vapor build --release
$ .build/release/Run --env=production
$ nano /etc/supervisor/conf.d/vapor-app.conf
[program:vapor-app]
command=/home/myappuser/vapor-app/.build/release/Run serve --env=production
directory=/home/myappuser/vapor-app
user=<username>
stdout_logfile=/var/log/supervisor/%(program_name)-stdout.log
stderr_logfile=/var/log/supervisor/%(program_name)-stderr.log
$ supervisorctl reread
$ supervisorctl add vapor-app
$ supervisorctl start vapor-app
$ sudo systemctl status supervisor
$ sudo systemctl start supervisor
$ sudo systemctl stop supervisor
$ supervisorctl status
vapor-app                        RUNNING   pid 3762, uptime 0:02:09

Now let’s run it via nginx

$ sudo ufw enable
$ sudo ufw allow ssh
$ sudo ufw allow http
$ sudo ufw status
$ sudo nano /etc/nginx/sites-available/default
server {
listen 80 default_server;
listen [::]:80 default_server;
location / {
proxy_pass http://127.0.0.1:8080;
}
}
$ sudo service nginx restart

Congratulations 🎉 Now it work

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store