LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-20-2010, 01:43 AM   #1
shreyansh
LQ Newbie
 
Registered: May 2010
Posts: 14

Rep: Reputation: 0
Unhappy Worried about the linux command not running in php


hi all
i m newbie to this stuff
i am making network attached storage.
in that i cant do the following command
ifconfig eth0 192.168.1.1 netmask 255.255.255.0
/sbin/useradd username -p password
/etc/init.d/samba restart
/sbin/fdisk -l


i have put entry in sudoers file about apache users ALL but can not do this.
please help me if i m nt able to do the things then project is snatched away from me.


Thank you
 
Old 05-20-2010, 01:48 AM   #2
ajeetsinghraina
Member
 
Registered: May 2010
Location: India
Distribution: Ubuntu 7.04/8.04/8.10/10.04, RHEL 6, OpenSUSE,Mandriva,Fedora, CentOS, XandrOS, Slackware, OpenSolar
Posts: 155

Rep: Reputation: 55
Code:
please help me if i m nt able to do the things then project is snatched away from me.
Looks little weird...
Hope you save it through LQ.

Code:
i am making network attached storage.
Can you elaborate? What do you mean saying so?
Building your own NAS ????

Where are you trying to run this command?
which distribution?
what error it throws when you run those commands?

Code:
i have put entry in sudoers file about apache users ALL but can not do this.
please elaborate your need so that we can help you.

Last edited by ajeetsinghraina; 05-20-2010 at 01:49 AM.
 
Old 05-20-2010, 02:14 AM   #3
shreyansh
LQ Newbie
 
Registered: May 2010
Posts: 14

Original Poster
Rep: Reputation: 0
ok
listen
it is not throwing any error
simply i run
<?php
$output=shell_exec("/sbin/fdisk -l");
echo "$output";
?>
it will run fdisk command but in browser it display nothing.
same as others
i m using ubuntu 9.04
got something?
 
Old 05-20-2010, 02:24 AM   #4
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
Are you able to execute some non privileged commnand say ls ?

Post the sudoers entry.
 
Old 05-20-2010, 02:32 AM   #5
shreyansh
LQ Newbie
 
Registered: May 2010
Posts: 14

Original Poster
Rep: Reputation: 0
ya i can run ls and all that even also run ifconfig eth0 but while trying to change ip using it cant run.

here the sudoers file.
go to last line for apache users



Networking
Cmnd_Alias NETWORKING = /sbin/route, /sbin/ifconfig, /bin/ping, /sbin/dhclient, /usr/bin/net, /sbin/ipt$

## Installation and management of software
Cmnd_Alias SOFTWARE = /bin/rpm, /usr/bin/up2date, /usr/bin/yum

## Services
Cmnd_Alias SERVICES = /sbin/service, /sbin/chkconfig

## Updating the locate database
Cmnd_Alias LOCATE = /usr/bin/updatedb

## Storage
Cmnd_Alias STORAGE = /sbin/fdisk, /sbin/sfdisk, /sbin/parted, /sbin/partprobe, /bin/mount, /bin/umount

## Delegating permissions
Cmnd_Alias DELEGATING = /usr/sbin/visudo, /bin/chown, /bin/chmod, /bin/chgrp

## Processes
Cmnd_Alias PROCESSES = /bin/nice, /bin/kill, /usr/bin/kill, /usr/bin/killall

## Drivers
Cmnd_Alias DRIVERS = /sbin/modprobe

# Defaults specification

#
# Disable "ssh hostname sudo <cmd>", because it will show the password in clear.
# You have to run "ssh -t hostname sudo <cmd>".
#
Defaults requiretty

Defaults env_reset
Defaults env_keep = "COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR \
LS_COLORS MAIL PS1 PS2 QTDIR USERNAME \
LANG LC_ADDRESS LC_CTYPE LC_COLLATE LC_IDENTIFICATION \
LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC \
LC_PAPER LC_TELEPHONE LC_TIME LC_ALL LANGUAGE LINGUAS \
## Next comes the main part: which users can run what software on
## which machines (the sudoers file can be shared between multiple
## systems).
## Syntax:
##
## user MACHINE=COMMANDS
##
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere

