Back to articles
Cloud VPS HostingAvertHostNovember 17, 202611 min read

Ubuntu Cloud Server: Deploy Nginx, PHP or Node.js with HTTPS

A hands-on guide to turning a hardened Ubuntu cloud server into a production web server: DNS, Nginx, PHP-FPM or a Node.js app under systemd, MySQL or PostgreSQL, free HTTPS with Certbot, and a go-live checklist.

An Ubuntu cloud server becomes a production web server in five steps: point your domain's DNS at it, install Nginx, add PHP-FPM or run your Node.js app as a systemd service, set up a local database, and switch on free HTTPS with Certbot. This guide walks through each step on Ubuntu 24.04 LTS (22.04 works with the small differences noted), with the commands to run and a check after each one.

It assumes the server is already hardened: a named sudo user, key-only SSH, ufw, fail2ban and automatic security updates. If you have not done that yet, follow how to set up a VPS: the first 30 minutes on Ubuntu first, then come back here.

Before you install: plan the stack, DNS and firewall

Runtime, database and hostnames

Decide three things up front, because they change the commands you run later.

  • Application runtime. PHP (WordPress, Laravel, a custom PHP app) runs through PHP-FPM behind Nginx. Node.js (Express, Next.js, NestJS) runs as its own process on a local port, with Nginx in front as a reverse proxy. You can run both on one server.
  • Database. MySQL or MariaDB for most PHP software, PostgreSQL if your framework or team prefers it. On a single server, the database listens only on localhost.
  • Domains. List every hostname the server will answer for, for example example.in, www.example.in and api.example.in. Each one needs a DNS record and must be on the HTTPS certificate.

A rough sizing guide (RECOMMENDATION, measure your own load before you commit):

WorkloadStarting pointWhat to watch
Company website, blog or small WordPress site2 vCPU, 4 GB RAMPHP-FPM worker count, database memory
Laravel or Node.js API with a local database2–4 vCPU, 4–8 GB RAMResponse time at peak, database buffer size
WooCommerce or a busy app with background jobs4 vCPU, 8 GB RAM or moreCPU during sales or batch runs, disk I/O

Our guide on choosing the right Linux VPS plan explains how to read these numbers. On a cloud server you can start small and resize when the metrics say so.

DNS records

At your DNS provider, create an A record for each hostname pointing to the server's public IPv4 address, and an AAAA record if the server has IPv6. Set a short TTL such as 300 seconds while you are migrating, so a mistake can be corrected quickly, and raise it later.

Check from your laptop that the records resolve before you request a certificate:

  • dig +short example.in A and dig +short www.example.in A should both print your server IP.
  • dig +short example.in AAAA should print the server's IPv6 address, or nothing. A stale AAAA record pointing to an old host is a common reason certificate validation fails.

Firewall

Open HTTP and HTTPS in ufw. Port 80 must stay open even after HTTPS is live, because Let's Encrypt validation and the redirect to HTTPS both use it.

  1. sudo ufw allow 80,443/tcp
  2. sudo ufw status should list 80 and 443 next to your SSH rule. Nothing else, and in particular no database port, should be open to the internet.

Install and configure Nginx

  1. sudo apt update && sudo apt install nginx -y
  2. systemctl status nginx should show active (running).
  3. Open http://SERVER_IP in a browser. The default "Welcome to nginx" page confirms the firewall and web server work.

Give each site its own directory and its own config file instead of editing the default one:

  1. sudo mkdir -p /var/www/example.in/public
  2. sudo chown -R deploy:www-data /var/www/example.in so your deploy user owns the code and Nginx can read it.
  3. Create /etc/nginx/sites-available/example.in with a server block containing listen 80;, listen [::]:80;, server_name example.in www.example.in;, root /var/www/example.in/public; and index index.php index.html;.
  4. sudo ln -s /etc/nginx/sites-available/example.in /etc/nginx/sites-enabled/ and remove the default site with sudo rm /etc/nginx/sites-enabled/default.
  5. sudo nginx -t must report "syntax is ok" and "test is successful". Only then run sudo systemctl reload nginx.

Make nginx -t a reflex. A reload with a broken config is refused, but a restart with one takes every site on the server down. Two more settings worth adding in /etc/nginx/nginx.conf: server_tokens off; to hide the exact Nginx version, and client_max_body_size 32m; (or whatever your largest upload is) so media uploads do not fail with a 413 error. The official Nginx documentation describes every directive.

