Jason G. Designs

WordPress Themes, Design Tutorials, Linux Themes and more…

Ubuntu Linux, Permissions and a Local WordPress Install

Flames and codeUpon installing LAMP and WordPress 3.3 on my local computer, I ran into a couple issues when trying to put my own previously created themes into the wp-content/themes directory. Mainly, it was the “Connection Information” screen that may pop up when installing a theme, not being able to access the /themes directory and the Manage Themes screen not recognizing themes once I had access. This article describes how I researched then remedied those. I primarily followed the tutorials How To Install LAMP (Linux, Apache, MySQL, PHP) On Ubuntu 11.04/11.10 and How To Install The Latest WordPress Version On Ubuntu 11.10/11.04. I installed into a wordpress directory in var/www.

*This post has been updated in light of new information–particularly the Smashing Magazine article Proper WordPress Filesystem Permissions And Ownerships.

Getting Rid of the “Connection Information” screen

After locally installing WordPress in Ubuntu Linux 11.10, I was asked to provide an FTP hostname, username and password when trying to download a theme. The issue was that I was not using ftp on a local install, therefore I probably did not know what to input in those fields. I tried every password and username combination I could think of: my WordPress admin username/password, my Ubuntu account’s username/password. None of these worked. This is because Apache does not have permissions to write to the wp-content directory. Luckily, I applied the information found in the article Why WordPress Asks for Connection Info.

  1. First, we need to see what user Apache is running under. Type the following into a New file in any text editor. Save As whoami.php in the /var/www directory (or wherever you set Apache to serve files from):
    <?php echo(exec("whoami")); ?>
  2. Open this file in a browser (for instance, localhost/whoami.php). It should reveal who the user is
  3. Next, we change the owner of the wordpress directory to the user that is shown with whoami.php. In my installation that user is www-data. Open the Terminal application and type:
    sudo chown -R user wordpress

Type in your super user password. In this case, replace user with www-data. The -R option is important, as it changes the owner for every file within the wordpress directory.

Now, you should be able to download themes and plugins and bypass the Connection Information screen. Many thanks go to Chris Abernethy for this solution.

Making sure WordPress’s Manage Themes Screen Can See Files Dropped into the /themes/ directory

First, an explanation is needed for the three numbers represented for the chmod command, as I really did not understand this concept when I originally wrote this post. The first number represents the owner of the file or directory (www-data), the second number represents the group the file belongs to, which currently is also www-data, the third number is anyone.

In addition, the numbers are calculated with 4 referring to read access only, 2 referring to write access (save and open files) and 1 referring to execute (move/delete files and directories). For each user type, the numbers are added to represent the total privileges. For example, the owner could have a total number of 7. What we want is the ability for our group to save, open, move and delete files as we please (at least in the wp-content directory).

  1. First, with the new method, I added my username group to the www-data group with the following command. Replace ubuntu username with your username:
    sudo usermod -a -G www-data  ubuntu username
  2. I Set permissions on the /var/www directory to 777. After reading many forums, someone suggested to set the permissions this way. This is normally very unsafe, but since this is a local install that only the owner can access, it should be okay. It is advised to NEVER set such loose permissions as 777 on directories in an online server. *I now set the permissions to 775 using the following method (be sure to change the directory to wherever wordpress is installed).
    cd var/www/wordpress
    sudo find . -type d -exec chmod 775 {} +
    sudo find . -type f -exec chmod 775 {} +

    The first find command gives the owner and group the ability to change and remove directories anywhere in the wordpress directory. If you want to limit this to only the wp-content directory, for instance, navigate there beforehand. The second command gives read/write access for files to the www-data group, read/write/execute access to our ubuntu user group and read access for anyone else

  3. By this time, I had some previously created themes to drop into the /themes/ directory. To test this, you can try manually downloading a theme, unzipping it and placing the theme’s inner folder in the /themes/ directory.
  4. Next, we need to change the group of the /wordpress/ directory so your ubuntu user account can have access to all of the files within:
    sudo chgrp -c -R ubuntu username /var/www/wordpress/

You can test if this works by opening up one of the theme’s files in a text editor and making a small change (an html comment or so); if you are able to save and see your changes in a browser, then it is successful.

You may ask, “Why not just stop at getting rid of the Connection Information screen and just upload a zip file for a theme?” Making sure the /themes/ directory is writable and visible to the Manage Themes screen will help those who need to develop a WordPress theme locally from scratch and preview as they are creating it.

I don’t consider myself an expert in Linux or WordPress. I literally learned this over two days of intensive Googling. But when I got it, I wanted to share my experiences immediately, as this may save people from a lot of frustration. Thank you for reading.

