Support » Installing WordPress » Folder permission on LINUX UBUNTU

  • I am having problems with my permission setting in my home directory. I am using Ubuntu as a webserver and I have a number of wordpress websites.

    The user I log into the system is “USER”
    The home folder is titled “USER”
    Inside the USER folder I have a folder titled “WEBSITE”
    Inside the WEBSITE folder I have a wordpress website.

    I have set up VFTP so I can update my wordpress files using FTP. I am using the USER name and password to do this. I am able to log into my website from another computer and update the files using the ftp services within wordpress in order to update the version of wordpress and the plug-ins.

    The problem I am having is that I cannot upload a picture when I create a post.

    Here is some more background information about my setup.

    I have assign the name and group for all of my folder, located inside my USER/WEBISTE folder to so that everything is owned by www-data:www-data. I did this because I have been told that wordpress uses the www-data user and group which is the same user and group as Apache2 running on Ubuntu.

    The permission settings for these folders are the following:

    USER folder: Permission= 755, owner = USER:USER
    WEBSITE folder: permission=755, owner = USER:USER
    wp-content folder: permission= 755, owner = www-data:www-data
    uploads folder: permission =775, owner = www-data:www-data
    2011 folder: permission=775, owner = www-data:www-data

    I am attempting to upload a picture from within wordpress to the USER/WEBSITE/wp-content/uploads/2011 directory.

    I get an error message stating that wordpress cannot create the folder 02. Check your permission setting for the parent directory…..Apparently WordPress needs to create a month folder, titled 02 for February, for when you upload a new picture.

    I am stumped on what might be preventing me from creating a folder. I even attempted to create the folder manually…which was successful. However, WordPress did not recognize the new folder. So I am not sure what is going on.

    How do I setup WordPress so it can create folder, upload files and manipulate the website files?

    Can anyone help?

    Spindler

