This guide provides step-by-step instructions for manually installing JWTPlus on a Linux server. It covers installing dependencies like MySQL/MariaDB, configuring JWTPlus, and setting it up as a startup service using systemd.
Step 1: Install MySQL Server
sudo apt update && sudo apt install mysql-server -y # For Debian/Ubuntu
sudo yum install mysql-server -y # For RHEL-based systems
sudo mysql_secure_installation
Follow the prompts to set a root password and disable anonymous users.
mysql -u root -p
Inside the MySQL shell, execute:
CREATE DATABASE jwtplus;
CREATE USER 'jwtplus_user'@'localhost' IDENTIFIED BY 'strongpassword';
GRANT ALL PRIVILEGES ON jwtplus.* TO 'jwtplus_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Don't forget to set your database's username and password.
Install MariaDB using:
sudo apt update && sudo apt install mariadb-server -y # Debian/Ubuntu
sudo yum install mariadb-server -y # RHEL-based
Follow the same steps as MySQL to configure security and create a database.
wget https://your-download-link.com/jwtplus-latest.tar.gz
tar -xvzf jwtplus-latest.tar.gz -C /opt/jwtplus
cd /opt/jwtplus
chmod +x jwtplus
Step 1: Create the configuration file
nano /opt/jwtplus/jwtplus.yaml
Step 2: Set the correct configurations in the config file
debug: false
server:
ip: 0.0.0.0
port: 2025
db:
location: 127.0.0.1
port: 3306
username: jwtplus_user
password: strongpassword
dbname: jwtplus
Don't forgot to add the correct information.
By invoking the below command, the JWTPlus connects to the database using the provided configuration and creates all the tables automatically.
After the successful table import, JWTPlus will create your root key. Save this somewhere because this is the first and last time the root key is shown.
/opt/jwtplus/jwtplus install
Step 1: Create a systemd Service File
nano /etc/systemd/system/jwtplus.service
Add the following:
[Unit]
Description=JWTPlus Authentication Service
After=network.target mysql.service
[Service]
ExecStart=/opt/jwtplus/jwtplus run
Restart=always
User=root
WorkingDirectory=/opt/jwtplus
[Install]
WantedBy=multi-user.target
Save and exit.
Step 2: Enable and Start the Service
systemctl daemon-reload
systemctl enable jwtplus
systemctl start jwtplus
Step 3: Check Service Status
systemctl status jwtplus
If running correctly, the service should show an "Active" status.
To ensure JWTPlus runs efficiently, you should add two CRON jobs that execute every minute:
Open the CRON editor:
crontab -e
Add the following lines at the end of the file:
* * * * * /opt/jwtplus/jwtplus clean
* * * * * /opt/jwtplus/jwtplus rotate
Save and exit.
This ensures that expired tokens are regularly removed, and JWTPlus automatically rotates keys when the time arises.
Start Service:
systemctl start jwtplus
Stop Service:
systemctl stop jwtplus
Restart Service:
systemctl restart jwtplus
View Logs:
journalctl -u jwtplus --follow