vidhya vidhya - 2 years ago 147
Bash Question

How to access root packages through php?

Issue: Initially, Through command line as a root user,I accessed a package called

pandoc (/root/.cabal/bin/pandoc)
which was installed in root folder. When I try to access that package through php using
,it fails.

Question: Is there any limitation for php
not to access root packages for security purposes? If so,how to resolve it?

I tried: Gave write permission to root folder then I could access root packages through
command line not as a root user. yet I couldn't to access it through php

php code:

shell_exec("cd /home/quotequadsco/public_html/pandoc_jats ; sudo -u quotequadsco
-S /root/.cabal/bin/pandoc ex.tex --filter /root/.cabal/bin/pandoc-citeproc
-t JATS.lua -o ex.xml");

and also tried,

shell_exec("cd /home/quotequadsco/public_html/pandoc_jats ;/root/.cabal/bin/pandoc
ex.tex --filter /root/.cabal/bin/pandoc-citeproc -t JATS.lua -o ex.xml");

Expectation: I need to execute pandoc root package through
in php.

Answer Source

Added the following line in the /etc/sudoer file

#Defaults requiretty   //commented this line
usergroup ALL=(ALL)  ALL

PHP code,

shell_exec("cd /home/quotequadsco/public_html/pandoc_jats ;echo password | sudo 
-S command"); //added a password for sudo command to run as a root user.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download