Posted on Leave a comment

Fix 403 Forbidden when creating users in Keycloak

Recently I try using Keycloak for IAM for my new website. I can log in just fine but couldn’t create any user.

I use a client to do all the tasks with Keycloak. After a few hours of searching, I found out that the client missed the manage-users role. That’s why it couldn’t create any user despite I have my Java code setup correctly.

So, what’s the fix?

The fix turned out to be very simple.

Here are the steps:

First, login to your realm, select your client and go to service account roles.

You’ll see something like this:

So, the magic is to select realm-management in the Client Roles select box and add user-management role to your service account.

That’s all you need to do to avoid 403 when creating users with Keycloak.

Posted on Leave a comment

Quick Fix For WordPress Local Deployment with Docker

Recently I had to set up a WordPress development environment with Docker. My setup is very simple with one MariaDB image with one WordPress image. Here is the part of the docker-compose.yaml file containing these two services:

    container_name: wp_main
    image: wordpress
    restart: always
      - ./wp_main/wp-content:/var/www/html/wp-content
      - ./wp_main/wp-config.php:/var/www/html/wp-config.php
      WORDPRESS_DB_HOST: db_main
    image: mariadb:10.5.9
    restart: always
    container_name: db_main
      - db_main:/var/lib/mysql
      MYSQL_ROOT_PASSWORD: root      

Very straight forward, right?

But I noticed that it strangely slow when connecting to this local site. I tried disabling DNS lookup but got no improvement.

Until I did a simple trick.

What I did to improve my local WordPress site 1000x times

Well, 1000x seems to be an overstatement but got the site loading from 17s to literally milliseconds, that’s a lot for me.

Long story short, I suspected that the connection to the DB took the lion share of the loading time. So, instead of letting the docker networking handling the name resolution, I mapped the IP of the DB instance directly in the WordPress container.

That’s all I did.

If you now know what to do, good. Leave this site and implement the changes immediately. You should see a huge improvement with the loading time.

If you still need the instructions, read on.

Step by step to improve local WordPress development loading time.

Step one: Find your db IP

It’s quite simple to find the DB’s IP. First, you need to locate the database container with the help of docker ps:

Finding database container

As you can see from the image, the database container in my case is db_main. Next, do a docker inspect to find the container’s IP:

docker inspect <container_name>
# In my case, that would be docker inspect db_main

You will get a lot of text. However, you only need to pay attention to the last part, where the Networks block resides:

Finding container’s ip address is the IP I need.

Let’s put this valuable info to the WordPress container.

Step 2: Put the IP of the DB in WordPress container

Now, let’s bash into the WordPress container:

docker exec -it <container_name> bash

# In my case, that would be wp_main

Now, let’s update the /etc/hosts file with the db name and its IP

echo " db_main" >> /etc/hosts

Now, the /etc/hosts file contains the IP of the db_host. It will not have to ask the DNS to find the IP. The improvement is night and day.

What have I done?

As you can see first in the docker-compose.yaml file, I pointed hostname to db_main. When WordPress saw that as the db host, it asked the DNS to find the IP for that host name.

By setting the IP of the hostname right in the /etc/hosts file, the DNS stopped after finding the IP in that file. Thus, no more wasting time on upper DNS levels.

Give it a try, I promise you will see a big improvement.