Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have set up a LAMP server and I have access via SSH and to the "it works" page from a web browser from inside my network (via ip address) and from outside using dyndns.

We have some Wordpress projects that sit in subdirectories in /var/www/wordpress1 /var/www/wordpress2, etc. I cannot access these sub directories from a browser in order to set up WP--or (I assume) to see the content on a browser. I get a 403 Forbidden error on my browser.

I assume that this is a permissions problem. Can you please tell me the proper settings for the permissions to:

  1. Allow the developers and me to read/write.
  2. to allow WP set up and do its thing
  3. Allow visitors to access the site(s) via the web.

I should also mention that the subfolder are actually simlinks to folder on another internal hdd--I don't think this will make a difference, but I thought I should disclose.

total 12
drwxr-xr-x  2 root root 4096 2012-07-12 10:55 .
drwxr-xr-x 13 root root 4096 2012-07-11 20:02 ..
lrwxrwxrwx  1 root root   43 2012-07-11 20:45 admin_media ->     /root/django_src/django/contrib/admin/media
-rw-r--r--  1 root root  177 2012-07-11 17:50 index.html
lrwxrwxrwx  1 root root   14 2012-07-11 20:42 media -> /hdd/web/media
lrwxrwxrwx  1 root root   18 2012-07-12 10:55 wordpress -> /hdd/web/wordpress

Here is the result of using chown -R www-data:www-data /var/www

total 12
drwxr-xr-x  2 www-data www-data 4096 2012-07-12 10:55 .
drwxr-xr-x 13 root     root     4096 2012-07-11 20:02 ..
lrwxrwxrwx  1 www-data www-data   43 2012-07-11 20:45 admin_media -> /root/django_src/django/contrib/admin/media
-rw-r--r--  1 www-data www-data  177 2012-07-11 17:50 index.html
lrwxrwxrwx  1 www-data www-data   14 2012-07-11 20:42 media -> /hdd/web/media
lrwxrwxrwx  1 www-data www-data   18 2012-07-12 10:55 wordpress -> /hdd/web/wordpress

I am still unable to access via browser.

share|improve this question
Please post the output of the command ls -la /var/www. – SirCharlo Jul 12 '12 at 16:52
please put that information in your question! – Jorge Castro Jul 12 '12 at 16:57
OK, it took a second for me to remember how to post code... – dpbklyn Jul 12 '12 at 17:05
Ok, well try chown -R www-data:www-data /var/www – SirCharlo Jul 12 '12 at 17:08
I think your problem now is that you are using links. Apache will not follow links. What you would do is move those files to /var/www and configure apache to use vitrualhosts. See Alternates, if you wish to use /hdd/web/wordpress would be to configure Apache (root directory) properly. You can configure apache to use links, but I do not advise it. See also – bodhi.zazen Jul 12 '12 at 18:37

First, you should ensure that your username is included in www-data group. If not, you can add your username as www-data group

sudo adduser $USER www-data

After that, you should change the ownership of /var/www to your username

sudo chown $USER:www-data -R /var/www

Next step, you should change permission to 755 (rwxr-xr-x), not recommend changing permission to 777 for security reason

sudo chmod u=rwX,g=srX,o=rX -R /var/www

Hope it helps...

share|improve this answer
didn't work for me, I add to use sudo chown www-data:www-data -R mywordpressdirectory/ – Louis Nov 20 '14 at 17:23
After change the ownership, you should change permission too. Have you change your permission to 755? – metamorph Nov 23 '14 at 1:27
He did with chmod. He's changing permission to 755 with sticky bits (to keep new files owned by www-data.) – Stuffix May 13 at 23:18

Apparently this is how it is recommended in the Ubuntu Server Guide:

Chapter 11. Web Servers.

1.4. Sharing Write Permission

For more than one user to be able to write to the same directory it will be necessary to grant write permission to a group they share in common. The following example grants shared write permission to /var/www/html to the group "webmasters"

I use www-data. Just replace "webmasters" with your group, be sure you add the user to the group of course.

sudo chgrp -R webmasters /var/www/html
sudo find /var/www/html -type d -exec chmod g=rwxs "{}" \;
sudo find /var/www/html -type f -exec chmod g=rws "{}" \;

I just tested it with Dreamweaver from my mac desktop and uploaded and replaced files added files etc and it retains the correct permissions with one exception, the local user becomes owner of new files along with www-data, but any files created by root in the html directory retain their ownership as root but are editable by local user.

$ls -l
$-rw-rw-r-- 1 localUser www-data 11505 May 28 09:56 index2.html
$-rw-rwSr-- 1 root  www-data 11535 May 28 09:58 index.html

Hope this clears up things and helps the weary, cause I know I was always weary of this situation, but now it is clear to me.

Oh and I highly recommend using sftp with keys to access your ftp, works great for me and don't need PureFTP or any other insecure method of delivering the files to the website. There's a good few tutorials on Digital Ocean site all about securing your server with ssh keys:

How To Configure SSH Key-Based Authentication on a Linux Server

share|improve this answer
1) that leaves setgid bits on files. Looks odd, does nothing, opens door to security issues if users can make files executable and run them. But if you're happy with setgid on files, replace complex finds with just sudo chmod -R g=srwX /var/www/html. – temoto Feb 9 at 19:32
2) find -exec chmod will spawn a separate program for each file, which is time consuming and puts unneeded pressure on system if you have many files. Solution: sudo find /var/www/html -type f -print0 |sudo xargs -0 chmod g=rw. xargs will try to feed as many files paths as possible to a single instance of chmod. – temoto Feb 9 at 19:33

Check that Apache has execute rights for /hdd/web/media and /hdd/web/wordpress.


chmod o+x /root /root/site /root/site/about

Moreover, Apache has to be configured to allow access to the directory on the filesystem. This has to be done by a system administrator by inserting a directive in the apache configuration files (httpd.conf).

Since the real directory is inside the web root it must be accessible, but FollowSymLinks may not have been enabled for the directory - this also has to be added to the directive.


share|improve this answer
Thanks all...I have decided to go with the path of least resistance...removed the symlinks. All works perfectly. – dpbklyn Jul 13 '12 at 14:20

Reading around the instalation guide for Ubuntu..

chown -R www-data /usr/share/wordpress

Maybe it could be easier to instal it this way instead of trying to unzip the files on /var/www

any way wordpress runs on apache... right? if you want to do it that way.. you show do as @metamorph an then give permisson on apache2 httpd.conf like this:

<VirtualHost *:80>
        ServerName site
        ServerName site.domain
        DocumentRoot /srv/www/

        DirectoryIndex index.php


and then default-server.conf.

<Directory "/srv/www/">
        Options None
        AllowOverride None
        Order allow,deny
        Allow from all

Maybe is best to do the step by step

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.