Hosting a site on your own VPS gives you full control and room to grow, and it is more approachable than it sounds. This walkthrough takes a fresh Ubuntu server to a live website with Nginx, PHP and free HTTPS. Commands are for Ubuntu or Debian; the steps are the same elsewhere.
Before you start
- A VPS you can reach over SSH. See Connecting to your Linux VPS over SSH.
- A domain you can point at the server.
- The security basics done first if this is a brand new box.
Step 1: Install Nginx
Nginx is a fast, lightweight web server:
sudo apt update
sudo apt install nginx -y
Visit your server's IP in a browser and you should see the default Nginx page. If a firewall is on, allow web traffic:
sudo ufw allow 'Nginx Full'
Step 2: Install PHP (for dynamic sites)
For WordPress or any PHP app, install PHP-FPM and the common extensions:
sudo apt install php-fpm php-mysql php-cli php-curl php-gd php-mbstring php-xml -y
A plain static HTML site can skip this step.
Step 3: Create your site directory
Keep each site in its own folder:
sudo mkdir -p /var/www/yourdomain.com
sudo chown -R $USER:$USER /var/www/yourdomain.com
Put your files there, or an index.html to test.
Step 4: Add an Nginx server block
Create /etc/nginx/sites-available/yourdomain.com with a basic config:
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
root /var/www/yourdomain.com;
index index.php index.html;
location / { try_files $uri $uri/ /index.php?$query_string; }
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php-fpm.sock;
}
}
Enable it and reload:
sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
nginx -t checks the config before you reload, so a typo never takes the site down.
Step 5: Point your domain
Add an A record for the domain to your server's IP. See How to point your domain to Vastrox. Wait for it to propagate, then load your domain in a browser.
Step 6: Add free HTTPS
Once the domain resolves to the server, secure it with a free certificate:
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
Certbot installs the certificate and sets up auto-renewal. Full details in How to get a free SSL certificate.
FAQ
Nginx or Apache?
Both work. Nginx is lighter and handles many connections efficiently, which is why it is the common choice for new setups. This guide uses Nginx.
Do I need PHP?
Only for dynamic sites like WordPress. A plain HTML or static site does not need it.
My domain shows the default Nginx page, not my site.
Your server block is not enabled, the root path is wrong, or DNS has not finished pointing at this server. Check those three in order.
Want the control of a VPS without the setup time? Pick a Vastrox VPS and we can configure the web stack for you.