Developer & Network Tools

Deploying a Website: From Laptop to Live

The steps to put a website online: choose hosting, upload your files, point the domain, turn on HTTPS and roll back safely.

Key takeaways

  • Static sites need only a host that serves files, while applications also need a runtime, configuration and usually a database.
  • A repeatable deploy (a script or a pipeline) is safer than dragging files across by hand.
  • Your domain reaches the host through DNS records, and TLS certificates provide HTTPS.
  • Test on a staging copy or preview link before changing what the public sees.
  • Decide how you will roll back before you deploy, especially when a database changes.

Deploying a website means copying it from your computer to a server that is always online, then making your domain name lead visitors there. The basic path is the same for almost every site: prepare a build, put it on a host, set up DNS, enable HTTPS, test, and keep a way back to the previous version.

The details depend on whether your site is a folder of static files or an application with a server and a database. This guide covers both and points out where each tends to go wrong.

Know what you are deploying

A static site is a set of files (HTML, CSS, JavaScript, images) that the server sends as they are. Sites produced by a static site generator fall in this group, even if you write them in Markdown.

A dynamic site runs code on the server for requests: a PHP content system, a Python or Node.js application, an online shop. It needs the right language version, installed dependencies, environment settings, writable storage and often a database.

That difference drives your hosting choice.

Option Suits You manage
Static hosting Documentation, portfolios, brochure sites Your files and build
Shared or managed hosting Common content systems The application and its updates
Platform service Custom applications Code and configuration
Virtual private server Anything unusual, or full control The operating system and everything above it

The comparison of hosting types goes further. When unsure, pick the option that leaves you the least to maintain while still running your code.

Prepare a production build

What runs on your laptop isn't always what should go online. Many front-end projects have a build step that bundles scripts, minifies styles and writes the result into a folder such as dist or build. You publish that folder, not your source.

Before the first deploy, check these:

  • Debug mode and detailed error pages are off.
  • Secrets come from the server's environment, not from files in your repository.
  • Dependencies install from a lock file, so the server gets the versions you tested.
  • Links and asset paths don't point at localhost.
  • File names match exactly. Many servers treat Logo.png and logo.png as different files, while a Windows or default macOS disk does not.

That last item explains a large share of "images work on my computer" reports.

Get the files onto the server

You have several common routes.

Upload through a control panel or SFTP. SFTP is file transfer over SSH. It works for small sites. Avoid plain FTP, which sends passwords unencrypted.

Copy with rsync. On macOS or Linux, rsync sends only what changed:

rsync -avz --dry-run dist/ [email protected]:/var/www/site/

The --dry-run flag lists what would happen without doing it. Remove it once the list looks right. Be careful with --delete, which removes files on the destination that you don't have locally, including uploads.

Pull with Git. The server holds a clone and you run git pull. Keep the .git folder out of public reach.

Connect a pipeline. Your host or a build service watches the repository, runs tests and the build, then publishes automatically after a push. This takes more setup and pays off quickly, because every deploy happens the same way.

A repeatable deploy
1 Commit Changes are recorded and pushed 2 Build and test A clean machine produces the output 3 Preview Check the result on a staging address 4 Release Switch the live site to the new version 5 Verify Load key pages and watch error logs Commit Changes are recorded and pushed 1 Build and test A clean machine produces the output 2 Preview Check the result on a staging address 3 Release Switch the live site to the new version 4 Verify Load key pages and watch error logs 5

Configure the web server and application

On managed platforms much of this is automatic. On your own server, a web server such as Nginx, Apache or Caddy listens for requests. It serves static files directly and forwards other requests to your application, a role called a reverse proxy.

Make sure the public document root contains only files meant to be public. Configuration files, backups and source code belong above or outside it.

Run your application under a service manager such as systemd so it restarts after a crash or reboot. A program started in a terminal window stops when the session ends.

Give the application write access only to the folders that need it, such as an uploads directory. If you use a firewall, open web ports 80 and 443 to the public and keep the database port closed to the internet.

For a database, create a separate user for the application with only the permissions it uses, and schedule backups from the first day.

