Troubleshooting localhost Port Conflicts
Resolving issues with ports like localhost 80, 443, 3000, 5173 being occupied, preventing Apache, Vite, and Next.js from starting.
When starting XAMPP, Vite, Next.js, or Docker, you may frequently encounter “port already in use” or Address already in use errors. This article explains how to troubleshoot and free up common localhost ports.
Common Conflict Ports
| Port | Common Occupants | Typical Error Scenarios |
|---|---|---|
| 80 | Apache, IIS, Skype, Caddy | XAMPP Apache cannot Start |
| 443 | Apache HTTPS, IIS | SSL site startup failure |
| 3000 | Next.js, Express, NestJS, CRA | Second Node project startup failure |
| 3306 | MySQL, MariaDB | Docker MySQL conflicts with XAMPP |
| 5173 | Vite | Multiple Vite projects or previous process not exited |
| 8080 | Tomcat, Backup Apache | Java / Second web service |
| 5432 | PostgreSQL | Local PG conflicts with Docker PG |
| 6379 | Redis | Duplicate Redis installation |
Checking Occupied Processes
macOS / Linux
# Check port 5173
lsof -i :5173
# Or
sudo ss -tlnp | grep 5173The PID column in the output indicates the process ID.
Windows
netstat -ano | findstr :5173The last column is the PID, which you can use in Task Manager or:
taskkill /PID <pid> /FTerminating Processes (Unix)
kill <PID>
# Force
kill -9 <PID>Common Scenarios and Solutions
XAMPP Apache Cannot Bind to 80
- Close IIS, Skype, and other web servers.
- Alternatively, modify
httpd.conffromListen 80toListen 8080, and use http://localhost:8080. - On Windows, check if the World Wide Web Publishing Service is running.
Vite 5173 Occupied
Vite will automatically try 5174, 5175, etc., but you can also explicitly specify:
npm run dev -- --port 3000Or set server.port in vite.config.ts.
Two MySQL Instances Running Simultaneously
XAMPP MySQL conflicts with Docker -p 3306:3306. Solutions:
- Stop XAMPP MySQL and use only Docker.
- Or map Docker to
3307:3306, and connect usinglocalhost:3307.
Next.js and NestJS Competing for 3000
Change the port for one of them:
npm run dev -- -p 3001 # Next.js
PORT=3001 npm run start:dev # NestJS (or modify in main.ts)Prevention Recommendations
- Close services in the XAMPP control panel when not in use.
- Use
docker compose downto release mapped ports for Docker projects. - Use the localhost-ports quick reference table to confirm default ports for various tools.
- When running multiple projects in parallel, assign different ports to each project and document them in the README.
Conclusion
To resolve port conflicts, first use lsof / netstat to find the PID and terminate the process, or modify the service listening port. The most commonly conflicting ports in local development are 80 (Apache), 3000 (Node), 5173 (Vite), and 3306 (MySQL).