LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-07-2009, 01:11 PM   #1
Barq
Member
 
Registered: Aug 2004
Location: EGYPT
Distribution: FEDORA 10
Posts: 114

Rep: Reputation: 15
permission problem when run php script by apache


Hi
when i in /var/www/html and run tst.php script by php directly i.e `php tst.php , it is run as we expect, where
tst.php
<?php ls > list ?>

but when i run this file (i.e tst.php) by httpd , "list" file was't created , why?
 
Old 05-07-2009, 01:39 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by Barq View Post
Hi
when i in /var/www/html and run tst.php script by php directly i.e `php tst.php , it is run as we expect, where
tst.php
<?php ls > list ?>

but when i run this file (i.e tst.php) by httpd , "list" file was't created , why?
Have you checked your apache logs yet?

And try to post complete information, like version/distro of Linux, what version apache, php, etc., and any error messages. Saying "wasn't created", doesn't give anyone alot to go on...

And you might want to check the permissions/ownership on the directories/files you're touching, too....make sure the apache user/group can read/write them.
 
Old 05-07-2009, 02:08 PM   #3
Barq
Member
 
Registered: Aug 2004
Location: EGYPT
Distribution: FEDORA 10
Posts: 114

Original Poster
Rep: Reputation: 15
thank you TB0ne
i run on fedora 10
httpd-2.2.10-2.i386
php-5.2.6-5.i386

if script <?php ls > list ?> become <?php ls > /tmp/list ?>, it run well as we expect , but if i make directory in tmp and allow write permission for all for this directory , also "list" file was't created.
and when i see /var/log/httpd/error_log, i find permission denied.
 
Old 05-07-2009, 02:24 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by Barq View Post
thank you TB0ne
i run on fedora 10
httpd-2.2.10-2.i386
php-5.2.6-5.i386

if script <?php ls > list ?> become <?php ls > /tmp/list ?>, it run well as we expect , but if i make directory in tmp and allow write permission for all for this directory , also "list" file was't created.
and when i see /var/log/httpd/error_log, i find permission denied.
Ok...then it's a permissions problem with where you're trying to write it, as your error clearly indicates. Fix the ownership or permissions on the target.
 
Old 05-07-2009, 04:32 PM   #5
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Quote:
Originally Posted by Barq View Post
thank you TB0ne
i run on fedora 10
httpd-2.2.10-2.i386
php-5.2.6-5.i386

if script <?php ls > list ?> become <?php ls > /tmp/list ?>, it run well as we expect , but if i make directory in tmp and allow write permission for all for this directory , also "list" file was't created.
and when i see /var/log/httpd/error_log, i find permission denied.
Unless you're using suphp or something similar the target location to write to needs to be writable by the apache user (because that's who it runs as.) You also might be getting a perm denied because php has been hardened and it isn't allowed to write to that location.

Furthermore, that doesn't look like valid php to me.

Try:
Code:
<?php system("ls > list"); ?>

Last edited by rweaver; 05-07-2009 at 04:37 PM.
 
Old 05-07-2009, 04:51 PM   #6
Barq
Member
 
Registered: Aug 2004
Location: EGYPT
Distribution: FEDORA 10
Posts: 114

Original Poster
Rep: Reputation: 15
thank you very much TB0ne
but problem still
i make /apache_test directory , owned by apache , and permissions are rwxrwxrwx
and when i run this file "tst.php" by apache which contain <?php `ls>/apache_test/list`?>
also it is appearing in /var/log/httpd/error_log
sh: /apache_test/list: Permission denied
 
Old 05-07-2009, 04:57 PM   #7
Barq
Member
 
Registered: Aug 2004
Location: EGYPT
Distribution: FEDORA 10
Posts: 114

Original Poster
Rep: Reputation: 15
rweaver problem still
 
Old 05-07-2009, 08:59 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Check your logfiles /var/log/messages, /var/log/audit/audit.log. sounds like an SELinux issue. Apache is not allowed to write outside of the areas defined by

semanage fcontext -l |grep http

(run that as root)

as an example, do

cd /var/www
ls -Z

to see the selinux settings there
 
Old 05-10-2009, 08:30 AM   #9
mpiekarski
LQ Newbie
 
Registered: May 2009
Location: Newark, DE
Distribution: Gentoo,ubuntu,rhel
Posts: 25

Rep: Reputation: 16
Hi

Your PHP is still invalid. You aren't writing proper php code which will not execute. Chances are you have php-cli installed. You should be able to from the command line run
Code:
php ./test.php
or whatever file you are using.

Check out shell_exec() Here: http://us2.php.net/manual/en/function.shell-exec.php. Just be careful... Executing shell script from php is just ASKING to get your server compromised if you don't sanitize any user inputs or protect it properly.

I am very confused how your above code would work if you ran it from the CLI since it isn't even php, its bash. You can see it is using the shell /bin/sh to run it in the error:

Quote:
sh: /apache_test/list: Permission denied
------------------------------------
Michael Piekarski
Network Engineer
mpiekarski@hostmysite.com
www.hostmysite.com

Last edited by mpiekarski; 05-10-2009 at 08:39 AM.
 
Old 05-11-2009, 03:03 AM   #10
suhas!
Member
 
Registered: Mar 2007
Posts: 100

Rep: Reputation: 17
Maybe your php script is running as cgi by apache, so it wont run under the privileges of user apache. Just execute <? system("whoami"); ?> and see which user the script is running as.
 
  


Reply



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
php/shell script to install mysql,apache and php automatically stranger_6_7 Linux - General 2 08-11-2009 02:07 AM
Calling a bash script from PHP - permission denied helsing Linux - Server 3 08-21-2008 07:30 AM
Apache 2, PHP 5, SuSE 9.2 - cannot run php files dickohead Linux - Networking 6 06-28-2006 10:25 AM
PHP script permission problem deadlock Linux - Newbie 8 01-11-2006 06:34 AM
crontab failure: permission denied trying to run script hedpe Linux - Software 5 05-03-2005 07:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 04:32 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
Open Source Consulting | Domain Registration