Find the answer to your Linux question:
Results 1 to 8 of 8
I have mounted a folder from server1 to server2 to the media folder located in the document root of Apache web-server.. Which is installed in server2. But when the Apache ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2011
    Posts
    4

    Apache cannot write to NFS mounted folder. File size is always zero.


    I have mounted a folder from server1 to server2 to the media folder located in the document root of Apache web-server.. Which is installed in server2. But when the Apache tries to write a file to this mounted folder an actual file is created but the content is not written.. it always shows file size as 0 bytes. Please help me to resolve this issue.

    these are the steps I used to setup NFS mount..
    For this I have chosen 2 Linux machines running CentOs 5.4

    1) I have chosen server1(192.168.1.1) as NFS server And Server2((192.168.1.2)) as client.

    2)installed nfs-utils on both machines using the command yum install nfs-utils.

    3) Then I have edited the file /etc/exports on server1 using vim and added the entry
    /home/user/media 192.168.1.2(rw)
    Then saved it
    Again added necessary entry in host.allow & host.deny files
    Then started the portmap service and nfs service.
    I want these files to be manipulated by appache on server2 so I have set the user and usergroup to apache:apache for this folder.

    4) Now from server2 I have started portmap and nfs.. then mounted this folder.. using the command
    mount 192.168.1.1:/home/user/media /var/www/html/media
    Every thing was correct till here... The folder from the server1 is now listed in server2.. i can now modify any file or folder inside the mounted folder from server2. But when Apache tries to write a file to this mounted folder an actual file is created but the content is not written.. it always shows file size as 0 bytes.

    Is this issue related to the user permission? or is this a serious mistake I did during my NFS mount steps? Can someone please help me in resolving this issue..

    Thanks!
    Last edited by ackurup; 11-25-2011 at 05:31 PM.

  2. #2
    Just Joined!
    Join Date
    Jan 2011
    Location
    Fairfax, Virginia, USA
    Posts
    94
    Hi ackurup,
    It sounds like your experiencing a problem with Unix permissions. I think from what your saying above that you can manually edit files on one machine and observe the differences on another machine. Here is what I'd do as the next step ... if your running Ubuntu, you can try editing /etc/apache2/envvars and temporarily change APACHE_RUN_USER and APACHE_RUN_GROUP to your user and group then run "/etc/init.d/apache2 restart". Don't forget to put things back they way they were however.

  3. #3
    Just Joined!
    Join Date
    Nov 2011
    Posts
    4
    Hi BrianMicek, Thanks for the reply... But I am using CentOS 5.4 and I can't locate a file like the one you mentioned... I tried changing the user & usergroup from the apache config file(httpd.conf).. But the apache did not start I am getting the following error..
    "Error:\tApache has not been designed to serve pages while\n\trunning as root. There are known race conditions that\n\twill allow any local user to read any file on the system.\n\tIf you still desire to serve pages as root then\n\tadd -DBIG_SECURITY_HOLE to the CFLAGS env variable\n\tand then rebuild the server.\n\tIt is strongly suggested that you instead modify the User\n\tdirective in your httpd.conf file to list a non-root\n\tuser.\n
    "

  4. #4
    Linux Enthusiast scathefire's Avatar
    Join Date
    Jan 2010
    Location
    Western Kentucky
    Posts
    626
    So when you write your file, is there anything in the logs (most likely /var/log/httpd/error.log).

    In order to actually test whether apache is able to write to that share try logging in as apache and writing a test file.

    Say the username is apache, as root:
    Code:
    su - www -s /bin/bash
    Now try to write a test file to your NFS share.
    linux user # 503963

  5. #5
    Just Joined!
    Join Date
    Nov 2011
    Posts
    4
    Quote Originally Posted by scathefire View Post
    So when you write your file, is there anything in the logs (most likely /var/log/httpd/error.log).

    In order to actually test whether apache is able to write to that share try logging in as apache and writing a test file.

    Say the username is apache, as root:
    Code:
    su - www -s /bin/bash
    Now try to write a test file to your NFS share.
    Hi scathefire, I tied the method you mentioned.. You are right... I could create a file using the command touch.. But I cannot edit and save the content into the file using vim... How can we set the permission for apache to write to this partition? Please guide me...
    Thanks!

  6. #6
    Just Joined!
    Join Date
    Nov 2011
    Posts
    4
    Oh.. sorry it was not because of the write permission I could write to the partition as user apache using the vi command.. So the issue is not with the user permission...

  7. #7
    Linux Enthusiast scathefire's Avatar
    Join Date
    Jan 2010
    Location
    Western Kentucky
    Posts
    626
    have you checked selinux?

    Code:
    sestatus
    If its enable, try setting it to permissive and trying it again.

    Code:
    setenforce permissive
    try on both server and client
    linux user # 503963

  8. #8
    Just Joined!
    Join Date
    Dec 2012
    Posts
    1
    Did you manage to resolve this ? Sounds like a problem I am currently experiencing.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •