Find the answer to your Linux question:
Results 1 to 6 of 6
Dear All, I have a java application which send sms. So on console it works fine no problem. The problem comes when I start to run from the web browser ...
  1. #1
    Just Joined!
    Join Date
    Jul 2010
    Posts
    64

    php exec giving permission denied error

    Dear All,
    I have a java application which send sms. So on console it works fine no problem. The problem comes when I start to run from the web browser using the php exec method. Then I get error as "PortInUseException : java.lang.RuntimeException:
    Error opening "/dev/ttyUSB0"
    Permission denied".
    I guess I must do some permission settings in linux any help please? Thank you.

  2. #2
    Linux Newbie
    Join Date
    Dec 2009
    Posts
    241
    Well it seems that the user of executing the php doesn't have the rights to open the USB Device.
    On my system the user would be "www-data".

    To get the user you simply ask your system:
    ps -ef | grep apache
    for example

    However you should take a look what user / groups have the rights to open the device:
    Code:
    ls -al /dev/ttyUSB0
    As far as i know it should be enough to add the user executing the php into the group.
    A typical code to do this would be:
    Code:
    usermod -a -G dialout www-data

  3. #3
    Just Joined!
    Join Date
    Jul 2010
    Posts
    64
    Dear Zom,
    Ok first I ran this
    ps -ef | grep apache
    apache 3025 2940 0 04:40 ? 00:00:00 /usr/sbin/httpd
    apache 3027 2940 0 04:40 ? 00:00:00 /usr/sbin/httpd
    apache 3029 2940 0 04:40 ? 00:00:00 /usr/sbin/httpd
    apache 3030 2940 0 04:40 ? 00:00:00 /usr/sbin/httpd
    apache 3032 2940 0 04:40 ? 00:00:00 /usr/sbin/httpd
    apache 3033 2940 0 04:40 ? 00:00:00 /usr/sbin/httpd
    apache 3034 2940 0 04:40 ? 00:00:00 /usr/sbin/httpd
    apache 3035 2940 0 04:40 ? 00:00:00 /usr/sbin/httpd
    root 3365 3260 0 04:52 pts/1 00:00:00 grep apache
    Thus the user here is known as apache.
    Then I run this
    ls -al /dev/ttyUSB0
    crw-rw---- 1 root uucp 188, 0 Jan 1 04:44 /dev/ttyUSB0
    Then I tried
    usermod -a -G dialout apache
    usermod: unknown group dialout
    So what is my mistake ? Thank you.

  4. #4
    Linux Newbie
    Join Date
    Dec 2009
    Posts
    241
    usermod -a -G uucp apache

  5. #5
    Just Joined!
    Join Date
    Jul 2010
    Posts
    64
    Dear Zom,
    Thank you it works now. Actually what is this command means ?

  6. #6
    Linux Newbie
    Join Date
    Dec 2009
    Posts
    241
    usermod
    Is to change existing users
    -a (add)
    -G (Group)
    uucp (Groupname)
    apache (User that shall be modified)

    ls -al /dev/ttyUSB0
    Simply shows a line what user owns the device and what group has what rights to access:
    crw-rw---- 1 root uucp 188, 0 Jan 1 04:44 /dev/ttyUSB0
    Simply put:
    root owns it
    Members of Group uucp also have rw permission
    anyone else has no permission
    rw-rw----
    The first 3 letters are for the owner, the second are the group and the last 3 is the rest.
    You could also have solved it by allowing everyone to access the device (chmod).
    Or you could have changed the owner or group with chown or chgrp.
    But since it's a device I don't know if the system will remember such settings.

    If you need more details you can access the manuals by writing:
    man <command>
    man usermod

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...