"It works on my laptop" is the most expensive sentence in software. I have watched a developer say it at 11pm while a client's site showed a 500 error, and I have said it myself, more than once, with confidence.
The laptop and the server are not the same computer. They do not have the same operating system, the same installed packages, the same files, or the same permissions. When you deploy, you move code into a different life. Anything you assumed about the old life can break.
The five usual suspects
After years of this, the causes are boring and repeat themselves.
- A missing environment variable. Your .env file is on your laptop and was never added to the server.
- A different dependency version. You installed the latest locally, the server has an old lockfile, or the other way around.
- File name casing. Windows ignores case. Linux does not.
Image.pngandimage.pngare the same file on your laptop and two different files on the server. - The database is not running, or the credentials point to localhost when the database is on another host.
- The build step never ran. Your framework needs a build, and you uploaded the source instead of the output.
Notice that none of these are logic errors. The code is fine. The environment is not what the code expected.
Read the server log, not the browser
The browser shows a generic error because the server does not want to leak details to strangers. The real message is in the server log. Until you find that log, you are guessing.
On a VPS it is usually in /var/log/nginx/error.log, or in the app's own log file, or in the output of pm2 logs if you use PM2. On shared hosting there is often an error log in the control panel. Find it before you change a line of code.
Then reproduce the request and watch the log update. If nothing appears, your request is not reaching the app at all, which is a different problem: DNS, firewall, or the wrong port.
Run it in production mode on your laptop
Most people test with the development server, which is forgiving. It reloads on change, shows detailed errors, and sometimes ignores missing variables. Production is stricter.
Before you deploy, run the same commands the server will run. For a Node app that might be npm run build then npm start with NODE_ENV=production. For PHP, turn off display_errors and check the log instead. If it fails locally in production mode, you have found the bug before your users did.
This one habit would prevent half of the panicked deployment messages I get from students.
Use the same versions, on purpose
Your laptop has Node 20 and the server has Node 14. Your Python is 3.12 and the server is 3.8. Your MySQL is 8 and the server is 5.7. None of these are exotic, and all of them can break code that looks correct.
Write down the versions in your README. Use a lockfile and commit it. If you control the server, install the same major version. If you do not, test against the older one locally before you deploy. Docker solves this properly, but it is a bigger lesson than most first projects need.
An 8GB laptop also has limits the server may not have, or the other way round. A build that uses 3GB of RAM will succeed on your machine and get killed on a 1GB VPS. That is not a code bug. That is a memory bug, and the log will say "Killed" or "out of memory" if you look.
Paths and permissions
Absolute paths from your laptop, like /Users/yourname/projects/app/uploads, do not exist on the server. Use relative paths or a configured base directory. This is the single most common reason file uploads work locally and vanish in production.
Permissions are the second. The server process may not have write access to the uploads folder, even though your laptop user does. The error will say permission denied, and the fix is a chmod or a chown, not a code change.
And check the obvious: did the file actually upload? Did the build copy it? Is the folder in .gitignore, so it never reached the server? I have debugged a "missing image" that was simply never committed.
Deploy smaller, more often
The worst deployments are the ones with forty changes. When something breaks, you have forty suspects. Deploy one small change at a time, and you will know what caused it.
Keep a rollback. If the last deploy broke the site, you should be able to return to the previous version in minutes, not hours. On a VPS, that might be a Git tag and a checkout. On a platform, it is usually a button. Know where that button is before you need it.
Also, test on the real domain after deploy. Load the homepage, then log in, submit a form, load one image, and check the console. The bugs hide in the second page, not the first.
The night I learned this
I once spent six hours on a deployment that kept returning 404 for every page except the homepage. The code was fine. The issue was that the server was configured for Apache and my .htaccess rewrite rules were being ignored because the module was off. Six hours, one config line.
Since then, my first question is never "what is wrong with my code". It is "what is different between here and there". That question saves time because it points at the environment, which is where the answer usually lives.
What to do this week
Take one project you have only run locally. Write down every environment variable it needs, every version it depends on, and every folder it writes to. Then deploy it to a cheap VPS or a free host and fix what breaks. That exercise teaches more than any tutorial about deployment.
If you are still building the app, read how to build your first CRUD app. When the server log gives you an error you cannot read, how to debug code without panicking walks through the method. The Software development for absolute beginners course includes a deployment section for people who have never done it.