Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use sudo commands from Symfony Process Component?

Tags:

php

nginx

symfony

I am working on a Laravel project where I have to generate a Nginx configuration file and store it on /etc/nginx/sites-available directory which only has write rights for the admin user, I have admin rights on the server, I just want to know if there is a way for doing this using the Process Component of Symfony stack.

Thanks a lot and bests ;)

like image 811
bretanac93 Avatar asked Sep 01 '25 09:09

bretanac93


1 Answers

I would recommend using linux ACL, and give PHP process rights to write into the directory. That way you don't need sudo.

Also, you will need rights to reload the nginx process. And imho having a cronjob under root user, that reloads the configuration, if it changes and is valid, is a much better option.

You should read the relevant answers, that suggest not having rights to do a sudo call from PHP, for example

  • https://stackoverflow.com/a/35340819/602899
  • https://stackoverflow.com/a/29520712/602899

Just don't do it. Find a workaround that doesn't require sudo permissions.

like image 118
Filip Procházka Avatar answered Sep 03 '25 22:09

Filip Procházka