To deploy a React application using PM2 on AlmaLinux 9, follow these steps:
Step 1 : Install PM2
First, install PM2 globally using npm:
Step 2 : Set Up PM2 Startup
Run the following command to configure PM2 to start on boot:
This will generate a command. Copy and execute it to enable PM2 at startup.
Step 3 : Create a React App
Use the following command to create a new React application:
Navigate into the project directory:
Install dependencies
Step 4 : Build the React App
Generate the production build:
Step 5 : Serve the Build with PM2
Run the app using PM2 on port 3000
:
Step 6 : Configure the Firewall (If Needed)
If the firewall is enabled, allow traffic on port 3000
:
Step 7 : Test the Application
Open a web browser and visit:
If everything is set up correctly, you should see your React application running.
Step 8 : Manage the Application with PM2
Use the following commands to manage your application:
- Check status: pm2 status
- Restart app: pm2 restart my-react-app
- Reload app: pm2 reload my-react-app
- Stop app: pm2 stop my-react-app
- Delete app: pm2 delete my-react-app
Congratulations! You have successfully deployed a React app using PM2 on AlmaLinux 9.