To deploy a React application on Ubuntu Server 24.10 using PM2, follow these steps:
Step 1 : Install PM2 globally using npm:
Step 2 : Run the startup command to ensure PM2 restarts your application on system reboot:
Step 3 : Use the following command to create a new React app using Vite:
Step 4 : Navigate to your project directory and build the application:
Step 5 : Use PM2 to serve the dist folder:
Step 6 : If you have UFW (Uncomplicated Firewall) enabled, allow traffic on port 3000:
Step 7 : Open your browser and navigate to:
Step 8 : You can use the following PM2 commands to manage your application:
- Check Status: pm2 status
- Restart: pm2 restart my-react-app
- Reload: pm2 reload my-react-app
- Stop: pm2 stop my-react-app
- Delete: pm2 delete my-react-app
Congratulations! You have successfully deployed a React app using PM2 on Ubuntu Server 24.10.