eglInitialize failed

The user you’re running as can’t connect to the X server running on the machine. Fix that first. Then retry your EGL connect test.

Once apps like glxgears and glxinfo run properly, you’re ready to retry your EGL test.

Which driver and driver version are you running? I have no idea if AMD drivers support creating EGL contexts without access to the X server, like NVIDIA does. However, if they do, there may be some tricks to ensuring that the user that you’re running as can connect to the underlying graphics driver. You can investigate this using strace. See this post where I detailed a similar investigation I did to figure out what access NVIDIA’s EGL support needed in order to create an EGL context without an X server connection.