Error in using gammu in php exec

3.5k Views Asked by At

I successfully installed gammu in ubuntu 11, and send text message using command line.
echo "TEXTMESSAGE" | gammu sendsms TEXT mobilenumber

My problem is, when I use exec function in my php script I always have the following errors:

Warning: No configuration file found!
Warning: No configuration read, using builtin defaults!
Error opening device, it doesn't exist.

Thanks for the help

3

There are 3 best solutions below

3
On

You are missing the .gammurc and the defaults fail to detect your device. Try running gammu-detect. It should say something along the lines of

[gammu]
device = /dev/ttyUSB0
name = Phone on USB serial port HUAWEI_Technology HUAWEI_Mobile
connection = at

If that does not work, run gammu-config and manually set up port and connection.

0
On

Just resolved the similar trouble. In my case gammu was executed under nagios user, so that it was not able to find the configuration file until I placed it in /etc/gammurc. According to gammu documentation on Linux, MacOS X, BSD and other Unix-like systems, the config file is searched in following order:

  1. $XDG_CONFIG_HOME/gammu/config
  2. ~/.config/gammu/config
  3. ~/.gammurc
  4. /etc/gammurc

My file was in /home/user/.gammurc, but when I executed it under nagios user "~" was a different directory, so that gammu was not able to find it.

Now permissions: In order to gain access for your user to /dev/ttyUSB0 (use your path) you should add nagios (in your case www-data or whatever it is) user to dialout group this way:

sudo usermod -a -G dialout nagios

And then set the SUID bit on gammu to allow nagios (www-data in your case) execute it on behalf of the root:

sudo chmod 4755 /usr/bin/gammu

Try to execute gammu on behalf of the root (you could use su command) Hope it would be useful.

0
On

You can change de path of .gammurc by doing this:

Copy the file (.gammurc) located on the root and past it on /etc.

cp .gammurc /etc/gammurc

Don't forget to remove the dot. I use it raspberry Pi , the directory of gammu may change on your environment