LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Apache user creates file in root account but not in other users (https://www.linuxquestions.org/questions/linux-newbie-8/apache-user-creates-file-in-root-account-but-not-in-other-users-4175503218/)

msp4422 04-28-2014 07:05 AM

Apache user creates file in root account but not in other users
 
favorite


I have a p3.php file which if I execute from root user it creates a text file but if I execute from another user it doesn't create any text file.

eg: I placed the p3.php in /var/www/html/p3.php and if I execute from "example.com/p3.php" it creates file without any issue.

but if I place in /john/public_html/tmp/p3.php and execute from "example.com/~john/tmp/p3.php" it doesn't create any file.

I gave all permissions to parent directory tmp and also executed the below commmand.

sudo chown apache /home/john/public_html/tmp/

I found apache is the user in httpd.conf file.

May I know what more I can do to create file in john account instead of root.

Many Thanks.

eklavya 04-28-2014 09:16 AM

First try to create file in the /tmp directory,
Suppose your code in the file p3.php
Code:

<?php
$ourFileName = "/tmp/testFile.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);
?>

Now you put the file in /home/john/public_html ( I suppose, this is the absolute path)
Now path of the file is /home/john/public_html/p3.php
Now you execute the file
http://example.com/~john/p3.php
and if it creates the file in /tmp directory of the server (not the /tmp directory of your public_html, the filesystem /tmp dir)
It means the code is fine and it is able to create the file.

To create the file in /home/john/public_html/tmp
Change the owner of directory /path/to/john/public_html/tmp, it should be apache
Quote:

# chown -R apache:apache /path/to/john/public_html/tmp
Now put the p3.php in the /home/john/public_html/tmp
Now execute the file, it should create the file in /path/to/john/public_html/tmp/myfile.txt if you have given the created file path in /home/john/public_html/tmp i.e. $ourFileName = "testFile.txt";
http://example.com/~john/tmp/p3.php

jpollard 04-28-2014 09:18 AM

You will have to show the php file. We can't tell anything about what it is/is not doing otherwise.

It would also help to know what distribution you are using.

John VV 04-28-2014 01:38 PM

Also the Apache server should be ran as a deamon
as the user
user=apache
group=apache

the user "apache" should not have a home folder

and you really DO NOT!!! want to run the apache software as root
-- nothing good will come of that --

unSpawn 04-28-2014 01:47 PM

...also if this:
Quote:

Originally Posted by msp4422 (Post 5160481)
I gave all permissions to parent directory tmp and also executed the below commmand.

means you ran a 'chmod -R 777 /some/directory' then please undo that before doing anything else.
It's not the "right" way to accomplish things in a secure and safe way and it's not the "right" way to troubleshoot problems.


All times are GMT -5. The time now is 10:29 AM.