PHP has this one core library function called exec which is used to execute commands as a sub-process on your system. Sitepoint actually released a new post about the exec and eval functions two days ago: https://www.sitepoint.com/the-delicious-evils-of-php/
Your main concern should be security: if your PHP code can execute commands on your system, and users can provider input via an interface, it’s very important to make sure no one has the ability to execute any malicious code at any given time.
One could write something from scratch to interact with the server’s system, but it’s probably a better idea to use an existing library instead; which already tackled many of the possible security issues. Symfony of course comes to mind, which has a component called the process component. I’ve never used this component myself, so I’m not sure how it handles security. You might actually need another Symfony component to make sure your application stays safe: https://symfony.com/doc/current/components/process.html. I’m sure you can find a lot of good documentation on this subject online. Also: Symfony is just a suggestion, you might want to use another library; which is fine. Just be sure your code is safe!