To set up Keycloak, you can either run it locally or deploy it in a server environment, such as on-premise or in the cloud. Here’s a step-by-step guide for setting up Keycloak locally using Docker and for running it as a standalone server.
Using Docker simplifies the process by providing an isolated environment to run Keycloak.
Pull the Keycloak Docker image:
Open a terminal and pull the official Keycloak Docker image by running:
docker pull quay.io/keycloak/keycloak:latest
Run Keycloak in Docker:
Once the image is downloaded, run the following command to start Keycloak in development mode:
docker run -p 8080:8080 --name keycloak \
-e KEYCLOAK_ADMIN=admin \
-e KEYCLOAK_ADMIN_PASSWORD=admin \
quay.io/keycloak/keycloak:latest start-dev
-p 8080:8080 flag maps port 8080 on your local machine to the same port on the container.KEYCLOAK_ADMIN and KEYCLOAK_ADMIN_PASSWORD environment variables set up the initial admin username and password.Access Keycloak Admin Console:
Once the container is running, open your browser and go to:
http://localhost:8080
You will be prompted to log in using the admin credentials (default username and password set to admin).
If you prefer to install Keycloak directly on your machine or a server, follow these steps:
Download Keycloak:
Visit the official Keycloak website and download the latest distribution of Keycloak.
Extract Keycloak:
After downloading, extract the contents of the ZIP or TAR file:
unzip keycloak-<version>.zip
cd keycloak-<version>
Configure the Admin User:
Before starting Keycloak, create an admin user by running:
bin/kc.sh create-admin --user admin --password admin
This creates the admin user with the default credentials.
Start Keycloak:
Once the admin user is set, start Keycloak by running:
bin/kc.sh start-dev
This will start Keycloak in development mode, which uses an in-memory database.
Access Keycloak Admin Console:
Open your browser and go to:
http://localhost:8080
Log in using the credentials you set for the admin user (admin/admin).
After you’ve successfully logged in, you can begin configuring Keycloak:
If you plan to use Keycloak in production, you’ll want to use an external database like PostgreSQL or MySQL instead of the default in-memory H2 database. You can configure Keycloak to use a database by editing the conf/keycloak.conf file and providing the necessary connection details.