This repository contains scripts to simplify the configuration and deployment of websites on a VPS server. It is particularly useful for system administrators and developers who want to automate the setting up of websites with Nginx and secure them with SSL certificates from Let's Encrypt.
- Structure
- Features
- Prerequisites
- Usage
- Specific Deployment Instructions
- Automated Database Backup
- Resolve problems
- Contributions
- License
This repository is organized into separate folders for different web technologies:
- prepare_environment.sh: Scripts and configurations for preparing the VPS to host websites.
- setup_site.sh: Scripts and configurations for setting up websites with Nginx and Let's Encrypt.
- nuxtjs3: Scripts and configurations for deploying Nuxt.js 3 applications.
- vuejs3: Scripts and configurations for deploying Vue.js 3 applications.
- adonisjs: Scripts and configurations for deploying AdonisJS applications.
Each folder contains a deploy-vps.yml
file for GitHub Actions and an nginx.conf
file for Nginx configuration specific to the technology.
- prepare_environment.sh: A script to install Nginx and Certbot, thereby preparing the VPS to host websites.
- setup_site.sh: A script to quickly configure a new website with Nginx and obtain an SSL certificate via Let's Encrypt.
- A Linux VPS (preferably Debian or Ubuntu)
- A domain name (e.g.
example.com
) with an A record pointing to the IP address of the VPS - A user account with
sudo
privileges
- Clone this repository to your VPS or directly download the scripts.
- Make the
prepare_environment.sh
script executable by runningchmod +x prepare_environment.sh
- Run the script with
sudo sh ./prepare_environment.sh
- Clone this repository to your VPS or directly download the scripts.
- Make the
setup_site.sh
script executable by runningchmod +x setup_site.sh
- Run the script with
sudo sh ./setup_site.sh example.com
Replace `example.com` with your domain or subdomain name.
- Navigate to the nuxtjs3 directory.
- Use the deploy-vps.yml in your GitHub Actions workflow to automate the deployment process.
- Add
SSH_HOST
,SSH_USERNAME
,SSH_PRIVATE_KEY
, andSSH_PORT
as secrets to your GitHub repository. - Replace
/var/www/dibodev.com/html
with the path to your application on your VPS. - Replace
dibodev.com
with your pm2 process name.
- Customize the nginx.conf file as needed and place it in your Nginx configuration directory (usually
/etc/nginx/sites-available
) on your VPS.
- The GitHub Actions workflow for Nuxt.js 3 automates the process of pulling the latest code from the repository, installing dependencies, building the application, and deploying it to the specified VPS using SSH.
- The provided
nginx.conf
is optimized for Nuxt.js 3 applications and includes HTTPS configuration with HTTP/2 support.
- Navigate to the vuejs3 directory.
- Use the deploy-vps.yml in your GitHub Actions workflow to automate the deployment of Vue.js 3 applications.
- Add
SSH_HOST
,SSH_USERNAME
,SSH_PRIVATE_KEY
, andSSH_PORT
as secrets to your GitHub repository. - Replace
/var/www/dibodev.com/html
with the path to your application on your VPS. - After the deployment, verify the application is running correctly by accessing your domain in a web browser.
- Customize the nginx.conf file as per your requirements. This configuration sets up an HTTPS server for Vue.js 3 applications.
- Place the
nginx.conf
file in the Nginx configuration directory (usually/etc/nginx/sites-available
) on your VPS. - Ensure that the SSL certificates specified in the configuration are correctly installed and valid for your domain.
- Test the Nginx configuration by running
sudo nginx -t
and then reload Nginx withsudo systemctl reload nginx
.
- The GitHub Actions workflow for Vue.js 3 automates the process of pulling the latest code from the repository, installing dependencies, building the application, and deploying it to the specified VPS using SSH.
- The provided
nginx.conf
is optimized for Vue.js 3 applications and includes HTTPS configuration with HTTP/2 support.
- Navigate to the adonisjs directory.
- Use the updated deploy-vps.yml in your GitHub Actions workflow to automate the deployment process of AdonisJS applications.
- Add necessary secrets such as
SSH_HOST
,SSH_USERNAME
,SSH_PRIVATE_KEY
,SSH_PORT
,APP_KEY
,DATABASE_DB_NAME
,DATABASE_HOST
,DATABASE_USERNAME
, andDATABASE_PASSWORD
to your GitHub repository. - Modify the
APP_DIR
andDOMAIN
environment variables in the workflow to match your deployment directory and pm2 process name. - The workflow now includes steps to set up the production
.env
file using.env.production
and update it with secrets.
- Ensure that the nginx.conf file is customized for your AdonisJS application and placed in the Nginx configuration directory (usually
/etc/nginx/sites-available
) on your VPS. - After deployment, confirm that Nginx has restarted successfully and the application is running as expected.
- The updated deployment process simplifies the creation and updating of the
.env
file for production use. - Additional commands have been added to restart the API using PM2, run database migrations, and seed the database after deployment.
- The deployment script now also ensures that Nginx is restarted, ensuring that any configuration changes are applied.
The mariadb/backup-ftp-database.yml workflow automates the process of backing up your MariaDB database to an FTP server. This is crucial for ensuring data safety and quick recovery in case of data loss.
The workflow is scheduled to run every 12 hours (at 00:00 and 12:00 each day). It can also be triggered manually via GitHub Actions.
- Install MariaDB Client and Gzip: Prepares the environment by installing necessary tools.
- MySQLDump - Database Backup: Connects to your MariaDB database and creates a compressed backup file.
- Set Current Date and Time: Generates a timestamp to label the backup file.
- Deploy Backup to FTP: Uploads the backup file to the specified FTP server.
To use this workflow, you need to set the following secrets in your GitHub repository:
DATABASE_HOST
: The hostname of your MariaDB server.DATABASE_USERNAME
: The username for the database.DATABASE_PASSWORD
: The password for the database.DATABASE_DB_NAME
: The name of the database to back up.SERVER_FTP_HOST
: The FTP server hostname.SERVER_FTP_USERNAME
: The FTP server username.SERVER_FTP_PASSWORD
: The FTP server password.SERVER_FTP_PORT
: The FTP server port (optional).
- resolve the right problem on job 📤 Deploy to VPS
- check whether the user
SSH_USERNAME
has the necessary rights to the path/var/www/[domain]/html
:
ls -ld /var/www/[domain]/html
- if not, change the owner of the path
/var/www/[domain]/html
to the userSSH_USERNAME
:
sudo chown -R [SSH_USERNAME]:[SSH_USERNAME] /var/www/[domain]/html
- check whether the user
Contributions to this project are welcome. Feel free to propose improvements or report issues via GitHub issues.
MIT License by Leoglme