Permission issues in the www folder of my Raspberry Pi

I run into this issue from time to time when I (re-)install Raspbian on one of my Raspberry Pi. I want to quickly install WordPress having installed phpmyadmin and MySQL already, but my user pi does not have write access to /var/www/html folder. There is an official way of installing WordPress, but that assumes you never want to manually touch any of the files within www root. It is maninly true for most users probably, but I develop plugins, so I need to touch files withing wp-content/plugins folder on a regular basis. In the same time I want to be able to use the WordPress UI to install/remove plugins, run updates, etc. So I can’t just change the ownership to user pi. Here is how I solved this problem.

1. Create a new directory for the WordPress installation and go there. In this case I’ll call it test-blog, so the command will be

sudo mkdir /var/www/html/test-blog
cd /var/www/html/test-blog

2. Download WordPress with

wget http://wordpress.org/latest.tar.gz

3. Unzip it with

tar xzf latest.tar.gz

4. Move files out of wordpress directory

sudo mv wordpress/* .

5. Delete empty wordpress directory and latest.zip

sudo rm -rf wordpress latest.tar.gz

6. Set permissions
Let Apache be owner of the directory

sudo chown www-data:www-data  -R *

Change directory permissions rwxr-xr-x

sudo find . -type d -exec chmod 755 {} \;

Change file permissions rw-r–r–

sudo find . -type f -exec chmod 644 {} \;

Now you are ready to run the WordPress installator and setup your site. Once you finished with that, follow the instructions to tighten security as outlined in Hardening WordPress.