root ALL=(ALL) ALL

## Allows members of the 'sys' group to run networking, software,
## service management apps and more.
# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS

## Allows people in group wheel to run all commands
# %wheel ALL=(ALL) ALL

## Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL

## Allows members of the users group to mount and unmount the
## cdrom as root
# %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom

## Allows members of the users group to shutdown this system
%users localhost=/sbin/shutdown -h now
apache ALL=(ALL) ALL
 
Old 05-20-2010, 03:23 AM   #6
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
If you are making sudo entry for any user you should invoke the command by preceding sudo to it.
Code:
sudo /sbin/fdisk -l

Secondly after you execute a command via sudo it asks for password, here in your case use should use NOPASSWD to do so


Code:
## Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
Two check the how the things work try giving shell to apache user and the try executing this command after you switch to apache user.
 
Old 05-20-2010, 03:30 AM   #7
shreyansh
LQ Newbie
 
Registered: May 2010
Posts: 14

Original Poster
Rep: Reputation: 0
i try that you say
su www-data
$ sudo /sbin/fdisk -l

prompt for password when i enter it will display nothing

$.
just
 
Old 05-20-2010, 03:46 AM   #8
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
I can see an entry for "apache" in your sudoers and here you are switching to www-data ?
Which group this user www-data belongs to ?
And in case it belongs to apache you show change the sudoers to group permission
 
Old 05-20-2010, 03:49 AM   #9
shreyansh
LQ Newbie
 
Registered: May 2010
Posts: 14

Original Poster
Rep: Reputation: 0
www-data:x:33:33:www-data:/var/www:/bin/sh
in /etc/passwd entry this code belongs
and this www-data is apache user i think.
 
Old 05-20-2010, 04:30 AM   #10
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
Do you have any entry corresponding to apache in /etc/passwd.

If this is the apache user modify your /etc/soduer for this user not apache
 
Old 05-20-2010, 04:35 AM   #11
shreyansh
LQ Newbie
 
Registered: May 2010
Posts: 14

Original Poster
Rep: Reputation: 0
no there is not any entry like apache user
just only www-data and what should i right for this in /etc/sudoers ?
that also called to change uid of www-data in /etc/passwd
if i change that it run all command but cant restart apache service and cant run php file in browser
 
Old 05-20-2010, 05:04 AM   #12
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
add this entry in your /etc/sudoers and then try to execute the command oh this user shell

Code:
www-data ALL=(ALL) NOPASSWD: ALL
 
Old 05-20-2010, 05:14 AM   #13
shreyansh
LQ Newbie
 
Registered: May 2010
Posts: 14

Original Poster
Rep: Reputation: 0
i put entry in sudoers

and try but get following error

$ sudo fdisk -l
sudo: must be setuid root
$ fdisk -l
$ /sbin/fdisk -l
when i set uid as root then commands are runnig but apache is not running.
 
Old 05-20-2010, 05:27 AM   #14
moueza
LQ Newbie
 
Registered: Jan 2009
Posts: 1

Rep: Reputation: 0
set your $ account belonging to root group,as main group
 
Old 05-20-2010, 05:36 AM   #15
shreyansh
LQ Newbie
 
Registered: May 2010
Posts: 14

Original Poster
Rep: Reputation: 0
i set adduser www-data root
Adding user `www-data' to group `root' ...
Adding user www-data to group root
Done.

now what to do?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Running the mount command from PHP Dhamon Programming 5 04-10-2009 03:32 AM
running a php script from command line leicaphotos Linux - Newbie 1 10-10-2008 01:24 PM
Problems running PHP script in command line Hondro Linux - Software 1 06-21-2007 04:16 AM
Problems running PHP scrip in command line Hondro Programming 0 06-21-2007 02:39 AM
running iptable command as php programming omid1979 Programming 1 07-15-2006 08:36 AM


All times are GMT -5. The time now is 10:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration