I'm new to Ubuntu.

I have installed LAMP on Ubuntu and everything is OK but while I copy a folder into /var/www it is not accessible via URL. I have tried following commands:

sudo cp -r Desktop/site /var/www
sudo chown myuser /var/www -R 
sudo chmod 755 /var/www -R


sudo chown myuser /var/www/site -R 
sudo chmod 755 /var/www/site -R

I event don't see the folder while try list directories (http://localhost/). However, it's ok while I create a folder manually using sudoo mkdir command.

What should I do and what's the matter ?


You have your syntax wrong. Try:

sudo chown -R <username> /var/www


sudo chmod -R a+rwX /var/www

but the most correct way would be:

sudo groupadd www
sudo useradd -g <username> www
sudo chown -R :www /var/www
sudo chmod -R g+rwX /var/www
sudo chmod g+s /var/www
| improve this answer | |

With some changes to Timo's helpful answer and a little more search, I solved it finally as below:

sudo adduser <username> www-data
sudo usermod -a -G <username> www-data
sudo chown :www-data /var/www -R
sudo chmod g+rwX /var/www -R
sudo chmod g+s /var/www

Then re-login and now it's working!

| improve this answer | |

You should change the ownership like this:

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

And then, change the directory permission like this:

sudo chmod -R 755 /var/www

Hope these help.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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