LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-13-2008, 07:43 AM   #1
phillpafford
LQ Newbie
 
Registered: Jun 2008
Distribution: centos 5
Posts: 1

Rep: Reputation: 0
php copy() + linux permission issue


Hi All,

Newbie here, I had originally posted on this forum (Link below)

webdeveloper.com/forum/showthread.php?p=897948#post897948

Having an issue with the copy(), I know it's a permission issue with the Apache/Nobody user.

Wanted to know if anyone had a good work around, here is my issue:

I have a template.php file that I just want to copy with a new name to it and place it in the root html dir /var/www/html/new_template.php

I have made a TEMP dir that I chown to apache and I can copy the file there, but can not move it to the /var/www/html/ from /var/www/html/TEMP/ because of the permission issues.

I have looked into a FTP solution, but didn't find anything that would work the way I wanted it to. (Can you FTP to your own server, LOCALHOST? and copy a file this way?)

Any insight would be great and thanks for the help.

the TEMP with owner as apache, the /var/www/html is root.

I can create a copy of the template file by giving apache ownership of the TEMP dir with 777 permissions, but I don't like this, but nothing else works.

I guess I am stuck with the user moving the file manually :-(

I didn't think it would be this hard just to copy a template file with a new file name in a different directory would be that hard.

Anyone else have any other ideas?

Thanks in advance,

Phill
 
Old 06-14-2008, 08:39 AM   #2
AdaHacker
Member
 
Registered: Oct 2001
Location: Brockport, NY
Distribution: Kubuntu
Posts: 384

Rep: Reputation: 32
There's no magic trick here. If you're trying to copy the file into /var/www/html, then you need to make that directory writable to Apache, period. That's just the way filesystem security works. You can do that by changing the permissions, the ownership, or both.

If you don't want to change the directory permissions, there are other ways to do it. However, they're not nearly as straight-forward as just changing the directory permissions or ownership.

There's the FTP to localhost trick you mentioned. That involves setting up an FTP server with a user account that can write to your target directory. I wouldn't recommend that unless you're in a shared hosting environment and don't have access to other methods.

There's the SCP to localhost trick. You could set up the Apache account with SSH key auth to authenticate to the local machine as root, which would allow you to use scp to copy the file as root without a password.

There's always cron jobs. You can create a different directory with write permissions, write your files there, and have a cron job running as root that moves them to the final destination every so often. But I wouldn't bother with that unless you'll be creating a lot of files.

And, of course, you could always reconfigure your server. You could set Apache with suexec CGI and have it run PHP as the owner of the target directory. That way, PHP wouldn't have any permission problems because its user would own the directory. Of course, that's not such a good idea if root owns the directory. In that case, you'd want to change the ownership, which is the sort of thing you were trying to avoid in the first place.

My recommendation: either change the permissions on /var/www/html or change your application to use a different directory that you're more comfortable changing the permissions on. Using any other method to accomplish a simple file copy is just making things waaaay more complicated than they need to be.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
DD copy reports permission denied error speedfreq Linux - Hardware 6 09-23-2009 06:30 PM
remote linux share permission issue rajan_juniku Linux - Networking 1 05-08-2007 04:44 AM
default access permission when we copy files bluenectar Linux - General 2 03-04-2007 09:09 PM
Stuck! No permission to copy files?? the shady one Linux - Newbie 3 08-24-2005 06:24 PM
Can't copy files from CD to hd. Says i don't have permission? dizzug7068 Linux - Newbie 6 05-12-2005 10:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:31 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