-
Choose VPS provider, or use your own. This setup currently uses the Oracle cloud VPS which provides an ARM Ubuntu instance.
- Keep in mind if a system that is other than Ubuntu on ARM is used, the docker files will need altering to reflect this.
-
Choose DNR (Domain Name Registrar). This setup currently uses the Cloudflare service.
-
SSH into your VPS (search and follow a guide if you don't know how to set this up)
-
Either manually copy the project or clone it in the home directory (just type
cdto get there) from Github by first setting your global name and username withgit config --global user.name "Mona Lisa"andgit config --global user.email "MonaLisa@example.com"- Then authenticate to github by generating ssh keys guide
-
Install certbot and its dependencies with
sudo apt install python3 python3-certbot python3-certbot-nginx python3-venv libaugeas0 -
Use ufw or another firewall service to open the needed ports, remember if you are using a VPS to also open these ports on the subnet/security system on there too. We only require the subnet to add the http and https ports be open (80 and 443). Ensure that if this is a server you don't have physical access to that you enable port 22 on the firewall service before applying any rule changes.
- For example with ufw it is
sudo apt install ufwsudo ufw allow 443 && sudo ufw allow 80 && sudo ufw allow 22 && sudo systemctl enable ufwthis opens the https, http and ssh ports respectively- Check if ufw was really enabled by typing
sudo systemctl status ufwand if there are all greens/enabled signs then it is fine, otherwise retry withsudo systemctl enable ufw - Sometimes you have to reboot the VPS to get the firewall properly active by doing
sudo reboot
- For example with ufw it is
-
Install nginx with
sudo apt install nginx- Create the nginx config file for your site using
sudo touch /etc/nginx/sites-available/your_optional_subdomain.your_domain_name.domain_extension- for this project I am currently deploying on a subdomainsar2with the domain nameandreasmaitaand the domain extension.comwhich comprisessar2.andreasmaita.com. Assume all further instructions with this domain can be replaced with your domain. - Paste in your configuration, the current one is:
- Create the nginx config file for your site using
server {
listen 80;
server_name sar2.andreasmaita.com;
# Let's Encrypt verification must come BEFORE any redirects
location /.well-known/acme-challenge/ {
root /var/www/html;
}
# Redirect all HTTP traffic to HTTPS
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name sar2.andreasmaita.com;
ssl_certificate /etc/letsencrypt/live/sar2.andreasmaita.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/sar2.andreasmaita.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
# Frontend - Proxy to Vite dev server
location / {
proxy_pass http://localhost:5173;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# WebSocket support (required for hot module reload)
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
# Backend - Proxy API requests to Laravel/PHP backend
location /api/ {
proxy_pass http://localhost:8000/api/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
-
- Create a symbolic link to the config file using
sudo ln -s /etc/nginx/sites-available/sar2.andreasmaita.com /etc/nginx/sites-enabled/ - Restart nginx with
sudo systemctl restart nginx - Run certbot and register your certificates with liveencrypt using
sudo certbot --nginx -d sar2.andreasmaita.com - Install SSL certificates such that your site can use secure HTTPS instead of just HTTP with
sudo certbot install --cert-name sar2.andreasmaita.com - Update your nginx config file for your domain such that it handles SSL encryption and allows HTTPS connection by adding the following to the end of your previous nginx configuration
- Create a symbolic link to the config file using
- Install docker and docker-compose using the instructions at guide
- Either re-log into the system or run
newgrp dockerto refresh permissions
- Either re-log into the system or run
- Make sure the backend and other ports needed for the project are exposed with
sudo ufw allow <port_number>e.g. port 8000 for php + python backend - Go to the
SAR-Repodirectory and run the project usingdocker-compose up -d, or instead I personally like the auto attach feature of usingdocker-compose up --build - If there are any issues with the docker environment or containers, attempt to reset the containers and everything with these commands
docker-compose down --volumes --remove-orphans && docker system prune -fand then run the command from the previous step