Sunday, March 24, 2013

Ubuntu Linux, Permissions and a Local WordPress Install

flames_and_codeUbuntu Linux, Permissions and a Local WordPress Install

Upon 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 theManage 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.

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/wwwdirectory (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


This part took literally days and hours of setting and resetting permissions to figure out what works best. This may not be optimal for everyone, but this worked for me as a newbie to Linux.

  1. 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 on directories in an online server
    sudo chmod -c -R 777 /var/www

    If anyone has a less permissive way to do this, please let me know in a comment below.

  2. 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.

  3. Next, we need to change the group of the /themes/ directory so our current user can add and remove files and directories:
    sudo chgrp -c -R [ubuntu username] /var/www/wordpress/wp-content/themes/

    The Ubuntu username is a user account name. I would replace that withjason in my account

  4. When I dragged the theme to the /themes/ directory, the owner was set to jason (my Ubuntu username). But, in order for the Manage Themes admin screen to recognize the theme, the owner of the directory needs to be set towww-data (in my case)
    sudo chown -c -R www-data /var/www/wordpress/wp-content/themes/[name-of-theme-directory]


  5. Changing the owner on this directory recursively gets rid of the originalchmod settings, so we must restore the 777 setting to the theme’s directory:
    sudo chmod -c -R 777 /var/www/wordpress/wp-content/themes/[name-of-theme-directory]



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.

No comments:

Post a Comment