Linux - GeneralThis 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
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.