Point your domain at the host

DNS translates your domain name into the address of your host. Your provider will tell you which records to create:

  • an A record pointing a name to an IPv4 address
  • an AAAA record pointing to an IPv6 address
  • a CNAME record pointing one name to another name, often used for www

The bare domain (without www) can't normally be a CNAME, a limitation explained in the apex domain problem.

DNS answers are cached for a period set by each record's time to live. If you are moving an existing site, lower that value a day or more ahead, and keep the old server running while caches expire.

Choose one canonical address, with or without www, and redirect the other to it. Leave your email records (MX and related TXT entries) alone unless you are moving mail too.

Turn on HTTPS

HTTPS encrypts traffic and lets browsers verify they reached your domain. It requires a TLS certificate. Many hosts issue and renew one automatically once DNS points to them.

On your own server, an ACME client can obtain free certificates and renew them on a schedule, as described in automated certificates. Confirm that renewal actually works, since an expired certificate puts a full-page warning in front of your visitors.

Redirect HTTP requests to HTTPS, and fix any images or scripts still loaded over http://. Once you are confident everything works securely, consider adding HSTS. Start with a short duration, because browsers remember the instruction.

What a visitor's request passes through
DNS Turns your domain into the host's address TLS Certificate proves identity and encrypts Web server Serves files or forwards the request Application Runs your code with its settings Database and storage Holds content and uploads DNS Turns your domain into the host's address TLS Certificate proves identity and encrypts Web server Serves files or forwards the request Application Runs your code with its settings Database and storage Holds content and uploads

Handle databases and user uploads

Code travels from your laptop to the server. Content usually travels the other way, because the live site is where orders, comments and uploaded images are created. Copying your local database over the live one erases all of it, which is one of the most painful deploy accidents.

Treat the two flows separately. Changes to the database structure go into migration files, small scripts that are kept in version control and applied in order on each environment. Content stays where it was created. When you need realistic data for testing, copy from live to staging and remove personal details on the way.

Uploaded files need the same care. Keep them in a directory that your deploy never replaces, or in object storage outside the release folder. If each release is a fresh directory, link the shared uploads folder into it.

For the first launch only, you will often move a database upward. Export it with your database's dump tool, import it on the server, then update any stored addresses that still refer to your local machine. Content systems may store those inside serialized settings, so use the migration tool they recommend instead of a blind text replacement.

Test before and after release

A staging site is a private copy that resembles production. Use it to try changes with realistic settings, and protect it with a password so search engines and strangers stay out. Strip personal data from any database you copy into it. See testing changes on staging.

After each release, walk a short checklist:

  1. Load the home page and a few deep links in a private window.
  2. Submit forms and complete any sign-in or checkout path with test data.
  3. Check the browser console and network tab for missing files.
  4. Read the server's error log.
  5. Confirm that a nonexistent URL returns a real 404 status.

Then set up uptime monitoring so you hear about outages before your visitors tell you.

Plan the way back

Something will eventually go wrong. A rollback should take one action.

Keeping each release in its own folder and switching a symbolic link to the active one is a simple pattern. Many platforms keep previous deployments and let you promote one again. With Git, you can revert the bad commit and redeploy.

Databases are the hard part. Restoring old code doesn't undo a changed table, and restoring an old database discards whatever users added since. Prefer changes that old and new code can both tolerate: add a new column first, start using it, and remove the old one in a later release. Take a backup immediately before any migration.

Browser and CDN caches can also make a fixed site look broken. Giving asset files a new name or version string whenever their contents change avoids most of this.

Common questions

How long does it take for a new domain setup to work?

Often minutes, though cached DNS answers can delay changes for as long as the previous time to live, and sometimes longer for changes at the registrar level.

Can I deploy directly by editing files on the server?

You can, and for an emergency it happens. The next deploy may overwrite the edit, and nothing records it. Copy any hotfix back into your repository immediately.

Written for 4Internet with AI writing tools and not reviewed line by line by a person. Check anything you rely on with the maker, provider or standard concerned. Report an error.

Keep reading

All 45 articles in Developer & Network Tools →

Latest news on this topic