Skip to content
Menu
DevSecOps Now!!!
  • About
  • Certifications
  • Contact
  • Courses
  • DevSecOps Consulting
  • DevSecOps Tools
  • Training
  • Tutorials
DevSecOps Now!!!

Complete Tutorial: Running Keycloak 26.x on Ubuntu with LAMPP (MariaDB) in Production

Posted on November 3, 2025

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

1. Background

You’re running:

  • Keycloak 26.3.3 (Quarkus-based)
  • LAMPP (XAMPP for Linux 8.2.4) stack at /opt/lampp
  • MariaDB managed by LAMPP (/opt/lampp/sbin/mysqld)
  • Systemd-based service for permanent Keycloak startup

Goal:
Run Keycloak as a systemd service using MariaDB from LAMPP, with production settings, automatic startup, and full connectivity.


2. Common Issues Encountered

Issue 1 — Keycloak Fails Under Systemd

keycloak.service: Main process exited, code=exited, status=1/FAILURE

Cause: Running as keycloak user but DB authentication failed due to incorrect socket or ENV overrides.


Issue 2 — “Access denied for user ‘root’@’localhost’”

Cause:
LAMPP uses UNIX socket authentication for root@localhost, while Keycloak (running as keycloak user) doesn’t have permission to use that socket.


Issue 3 — “Socket fail to connect to 127.0.0.1. Connection refused”

Cause:
LAMPP MySQL wasn’t listening on TCP (only socket). Hence, Keycloak’s JDBC TCP URL (127.0.0.1:3306) couldn’t connect.


Issue 4 — kc.db-url still showing (ENV) source

Cause:
Old shell exports like KC_DB_URL, KC_DB_USERNAME, etc., in root’s environment were overriding keycloak.conf.


3. Step-by-Step Solution


Step 1 — Clean up any leftover ENV variables

Run as root:

unset KC_DB_URL KC_DB KC_DB_USERNAME KC_DB_PASSWORD KC_HOSTNAME KC_HTTP_ENABLED

Then verify:

env | egrep '^KC_|^kc\.' || echo "no KC_* env"

Step 2 — Fix the Keycloak DB config

Edit:

sudo nano /opt/auth.myhospitalnow.com/conf/keycloak.conf

Use this:

