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><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><your_name>/vapor-app.git
$ vapor build --release
$ .build/release/Run --env=production
$ nano /etc/supervisor/conf.d/vapor-app.conf
command=/home/myappuser/vapor-app/.build/release/Run serve --env=production
$ 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 / {
$ 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