Linux permission problem using php file_put_contents

Linux ltfx1815
Apache/2.2.15 (Red Hat)
php 5.3.3
I have created some sitemap.xml files.  I can ftp them to the server with no problem. I can use putty to log in as root and see the files and see their permissions and owner (discover). I also log in to putty using user name discover.

-rwxrwx--- 1 discover discover    6752 Jul 15 09:46 SiteMapIndex.xml

When I try to use the web interface to rebuild the files, I get Warning: file_put_contents(../SiteMapIndex.xml): failed to open stream: Permission denied.

The code works fine on my desktop (php 5.6) I don't think its a code problem, I know its a permission problem. The server is pretty locked down. I do not understand enough about linux/apache to permanently change the permission of those files so that I access them from web interface.

I believe the ftp user and web interface user are the same login.  I do not know how to check who I log in as using web interface.  (its all a secure connection that I don't have access to.  I know all the sql user's and their permissions, just not the linux users permissions.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jan SpringerCommented:
If you're using the web interface to modify files owned by the account used to ftp, then it cannot.

The files need to be writable by the web server user.
DonnaOsburnAuthor Commented:
How can i find out what account the web server interface uses?
I believe they are the same account.
Jan SpringerCommented:
ps -Af | grep httpd

The first column is the username -- typically "apache".
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

DonnaOsburnAuthor Commented:
I appreciate your help. however - what is this code.  php code to put in web page? something to check in putty?  if i run the command in putty i get:
 ps -Af|grep httpd
root      7394     1  0 Jul14 ?        00:00:04 /usr/sbin/httpd
apache    9995  7394  0 11:06 ?        00:00:00 /usr/sbin/httpd
apache   10066  7394  0 11:06 ?        00:00:00 /usr/sbin/httpd
apache   10372  7394  0 11:08 ?        00:00:00 /usr/sbin/httpd
apache   11118  7394  0 11:11 ?        00:00:00 /usr/sbin/httpd
apache   11529  7394  0 11:14 ?        00:00:00 /usr/sbin/httpd
apache   11530  7394  0 11:14 ?        00:00:00 /usr/sbin/httpd
apache   11538  7394  0 11:14 ?        00:00:00 /usr/sbin/httpd
apache   11540  7394  0 11:14 ?        00:00:00 /usr/sbin/httpd
apache   11544  7394  0 11:14 ?        00:00:00 /usr/sbin/httpd
apache   11545  7394  0 11:14 ?        00:00:00 /usr/sbin/httpd
apache   11548  7394  0 11:14 ?        00:00:00 /usr/sbin/httpd
apache   11549  7394  0 11:14 ?        00:00:00 /usr/sbin/httpd
apache   11550  7394  0 11:14 ?        00:00:00 /usr/sbin/httpd
apache   11563  7394  0 11:14 ?        00:00:00 /usr/sbin/httpd
apache   11690  7394  0 11:15 ?        00:00:00 /usr/sbin/httpd
apache   11828  7394  0 11:16 ?        00:00:00 /usr/sbin/httpd
apache   11832  7394  0 11:16 ?        00:00:00 /usr/sbin/httpd
apache   11845  7394  0 11:16 ?        00:00:00 /usr/sbin/httpd
apache   11869  7394  0 11:16 ?        00:00:00 /usr/sbin/httpd
apache   11871  7394  0 11:16 ?        00:00:00 /usr/sbin/httpd
apache   12121  7394  0 11:17 ?        00:00:00 /usr/sbin/httpd
apache   12239  7394  0 11:18 ?        00:00:00 /usr/sbin/httpd
apache   12268  7394  0 11:18 ?        00:00:00 /usr/sbin/httpd
root     12270 21035  0 11:18 pts/1    00:00:00 grep httpd

which doesn't even show me the ftp user or other users.  So i don't know what you what me to do with this command. Sorry!
Jan SpringerCommented:
what I am saying is that you logged in via ftp as the user and group "discover".  account "discover" has write access.

the web server runs under account "apache".

if you html directory is (for example), /var/www/html, the

chgrp -R apache /var/www/html
chmod 771 /var/www/html

i don't like this because it gives apache complete authority to write anywhere within the html directory.

sometimes it's better to just change the group and permissions of the file, files, or directory needed by apache to write.
DonnaOsburnAuthor Commented:
Well that is all i want to do. change the write permission on these siteindex.xml files.  But i don;t know how to do it and make it permanent.
Jan SpringerCommented:
do you have ssh access to the server?  if so,

#change to root, you can also use sudo intead
su -

#change to the html directory, if it's somewhere else, change below
cd /var/www/html

#set the permissions and ownership
chgrp apache siteindex.xml
chmod 660 siteindex.xml
DonnaOsburnAuthor Commented:
will these commands accept wildcards? i have over 50 files. I don't want to do the entire directory.

It appears chgrp to apache will let me have access!

-rwxrwx--- 1 discover apache 6752 Jul 15 09:46 SiteMapIndex.xml

i assume the first one (discover) - is the creator of the file and the second one (apache) is now the owner?
Jan SpringerCommented:
cd /var/www/html

find . -name SiteMapIndex.xml -exec chgrp apache {} \;
find . -name SiteMapIndex.xml -exec chmod 660 {} \;


cd /var/www/html

chgrp -R apache SiteMapIndex.xml
chmod -R 660 SiteMapIndex.xml

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DonnaOsburnAuthor Commented:
Thank you for your patience and help!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.