Viewing 15 replies - 1 through 15 (of 17 total)
  • wp-content folder: permission= 755, owner = www-data:www-data

    In a very compressed nutshell:

    1) First try setting permissions on /wp-content so it’s writable by the server. See if that lets you upload. If it does, chmod /wp-content back to 0755 afterward.

    I am stumped on what might be preventing me from creating a folder. I even attempted to create the folder manually…which was successful. However, WordPress did not recognize the new folder.

    2) WordPress files should be owned by your username and writable by the web-server (www-data in ths case).

    You may want to consider chown’ing your files and directories to [username]:www-data so that your linux user account actually owns and can manipulate them.

    sudo -i
    [password]

    cd to your wordpress root directory (the directory where the wordpress files are actually located) and recursively chmod files to 0644 and directories to 0755. Usually, Ubuntu will allow you to chmod the directory wordpress actually resides in, to 0750 if you like, with no issues. Bear in mind that if you do this before you upload your first media file from the dashboard, /wp-content needs to be writable to the server, to allow wordpress to create the uploads directory.

    Thread Starter Spindler

    (@spindler)

    This is helpful….but I need some more detail in how to do what you are saying.

    1. Do I need to change the owner so the files are writable by the server? Or do I need to set something so the server can write to the directory? What is the server user name?

    2. The comments you have here make sense to me. However, I tried this already and it did not help.

    One thing I failed to mention the actual error I got was the following….which shows that wordpress is attempting to write in a different location.

    “picture.jpg” has failed to upload due to an error
    Unable to create directory /var/www/html/wp-content/uploads/2011/02. Is its parent directory writable by the server?

    I attempted to write a picture file and wordpress was pointing to the VAR directory.

    A. Can I change wordpress so it writing into the write directory?
    B. Is it better to attempt to change the permissions in the var/html/wp-content director so wordpress can write to that file?

    I’m getting a lot of conflicting information from the content of your posts. Maybe you could help me to help you by answering a couple of quick questions:

    1) What version of Ubuntu are you using… Server or Desktop (with gnome GUI), and what release?

    2) How did you install WordPress… manually in /var/www/html, or by using apt-get, synaptic, or the package management system?

    3)How many WordPress installations are you actually trying to get fired up at present… one, or several?

    4) lastly, are you using name based virtual host containers to host several sites from /var/www/html, or are you just trying to get one WordPress site to run initially from the default apache2 document location?

    Thread Starter Spindler

    (@spindler)

    To answer your questions.

    1. I am running Ubuntu 10.04 with Gnome 2.30.2. I installed a LAMP server using the Ubuntu Software center. I am also running vftp. I installed GNome, LAMP and vftp using the software center.

    2. I have 9 websites. Each one uses a different wordpress version. Some are old. I originally had the sites on a hosting service and I copied the files over. Some of the sites I made from scratch on this server. I assume all are displaying this problem. Most of the sites are work in progress or archive. I did not use apt-get, synaptic or a package management system.

    3. I am only concerned about one website right now. If I can get it fixed then I will apply the change to the rest of my sites and see what happens. If the fix does not work on the secondary sites it is not a big deal. I really need it on my primary site.

    4. Yes I am using the virtual server managed by Apache2. The virtual host file points to the home/USER/WEBSITE directory. It looks like it works ok. There is nothing pointing to the var directory. so I do not know why wordpress wants to update that location.

    On your local Ubuntu Server, your WordPress files, in every instance, need to be owned by your user account and group owned by the web server account. The user account is your linux user name. The web server name on Ubuntu is www-data. So, once again, your wordpress files need to be recursively chown’ed to : [username]:www-data

    They also need to be recursively chmod’ed to files 0644, and directories 0755.

    The root directories themselves ( where each instance of WordPress resides ), can be chmod’ed to 0750, and should be owned by [username]:www-data.

    The /wp-content directory (ies) will need to be chmod’ed to a writable state ( let’s assume 0777 to remove any doubt ) in order for WordPress to create the “uploads” directories on the first attempt at uploading any media from the dashboard. After that it ( /wp-content directory) should be set back to 0755.

    Beyond that, you are dealing with Apache configuration, and server setup and administration issues.

    Thread Starter Spindler

    (@spindler)

    I tried this. Weird thing happened. When I changed the owner on the files and folder to USER:www-data my website went down.

    I could not access the website at all using a browser, such as firefox or explorer. I changed the file permission on the wp-login.php file to 777 to see if I can access that page. However, I could not.

    I change the directorys and file owner back to www-data:www-data and the problem went away. So I know that www-data:www-data allows everyone to access the site. However USER:www-data prevents everyone from access the site.

    What could be preventing USER:www-data from working as intended?

    Your issues appear to be related to server setup and administration at this point, and not WordPress.

    What could be preventing USER:www-data from working as intended?

    Only you know how you have set-up your server and user accounts, and whether or not the method you are using to recursively chown and chmod files and directories is in fact being effective. My recommendation is to take a breather, and find yourself one of the many, many, written and video tutorials for WordPress on Ubuntu that are available on the web. Compare what you have done, to what others have done, and perhaps something will stand out.

    Some tips:

    The default location for Apache2 to serve documents from in Ubuntu, is /var/www. Maybe create directories for each of your sites inside /var/www, and then create symlinks to them in your home directory, instead of trying to actually serve documents from “Home”, if the machine you are using for your server is going to be a”single user” setup. ( if your user will be the only account on the server )

    Example:

    you@yourbox:~$ sudo -i
    [sudo] password for you: [password]
    root@yourbox:~# cd /var/www
    root@yourbox: /var/www# mkdir site1
    root@yourbox: /var/www# chown you:www-data site1
    root@yourbox: /var/www# chmod 0750 site1
    root@yourbox: /var/www# logout
    you@yourbox:~$ ln -s /var/www/site1 /home/you/site1
    you@yourbox:~$ exit

    Now install wordpress in the site1 directory ( you can copy the wordpress files to /site1 directly by using the “shortcut” that’s in your home directory, or if you are actually running an ftp server on the box, you can do it that way, your choice. Then go to another machine on your network and install WordPress using the static internal network address you assigned to your development server:

    //192.168.x.x/site1/wp-admin/install.php

    Repeat the process for as many different sites as you like, altering just the name of the directory for each one.

    virtual hosts are added a little differently in Ubuntu with Apach2.
    “sites-enabled” and “sites-available” will be the keywords if you need to search out that information.

    I had this problem on my local dev environment where I have a ubuntu/apache2 server.

    I just changed the apache user to my user account as follows:

    edit the file /etc/apache2/envvars

    locate lines:

    export APACHE_RUN_USER = www-data
    export APACHE_RUN_GROUP= www-data

    and modify to the user who installed wordpress (in my case ‘phil’)

    export APACHE_RUN_USER = phil
    export APACHE_RUN_GROUP= phil

    Save the file and then restart apache.

    Now when you upload the media files the upload directories and files have user/group the same as the rest of the workpress file structure.

    Thread Starter Spindler

    (@spindler)

    Thanks a lot. This has helped assign my USER name to each directory and file.

    However, wordpress is still pointing to the var directory. Not really sure how to correct this. i attempted to upload a file and this is the error I see.

    “picture.jpg” has failed to upload due to an error
    Unable to create directory /var/www/html/wp-content/uploads/2011/02. Is its parent directory writable by the server?

    Have a read of this (but ignore points 1 and 6) …

    http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory

    Check you have the correct paths set up for the WordPress and Site URLs

    Note you can also set these urls in wp-config.php:

    define(‘WP_SITEURL’, ‘http://www.example.com/wordpress’);
    define(‘WP_HOME’, ‘http://www.example.com’);

    or

    define(‘WP_SITEURL’, ‘http://’ . $_SERVER[‘SERVER_NAME’]. ‘/wordpress’);
    define(‘WP_HOME’, ‘http://’ . $_SERVER[‘SERVER_NAME’]);

    Thread Starter Spindler

    (@spindler)

    This is useful. However, I am not sure how this will help me. Is there a way of fix or redirect wordpress so it follows the apache2 link to the correct location?

    WordPress want to save a file on the /var/www/html/wp-content/uploads/2011/02 directory. However that file does not exist. it looks like var/www/ and inside this folder is an apache2 file for my server admin page. All other redirect files are managed by apache2 and point to each website.

    I think the problem might be with apache2? Any ideas how this might be able to be fixed?

    I’m afraid I’m no expert on apache so not sure what you mean by redirect files.

    Are you not defining a virtual server for each site? That is what I have used to host multiple sites including wordpress sites on my local environment.

    If you need some help with setting up virtual servers in apache I can post the links I used to guide me through it.

    Is there a way of fix or redirect wordpress so it follows the apache2 link to the correct location?

    From what I can gather, mainly from your own statements:

    I am having problems with my permission setting in my home directory. I am using Ubuntu as a webserver and I have a number of wordpress websites
    Inside the USER folder I have a folder titled “WEBSITE”
    Inside the WEBSITE folder I have a wordpress website.

    As I mentioned earlier, Apache2 serves documents by default from /var/www.

    Unless you know how to properly configure apache2 to use per-user web directories, I strongly recommend you serve your wordpress documents from /var/www, not from your Home directory – as I outlined above for you. I shouldn’t think there would really be any need to do anything other than that on a home development server. (just my opinion). You are really putting yourself through a lot of agony over a 20 minute task.


    Apache2 “version 2.2” “per user web directories” “how to”

    Thread Starter Spindler

    (@spindler)

    Hello Clayton James,

    Yes It appears that way… However, this is not my first attempt in setting up this server. My first attempted used the var/www directory. When I first started to set it up everything seamed ok but then I started to develop some security and system update issues that caused more grief then I wanted and I eventually had to format the drive and start over again with a fresh install. I need to avoid this from happening again so I want to spend just a little more time in investigating the issues and all possible solutions before I open a new security/config vulnerability.

    Thanks for your help. I am taking your ideas into consideration and will have to implement your idea if I cannot overcome this pointing issue.

    Spindler

    Ive had the same problem, but this solved it

    I had this problem on my local dev environment where I have a ubuntu/apache2 server.

    I just changed the apache user to my user account as follows:

    edit the file /etc/apache2/envvars

    locate lines:

    export APACHE_RUN_USER = www-data
    export APACHE_RUN_GROUP= www-data

    and modify to the user who installed wordpress (in my case ‘phil’)

    export APACHE_RUN_USER = phil
    export APACHE_RUN_GROUP= phil

    Save the file and then restart apache.

    Now when you upload the media files the upload directories and files have user/group the same as the rest of the workpress file structure.

    Many Thanks

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Folder permission on LINUX UBUNTU’ is closed to new replies.