A VPS is a blank canvas. After the initial security steps (SSH keys, firewall, disabling root password login), a web server is the most common next addition. Nginx is lightweight, fast, and powers a large share of the web. This guide takes you from zero to a running website with HTTPS on Ubuntu.
Installing Nginx
apt update apt install nginx -y systemctl enable nginx systemctl start nginx
Open a browser and go to your VPS IP address. You should see the default Nginx welcome page. That confirms the web server is running and reachable.
Opening the firewall
If you use UFW (which you should after following a basic VPS security guide):
ufw allow 'Nginx Full'
This opens port 80 (HTTP) and port 443 (HTTPS). If you only want HTTPS, use ufw allow 'Nginx HTTPS' instead, but during initial setup you need HTTP for the Certbot verification step.
Installing PHP
Most web applications need PHP. On Ubuntu 24.04:
apt install php8.3-fpm php8.3-mysql php8.3-curl php8.3-mbstring php8.3-xml php8.3-zip -y
The modules you install depend on your application. WordPress requires php-mysql, php-gd, php-curl and php-mbstring. Laravel also needs php-xml and php-zip. If you are only hosting static HTML, skip PHP entirely.
Configuring your site
Create a configuration file for your domain:
nano /etc/nginx/sites-available/mysite
Contents:
server {
listen 80;
server_name example.com www.example.com;
root /var/www/mysite;
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/php8.3-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Enable the site and test the configuration:
ln -s /etc/nginx/sites-available/mysite /etc/nginx/sites-enabled/ nginx -t systemctl reload nginx
The nginx -t command checks for syntax errors before reloading. If it reports errors, fix them before reloading. A reload with broken config takes the entire web server down.
SSL with Certbot (Let's Encrypt)
HTTPS is not optional. Browsers mark HTTP sites as insecure and search engines rank them lower.
apt install certbot python3-certbot-nginx -y certbot --nginx -d example.com -d www.example.com
Certbot automatically modifies your Nginx configuration to serve HTTPS and sets up a renewal timer. Certificates are valid for 90 days and renew automatically. You can verify the renewal timer with systemctl list-timers | grep certbot.
Uploading your site files
Create the document root and set permissions:
mkdir -p /var/www/mysite chown -R www-data:www-data /var/www/mysite
Upload your files via SFTP (FileZilla, WinSCP) or from the terminal with scp or rsync. The www-data user must own the files, or PHP will not be able to read them.
Adding MariaDB for a database
Most web applications need a database:
apt install mariadb-server -y mysql_secure_installation
Create a database and user:
mysql -e "CREATE DATABASE mydb;" mysql -e "CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'strongpassword';" mysql -e "GRANT ALL ON mydb.* TO 'myuser'@'localhost';" mysql -e "FLUSH PRIVILEGES;"
Replace strongpassword with an actual strong password. Never use the MariaDB root account for your application.
Multiple sites on one VPS
Each site gets its own Nginx config file in /etc/nginx/sites-available/, its own document root under /var/www/, and its own Certbot certificate. The process is the same as above, repeated for each domain. Nginx routes incoming requests to the correct site based on the server_name directive.
Performance tuning basics
For small sites you rarely need to touch the default Nginx config. As traffic grows, a few settings help:
- worker_processes: set to
auto(the default on most installs). Nginx then uses one worker per CPU core. - gzip: enable gzip compression for text-based files (HTML, CSS, JavaScript, JSON). This reduces bandwidth and speeds up page loads. Add
gzip on;andgzip_types text/plain text/css application/json application/javascript;to the http block. - client_max_body_size: the default is 1 MB. If your application accepts file uploads, increase this in the server block, for example
client_max_body_size 64m;.
Can I use Apache instead of Nginx?
Yes. Apache works fine and has a longer track record with .htaccess files and mod_rewrite. Nginx is lighter on memory and faster for static files. Choose Apache if you work with software that explicitly requires it. For everything else, Nginx is the modern default.
How many websites can a VPS handle?
That depends on the memory and traffic. A VPS with 2 GB of RAM comfortably runs 5 to 10 small websites. Each site gets its own Nginx config and directory. The bottleneck is usually PHP memory usage during traffic spikes, not Nginx itself.
Can I install WordPress on this setup?
Yes. After Nginx, PHP and MariaDB are in place, download WordPress, extract it into the site directory and follow the browser-based installer. The entire procedure takes about 15 minutes.
All KVM VPS plans at HostValues come with full root access, so you can install any web server stack you want.