Junior — Middle
How could you set up and deploy an application on a production server?
sobes.tech AI
Answer from AI
The following steps are usually performed to set up and deploy an application on a production server:
- Server preparation: installing necessary dependencies (e.g., web server, database, runtime environment).
- Copying application files: using SCP, FTP, Git, or CI/CD tools.
- Configuring settings: setting environment variables, configuration files.
- Starting the application: via system services (systemd), Docker containers, or process managers (e.g., PM2 for Node.js).
- Configuring web server and proxy: for example, Nginx or Apache to handle requests and SSL.
- Monitoring and logging: setting up systems to track application health.
Example of a simple deployment of a Node.js application on Ubuntu:
# Clone the repository
git clone https://github.com/user/app.git
cd app
# Install dependencies
npm install
# Run the application using PM2
npm install pm2 -g
pm2 start app.js
# Configure Nginx as a reverse proxy
sudo nano /etc/nginx/sites-available/app
# In the configuration, set proxy_pass to localhost:3000
sudo ln -s /etc/nginx/sites-available/app /etc/nginx/sites-enabled/
sudo systemctl restart nginx
For more complex projects, it is recommended to use CI/CD pipelines (GitLab CI, Jenkins, GitHub Actions) and containerization (Docker).