Run your application: PHP-FPM or Node.js

Option A: PHP with PHP-FPM

  1. sudo apt install php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-zip php-intl -y installs PHP-FPM with the extensions most frameworks and WordPress need. Ubuntu 24.04 ships PHP 8.3; 22.04 ships PHP 8.1. Check with php -v.
  2. In your site's server block, add a location ~ \.php$ block containing include snippets/fastcgi-php.conf; and fastcgi_pass unix:/run/php/php8.3-fpm.sock; (use php8.1-fpm.sock on 22.04).
  3. Add location / { try_files $uri $uri/ /index.php?$query_string; } so pretty URLs in Laravel and WordPress work.
  4. sudo nginx -t && sudo systemctl reload nginx
  5. Test with a temporary file: echo '<?php echo PHP_VERSION;' | sudo tee /var/www/example.in/public/v.php, open http://example.in/v.php, then delete the file. Never leave a phpinfo() page on a live server.

The one PHP-FPM setting that matters most on a small server is pm.max_children in /etc/php/8.3/fpm/pool.d/www.conf. The Ubuntu default is low. Work it out from memory: watch a few busy requests in htop, note the typical size of a php-fpm worker (often 40–80 MB for WordPress), and divide the RAM you can spare for PHP by that number. For example, with about 2 GB free for PHP and 60 MB per worker, roughly 30 workers is a sensible ceiling. Set it too high and the server swaps under load; too low and visitors queue.

Option B: Node.js as a systemd service

The nodejs package in Ubuntu's own archive is often an older major version. For production, install a current LTS release from the NodeSource repository or the official binaries, and check it against the Node.js release schedule. Avoid odd-numbered "Current" releases on servers.

Run the app under systemd rather than in a screen session, so it starts on boot and restarts if it crashes. Create /etc/systemd/system/myapp.service with:

  • under [Unit]: Description=myapp and After=network.target;
  • under [Service]: User=deploy, WorkingDirectory=/var/www/myapp, Environment=NODE_ENV=production PORT=3000, ExecStart=/usr/bin/node server.js, Restart=on-failure and RestartSec=5;
  • under [Install]: WantedBy=multi-user.target.

Then sudo systemctl daemon-reload, sudo systemctl enable --now myapp, and check it with systemctl status myapp and journalctl -u myapp -f. Make the app listen on 127.0.0.1:3000, not on all interfaces, so the only way in is through Nginx.

