LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 04-28-2014, 08:05 AM   #1
msp4422
LQ Newbie
 
Registered: Apr 2014
Posts: 8

Rep: Reputation: Disabled
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.
 
Old 04-28-2014, 10:16 AM   #2
eklavya
Member
 
Registered: Mar 2013
Posts: 619

Rep: Reputation: 136Reputation: 136
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

Last edited by eklavya; 04-28-2014 at 10:20 AM.
 
Old 04-28-2014, 10:18 AM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
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.
 
Old 04-28-2014, 02:38 PM   #4
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 16,827

Rep: Reputation: 2409Reputation: 2409Reputation: 2409Reputation: 2409Reputation: 2409Reputation: 2409Reputation: 2409Reputation: 2409Reputation: 2409Reputation: 2409Reputation: 2409
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 --
 
Old 04-28-2014, 02:47 PM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531
...also if this:
Quote:
Originally Posted by msp4422 View Post
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.
 
  


Reply

Tags
ajax, apache, linux, php


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
[SOLVED] SSH - How can I only allow a key pair login for my user account not root account? shanekelly Linux - Security 5 01-25-2013 10:45 AM
[SOLVED] ssh-keygen always creates root user in comment Luminaro Linux - Newbie 3 10-24-2012 12:25 PM
LXer: Xandros Creates Enhanced User Experience for Netbook Users With Moblin V2 LXer Syndicated Linux News 0 06-03-2009 04:00 AM
is it legitimate and allowed and can be done to make another user account set uid and gid to null 0 to make another root account with different name and possibly not damage the debian system creating and using that new account BenJoBoy Linux - Newbie 12 01-29-2006 11:02 AM
KDE users - Having root file manager while still logged in as normal user thegeekster Linux - General 1 04-27-2004 11:47 PM


All times are GMT -5. The time now is 07: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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration