Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

zidance's avatar

How can i secure my public api (server to server connection)

I am going to expose the API as a web service and protected by a secret key. It will be server to server connection.

But how can i do that without user registration?

Is it just generate a secret key and store in env then pass to the other server? So they can pass it in header everytime make request? And also create middleware to check the header secret key?

0 likes
1 reply
bugsysha's avatar

Depending on your setup. Do you own other servers also? If you do I guess it is enough. If you don't I would have a separate secret key for every server so you can change which ones can access your API.

Please or to participate in this conversation.