In the Nginx server block, replace the PHP locations with a reverse proxy: location / { proxy_pass http://127.0.0.1:3000; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; }. If the app uses WebSockets, also pass the Upgrade and Connection headers. Keep secrets such as database passwords in an EnvironmentFile= readable only by the app user, not in the unit file or in Git.

Add the database on localhost

MySQL or MariaDB

  1. sudo apt install mysql-server -y (or mariadb-server).
  2. sudo mysql_secure_installation: remove anonymous users and the test database, and disallow remote root login.
  3. Create one database and one user per application: in sudo mysql, run CREATE DATABASE appdb;, CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'a-long-random-password'; and GRANT ALL ON appdb.* TO 'appuser'@'localhost';.
  4. sudo ss -tlnp | grep 3306 should show the server listening on 127.0.0.1 only.

PostgreSQL

  1. sudo apt install postgresql -y
  2. sudo -u postgres createuser --pwprompt appuser and sudo -u postgres createdb -O appuser appdb
  3. Leave listen_addresses at its default of localhost.

For MySQL, the largest single performance setting is innodb_buffer_pool_size. On a server that also runs the web stack, a starting value of about a quarter to a third of RAM is reasonable, adjusted after you watch real usage. Set up a nightly dump (mysqldump --single-transaction or pg_dump) to a location off the server, and test a restore. A server snapshot taken while the database is writing is not a reliable database backup on its own.

Turn on HTTPS with Let's Encrypt

Let's Encrypt certificates are free, trusted by all browsers, and renewed automatically by Certbot. With DNS pointing at the server and port 80 open:

  1. Install Certbot with the Nginx plugin. The Certbot instructions recommend the snap package (sudo snap install --classic certbot); the Ubuntu package (sudo apt install certbot python3-certbot-nginx) also works.
  2. sudo certbot --nginx -d example.in -d www.example.in obtains the certificate, adds the listen 443 ssl lines to your server block and sets up the HTTP-to-HTTPS redirect.
  3. sudo certbot renew --dry-run confirms that automatic renewal will work. Renewal runs from a systemd timer, which you can see with systemctl list-timers.
  4. From your laptop: curl -I http://example.in should return a 301 to https://, and curl -I https://www.example.in should return 200.

Pick one canonical hostname (with or without www) and redirect the other to it with a 301, so search engines see a single version of each page. Once HTTPS has worked for a few weeks, consider adding an HSTS header. If you need an organisation-validated certificate instead, our guide to SSL certificate types explains when that matters.

Performance, logs and the go-live checklist

Quick wins for Indian visitors

  • Compression. Enable gzip on; with gzip_types text/css application/javascript application/json image/svg+xml;. Many Indian users browse on mobile data, where smaller pages load noticeably faster.
  • Static file caching. Add expires 30d; for css, js, images and fonts, and use versioned file names so updates still reach users.
  • HTTP/2. Ubuntu 22.04 and 24.04 ship Nginx versions older than 1.25.1, so enable it on the HTTPS listen line: listen 443 ssl http2;. On Nginx 1.25.1 and later the separate http2 on; directive replaces that syntax. Check your version with nginx -v.
  • Measure from where your users are. curl -o /dev/null -s -w "connect %{time_connect}s, TLS %{time_appconnect}s, first byte %{time_starttransfer}s\n" https://example.in/ run from an office or phone hotspot in India shows the network time and how long your app takes to start responding. A server in India keeps the network part short; the rest is your code and database.

Logs and personal data

Nginx writes to /var/log/nginx/access.log and error.log, and logrotate on Ubuntu rotates them daily for about two weeks by default. Access logs contain visitors' IP addresses, and your database probably holds names, phone numbers or email addresses. Under the Digital Personal Data Protection Act, 2023, you are expected to protect personal data with reasonable security safeguards and not keep it longer than needed. Decide a retention period for logs and backups, restrict who can read them, and keep the hosting in India if your customers or contracts require data to stay in the country. Ask your CA or lawyer which obligations apply to your business.

Go-live checklist

  1. A and AAAA records correct for every hostname; TTL raised after launch.
  2. sudo nginx -t clean; default site removed; server_tokens off.
  3. PHP-FPM pm.max_children sized to RAM, or the Node.js app running under systemd and bound to 127.0.0.1.
  4. Database listening on localhost only, one user per app, nightly off-server dump with a tested restore.
  5. HTTPS on every hostname, HTTP redirects to HTTPS, one canonical hostname, certbot renew --dry-run passes.
  6. ufw allows only SSH, 80 and 443.
  7. Gzip and static caching on; first-byte time measured from India.
  8. External uptime monitor on the HTTPS URL; a snapshot taken right before launch.

How AvertHost can help

AvertHost Linux cloud VPS plans let you deploy Ubuntu, CentOS or Debian with root access, on NVMe storage with a separate NVMe backup volume. Each plan has a dedicated IP with IPv6 support and DDoS protection. Servers run in a Tier-IV data centre in Delhi, so your application and its data stay in India, close to Indian users, and the platform is backed by a 99.9% uptime SLA. You can scale CPU, RAM and storage as traffic grows, use hourly billing for a staging server and monthly billing for production, and get INR billing with GST invoices.

Our 24/7 support team is based in India. If a step in this guide does not behave as described on your server, for example a certificate that will not validate, they can help you find the cause.

FAQ

Which Ubuntu version should I use for a cloud server?

Use the newest LTS release your software supports, currently Ubuntu 24.04 LTS. LTS releases get five years of standard security updates, so you are not forced into an upgrade every year. Avoid interim releases on production servers.

Nginx or Apache on an Ubuntu cloud server?

Both work well. Nginx uses less memory per connection and is the natural choice as a reverse proxy for Node.js, which suits small cloud servers. Apache is useful if your PHP application depends on .htaccess rules. Many WordPress plugins write .htaccess rules that Nginx ignores, so check that your plugins also document Nginx settings.

Can I host several websites on one Ubuntu cloud server?

Yes. Give each site its own directory, its own Nginx server block and its own database user, and add each hostname to a certificate with Certbot. Keep an eye on total memory: every PHP pool or Node.js process adds to it. When one site's traffic starts affecting the others, move it to its own server.

Do I need a control panel to run a website on Ubuntu?

No. Everything in this guide uses the command line and standard Ubuntu packages. A control panel can help if you manage many client sites, but it adds licence cost, memory use and more software to patch.