php execute external program on ubuntu

Hello,

I have installed a program on Ubuntu named "gammu" which is command line tool to send SMS. I test it and it send sms from the shell successfully. My question is how can I use this tool from PHP?
I tried "exec" but with no response and even with no output in the browser - note exec has additional 2 parameters which I tried to echo them-.
The thing I am doubt  in is the issue of permissions.

Your help is highly appreciated.
LVL 8
Ahmed MerghaniSoftware EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hugh McCurdyCommented:
If you are running Linux and control the server, I suggest you try running the command with the same permissions as Apache (or whatever) have.

Something like

# su
(enter the password for root)
# su apache
(or su www or whatever it is)

Then try the command to see if it work.  If it fails (and otherwise works from the command line) then this would support the permissions problem and also have the advantage of giving you an error that you can read (I hope).
0
Ahmed MerghaniSoftware EngineerAuthor Commented:
Thanks hmccurdy for your reply. When I run the command from the command line it works fine and the command is something like this:

sudo gammu bla bla bla

Open in new window


But when do it from PHP it do nothing. This is PHP code:
exec('sudo gammu bla bla', $ary, $rst);

Open in new window


I tried to print the tow variables $ary and $rst. The $ary is empty and $rst print 1.
0
mhmrCommented:
what is the output if you use
echo exec('gammu bla bla');
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Ahmed MerghaniSoftware EngineerAuthor Commented:
This is the output:

Array ( [0] => Error opening device, you don't have permissions. )
106

Open in new window

0
Hugh McCurdyCommented:
Is Apache (or whatever the user is for the web server) in the sudoers file as an authorized user of gammu?
0
Ahmed MerghaniSoftware EngineerAuthor Commented:
How can I check that?
0
Hugh McCurdyCommented:
We may have found the problem.  To look, you could

$ sudo cat /etc/sudoers

To edit, you could use your favorite editor.  Mine is vim which is sometimes also called vi.  (The editor elvis is also sometimes called vi)

$ sudo vi  /dev/sudoers

To get some idea of what you are trying to change

http://linux.die.net/man/5/sudoers

One option is top copy/paste your sudoers file here.  However, before you do that, you might want to make sure the file doesn't contain any information you want to keep secret.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ahmed MerghaniSoftware EngineerAuthor Commented:
Thanks for reply. This is the content of the file:

# /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
#

Defaults	env_reset

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root	ALL=(ALL) ALL

# Allow members of group sudo to execute any command
# (Note that later entries override this, so you might need to move
# it further down)
%sudo ALL=(ALL) ALL
#
#includedir /etc/sudoers.d

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

Open in new window

0
Ahmed MerghaniSoftware EngineerAuthor Commented:
Thanks hmccurdy. Now I can run the utility throw the PHP script. Just I add to the sudoers file this line in the bottom:
%www-data ALL=NOPASSWD: /usr/bin/gammu

Open in new window


Where "www-data" is the user that will run the PHP script.
"/usr/bin/gammu" the utility path which I want to run within the PHP script.
0
Hugh McCurdyCommented:
Glad I could help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.