18 Comments

  1. Marcos says:

    Thanks a lot, just what I needed!

  2. Neat blog! Is your theme custom made or did you download it from somewhere?
    A theme like yours with a few simple adjustements would really make
    my blog jump out. Please let me know where you got your design. Many thanks

  3. Thanks for this tutorial 100% work for me 🙂

  4. Bruce says:

    Wow, marvelous weblog structure! How lengthy have you been blogging
    for? you make blogging glance easy. The entire look of your website is magnificent, as
    neatly as the content material!

  5. Jordan Jelinek says:

    Yeah, no kidding.

  6. Milton says:

    You save my day!

  7. Newwbea says:

    it shows me that in the terminal
    chown: cannot access `wordpress’: No such file or directory

    1. Jason Gonzalez says:

      Hello Newwbea. I don’t know if you’ve already resolved this issue, but was WordPress installed in your /var/www directory or somewhere else?

  8. Uytko says:

    Hi,
    This way worked for me

    cd /var/www/wordpress/wp-content/themes
    su www-data -c ‘wget http://wordpress.org/extend/themes/download/eclipse.2.0.1.zip‘; su www-data -c ‘unzip eclipse.2.0.1.zip’; rm eclipse.2.0.1.zip
    ls -l

    regards

  9. I did what you told, but nothing worked. Than I realized what the problem was.

    I installed wordpress through the terminal, so I had a symbolic link in var/www, while the archives were at usr/share (I’m using ubuntu 12.10). I tryed to do the same thing with usr/share/wordpress, but nothing worked.

    The solution: manually create a new wordpress file. It was actually easier than the method you described. I just executed a sudo chown www-data with a couple of files and then it was set.

  10. tay says:

    thanks
    you have been very helpful
    everything works fine now

  11. tay says:

    Using 12.04. Had a problem when using the command “grp”

    No command ‘grp’ found, did you mean:
    Command ‘igrp’ from package ‘irpas’ (multiverse)command not found and then give a whole array of options
    Command ‘gp’ from package ‘pari-gp’ (universe)
    Command ‘grep’ from package ‘grep’ (main)
    Command ‘grpn’ from package ‘grpn’ (universe)
    Command ‘grap’ from package ‘grap’ (universe)
    Command ‘gri’ from package ‘gri’ (universe)
    Command ‘arp’ from package ‘net-tools’ (main)
    Command ‘gip’ from package ‘gip’ (universe)
    Command ‘gpp’ from package ‘gpp’ (universe)
    Command ‘gpr’ from package ‘gpr’ (universe)
    Command ‘gap’ from package ‘gap-core’ (universe)
    Command ‘gyp’ from package ‘gyp’ (universe)
    Command ‘gcp’ from package ‘gcp’ (universe)
    Command ‘grc’ from package ‘grc’ (universe)
    Could you tell me which command I should use.
    Thanks

    Command ‘grn’ from package ‘groff’ (main)

    1. Jason Gonzalez says:

      Hello tay. The command to change the group for directories is chgrp.

  12. dt says:

    works like a dream. thanks a million
    had a slight problem, just a matter of the full directory of wordpress is required in the command
    sudo chown -R [user] wordpress

  13. Jason Gonzalez says:

    You’re welcomed. I am also thankful for the resources I found with Google for helping me write this article as well.

  14. scurveedog says:

    Jason G you are AWESOME!!!

    I too was in google and after 100’s of websites yours was the first and only one that solved this issue for me…thank you for the complete, concise instructions and sharing your knowledge

  15. TRX says:

    My wordpress blog worked after modify according your suggestion.

    Thanks

  16. datboip says:

    holy effin shtufff…. I was stuck for a week ftping this and that,,, This was all i needed! Thanks!!!

Trackbacks and Pingbacks

Trackback URL for this post: https://www.jasong-designs.com/2012/01/14/ubuntu-linux-permissions-and-a-local-wordpress-install/trackback/

  1. […] Policy « How to Bring Your WordPress Theme up to Current Standards Ubuntu Linux, Permissions and a Local WordPress Install […]

  2. […] you are developing this theme on Linux, please see the blog post Ubuntu Linux, Permissions and a Local WordPress Install before getting […]

  3. […] you are developing this theme on Linux, please see the blog post Ubuntu Linux, Permissions and a Local WordPress Install before getting […]

  4. […] with that information, see the article Ubuntu Linux, Permissions and a Local WordPress Install to give your user account permissions. From that article, replace the folder reference in chgrp […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.