# ---------- DB ----------
db=mariadb
db-username=root
db-password=UW7k(rDc3t&cUIu7i#G0&c$B
db-url=jdbc:mariadb://127.0.0.1:3306/keycloak_db
db-pool-initial-size=5
db-pool-min-idle=5
db-pool-max-size=25
db-pool-prefill=true

# ---------- HTTP ----------
http-enabled=true
http-port=8080

# ---------- HOSTNAME ----------
hostname=auth.myhospitalnow.com
hostname-strict=false
hostname-strict-backchannel=false
proxy-headers=xforwarded
proxy=none

# ---------- CACHE ----------
cache=local
health-enabled=true
metrics-enabled=true

Key fixes:

  • Removed localSocket=/opt/lampp/var/mysql/mysql.sock
  • Switched to TCP: jdbc:mariadb://127.0.0.1:3306/keycloak_db
  • No quotes around passwords

Step 3 — Enable TCP networking in LAMPP MySQL

Edit /opt/lampp/etc/my.cnf:

sudo nano /opt/lampp/etc/my.cnf

Ensure:

[mysqld]
port=3306
bind-address=127.0.0.1
# Comment out if found:
# skip-networking
# skip-bind-address

Restart MySQL:

sudo /opt/lampp/lampp restartmysql

Confirm it’s listening:

sudo ss -ltnp | grep 3306

Step 4 — Allow TCP login for root

sudo /opt/lampp/bin/mysql -u root -p

Inside MySQL:

CREATE DATABASE IF NOT EXISTS keycloak_db;
CREATE USER IF NOT EXISTS 'root'@'127.0.0.1' IDENTIFIED BY 'UW7k(rDc3t&cUIu7i#G0&c$B';
GRANT ALL PRIVILEGES ON keycloak_db.* TO 'root'@'127.0.0.1';
FLUSH PRIVILEGES;

Then test:

sudo -u keycloak /opt/lampp/bin/mysql -h 127.0.0.1 -uroot -p keycloak_db -e "SELECT 1;"

Step 5 — Rebuild Keycloak runtime

/opt/auth.myhospitalnow.com/bin/kc.sh build

Check config sources:

/opt/auth.myhospitalnow.com/bin/kc.sh show-config | egrep '^(kc\.db|kc\.db-|kc\.db-url)'

All should now say (keycloak.conf)


Step 6 — Create clean systemd unit

Create:

sudo nano /etc/systemd/system/keycloak.service

Add:

[Unit]
Description=Keycloak Server
After=network.target mariadb.service
Wants=network-online.target

[Service]
User=keycloak
Group=keycloak
WorkingDirectory=/opt/auth.myhospitalnow.com
Environment=JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
Environment=PATH=/usr/lib/jvm/java-17-openjdk-amd64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
Environment=JAVA_OPTS=-Xms512m -Xmx2048m
ExecStartPre=/bin/sh -c 'for i in $(seq 1 30); do nc -z 127.0.0.1 3306 && exit 0; sleep 1; done; exit 1'
ExecStart=/opt/auth.myhospitalnow.com/bin/kc.sh start --optimized
ExecStop=/opt/auth.myhospitalnow.com/bin/kc.sh stop
Restart=always
RestartSec=5
TimeoutStartSec=120
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

Apply changes:

sudo systemctl daemon-reload
sudo systemctl enable keycloak

Step 7 — Fix ownership and permissions

sudo useradd -r -s /usr/sbin/nologin keycloak 2>/dev/null || true
sudo chown -R keycloak:keycloak /opt/auth.myhospitalnow.com
sudo chmod +x /opt/auth.myhospitalnow.com/bin/kc.sh

Step 8 — Test Run

Run manually first:

sudo -u keycloak /opt/auth.myhospitalnow.com/bin/kc.sh start --optimized

If it starts fine, enable permanent startup:

sudo systemctl restart keycloak
sudo systemctl status keycloak

Should show Active (running).


4. Verification Checklist

CheckCommandExpected Output
MariaDB listening on TCP`sudo ss -ltnpgrep 3306`
Keycloak DB connectivitysudo -u keycloak /opt/lampp/bin/mysql -h 127.0.0.1 -uroot -p keycloak_db -e "SELECT 1;"1
Keycloak DB sourcekc.sh show-config(keycloak.conf)
Keycloak systemd statussudo systemctl status keycloakActive (running)

5. Troubleshooting Summary

ErrorRoot CauseFix
Access denied for user ‘root’@’localhost’Using UNIX socket authCreated root@127.0.0.1 with password
Connection refused to 127.0.0.1LAMPP disabled TCPEnabled port=3306 and bind-address=127.0.0.1
kc.db-url from (ENV)Old shell exportsunset KC_* and rebuild
Starts manually but not via systemdJava PATH missingAdded JAVA_HOME and PATH in unit
Service fails at bootDB not readyAdded ExecStartPre with port-wait loop

🔧 6. Bonus Tips

  • For HTTPS later, add: https-certificate-file=/opt/auth.myhospitalnow.com/conf/server.crt.pem https-certificate-key-file=/opt/auth.myhospitalnow.com/conf/server.key.pem
  • Logs live in: /opt/auth.myhospitalnow.com/data/log/ journalctl -u keycloak -f
  • To test admin login: http://auth.myhospitalnow.com:8080

Post Views: 825
  • Access denied for user 'root'@'localhost'
  • code=exited
  • Keycloak Fails Under Systemd
  • keycloak.service: Main process exited
  • Running Keycloak
  • Running Keycloak 26.x on Ubuntu with LAMPP
  • Running Keycloak on Ubuntu with LAMPP
  • Socket fail to connect to 127.0.0.1. Connection refused
  • status=1/FAILURE
Subscribe
Login
Notify of
guest
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
  • Guide to DevSecOps Maturity Levels for Platform and Security Teams
  • Canada PR CRS Calculator: Express Entry Points System Explained
  • Austria PR Points Calculator: Ultimate Guide to Navigating the Red-White-Red Card System
  • The Essential Guide to Enterprise DevSecOps Implementation
  • How to Set Up Claude Code Agent on a Local Windows Laptop and Use claude Command from Anywhere
  • DevOps and DevSecOps Explained: Bridging the Gap Between Speed and Security
  • Comprehensive Manual on DevOps Methodologies and Cloud Native Engineering
  • The Master Guide to Immigration Points: Calculating Your Path to Canada, Australia, and Beyond
  • How to Skip the Activation Email and Password Reset After Google Login in Keycloak Auto-Link Existing Users in First Broker Login
  • Free SSL Certificate Generation Tutorial for Any Website Using Certbot and Apache
  • The Ultimate Guide to Certified FinOps Professional: Skills, Levels, and Career Impact
  • Certified FinOps Manager: Essential Skills for Modern Cloud Operations
  • How to Use Claude AI for Programming: Complete Guide for Developers to Boost Productivity
  • The Definitive Guide to Certified FinOps Engineer: Master Cloud Value Engineering
  • A Comprehensive Guide to the Certified FinOps Architect Certification and Training
  • Linux Server Diagnostic Commands: Complete Guide for Performance, Network & System Troubleshooting
  • The Ultimate Guide to CDOM – Certified DataOps Manager Certification
  • The Practical Path to AI Reliability: A Guide to the Certified MLOps Manager
  • Master the Machine Learning Lifecycle:Guide to Becoming a Certified MLOps Architect
  • How to Build a Project-Level AI Memory System That Works Across Codex, Claude, and Other AI Coding Tools
  • Certified MLOps Professional: A Deep Dive into the Certified MLOps Professional Certification
  • Certified MLOps Engineer : The Comprehensive Guide to Mastering Machine Learning Operations
  • Codex vs Claude: A Complete Practical Guide for Modern Developers (2026)
  • Certified AIOps Professional Program A Guide to Career Growth
  • Keycloak Multi-Client Architecture with Project-Based Email Validation (Student, Trainer, Company, Consulting)
  • Incorrect definition of table mysql.column_stats
  • Mautic and PHP 8.3 Compatibility Guide (2026)
  • Certified AIOps Engineer: The Complete Career Path and Certification Guide
  • How to Rename Apache Virtual Host Files Safely (Step-by-Step Guide for Linux)
  • AIOps Foundation Certification: Everything You Need to Know to Get Certified

Recent Comments

  1. emmy day on SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘provider’ in ‘field list’
  2. digital banking on Complete Tutorial: Setting Up Laravel Telescope Correctly (Windows + XAMPP + Custom Domain)
  3. SAHIL DHINGRA on How to Uninstall Xampp from your machine when it is not visible in Control panel programs & Feature ?
  4. Abhishek on MySQL: List of Comprehensive List of approach to secure MySQL servers.
  5. Kristina on Best practices to followed in .httacess to avoid DDOS attack?

Archives

  • May 2026
  • April 2026
  • March 2026
  • February 2026
  • January 2026
  • December 2025
  • November 2025
  • October 2025
  • September 2025
  • August 2025
  • July 2025
  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022

Categories

  • Ai
  • AI Blogging
  • AiOps
  • ajax
  • Android Studio
  • Antimalware
  • Antivirus
  • Apache
  • Api
  • API Security
  • Api Testing
  • APK
  • Aws
  • Bike Rental Services
  • ChatGPT
  • Code Linting
  • Composer
  • cPanel
  • Cyber Threat Intelligence
  • Cybersecurity
  • Data Loss Prevention
  • Database
  • dataops
  • Deception Technology
  • DeepSeek
  • Devops
  • DevSecOps
  • DevTools
  • Digital Asset Management
  • Digital Certificates
  • Docker
  • Drupal
  • emulator
  • Encryption Tools
  • Endpoint Security Tools
  • Error
  • facebook
  • Firewalls
  • Flutter
  • git
  • GITHUB
  • Google Antigravity
  • Google play console
  • Google reCAPTCHA
  • Gradle
  • Guest posting
  • health and fitness
  • IDE
  • Identity and Access Management
  • Incident Response
  • Instagram
  • Intrusion Detection and Prevention Systems
  • jobs
  • Joomla
  • Keycloak
  • Laravel
  • Law News
  • Lawyer Discussion
  • Legal Advice
  • Linkedin
  • Linkedin Api
  • Linux
  • Livewire
  • Mautic
  • Medical Tourism
  • MlOps
  • MobaXterm
  • Mobile Device Management
  • Multi-Factor Authentication
  • MySql
  • Network Traffic Analysis tools
  • Paytm
  • Penetration Testing
  • php
  • PHPMyAdmin
  • Pinterest Api
  • Quora
  • SAST
  • SecOps
  • Secure File Transfer Protocol
  • Security Analytics Tools
  • Security Auditing Tools
  • Security Information and Event Management
  • Seo
  • Server Management Tools
  • Single Sign-On
  • Site Reliability Engineering
  • soft 404
  • software
  • SSL
  • SuiteCRM
  • SysOps
  • Threat Model
  • Twitter
  • Twitter Api
  • ubuntu
  • Uncategorized
  • Virtual Host
  • Virtual Private Networks
  • VPNs
  • Vulnerability Assessment Tools
  • Web Application Firewalls
  • Windows Processor
  • Wordpress
  • WSL (Windows Subsystem for Linux)
  • X.com
  • Xampp
  • Youtube
©2026 DevSecOps Now!!! | WordPress Theme: EcoCoded
wpDiscuz