Curious why you let users run cli commands on your server in the first place? That in itself seems like a really really bad idea!
Maybe if we understand what the actual need is we can give better advice
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
We are facing a serious security issue with our backend infrastructure. We have API endpoints that allow command execution or access to the server's CLI.
Let me explain the scenario: Suppose our backend team creates an API for command execution on our server. This API could potentially expose the .env file of our project by running commands on the server. As we all know, the .env file contains crucial data that should only be accessible to IT admins and DevOps.
This issue poses a significant risk to our production environment, and any advice on how to secure it would be greatly appreciated. This is a serious vulnerability as it could expose sensitive server configuration details.
I found a possible solution: Disabling functions like exec, shell_exec, system, passthru, popen, and proc_open, which are used to gain CLI access in the LAMP stack server.
However, many of our APIs and services rely on the server's CLI. Disabling these functions in PHP could create significant issues for our server.
Please suggest How to secure the .env file access through the api ?
Thank you in advance for your help.
Please or to participate in this conversation.