Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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.
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
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
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:
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.