Can't create any folder in htdocs on ubuntu

4

13

How do I set the permission, so I can? The "Create new folder" option is greyed out. I tried this: sudo chmod -rw /opt/lampp/htdocs

But it still doesn't work. When I add sudo chmod -rw 755 /opt/lampp/htdocs, it says: "755" no such file or directory

Blub

Posted 2011-04-10T10:09:07.880

Reputation: 448

1have you tried "chmod -R 777 /opt/lampp/htdocs" – HTDutchy – 2011-04-10T10:16:04.080

Answers

15

You are mistaking how chmod and the unix file permissions operate.

You need to configure the /opt/lampp/htdocs directory so that the user you are logged in as has permission to write. You also need to ensure that what you write in there can be read by whatever web server LAMPP uses (I'm not familiar with LAMP unfortunately.)

First you need to look at who is owning /opt/lampp/htdocs:

$ ls -ld /opt/lampp/htdocs

Should return something like:

drwxr-xr-x 4 lampp www 4096 2011-03-22 12:43 /opt/lampp/htdocs

The first bit (dwrxr-xr-x) is the file permissions. "lampp" is the owner of the directory, and "www" is the group-owner of the directory. You need to note this one.

First off let's sort the group. If the group is anything except "root" then all is well and good and you can skip this section:

If it's "root" it will need changing to something more sensible. Let's make a new group for it to belong to:

$ sudo groupadd www

Then change the group on the directory:

$ sudo chgrp -R www /opt/lampp/htdocs

Now you need to make the web server run as the group www. If the web server is Apache then you should check the /etc/apache/httpd.conf file and edit the "Group" setting accordingly. I don't know the setting for other web servers.

Now this is where you'd skip to if you didn't need to switch the group from root to something else.

We now need to address the permissions on the directory. We want to be using some very special permissions, called the "setgid" bit.

$ sudo chmod 2775 /opt/lampp/htdocs
$ ls -ld /opt/lampp/htdocs
drwxrwsr-x 4 lampp www 4096 2011-03-22 12:43 /opt/lampp/htdocs

You see the permissions have now changed somewhat. Let's explain these.

  • The first letter is the file type. In this case "d" is for Directory.
  • The next three, "rwx" are the permissions the owner (lampp) has on the directort. r = read, w=write and x=see the directory contents.
  • The next three, "rws" are for the group-owner (www), but you notice the x in this case is actually an s - we will come to that in a moment.
  • The last three, "r-x", are for everybody else. That is read, and see the content of the directory. No writing.

The "s" in the group permissions is called the "setgid" bit. This is a special permission which causes any files created in the directory to inherit the group-owner from the directory itself. So if user "fred" in group "users" makes a file in there it would be owned by "fred" in group "www". This is very useful for a shared area where multiple people all read and write the same files.

But as it stands you still don't have the ability to write to that area. Why? Because you're not in the "www" group. Let's rectify that now:

$ sudo usermod -aG www blub

Replace "www" with the group-owner of the /opt/lampp/htdocs directory you noted near the beginning.

You will need to log out and in again for this change to take effect - your group memberships are read at login time.

Once you have done that you should suddenly find you can now magically write files in /opt/lampp/htdocs.

If you have other users on the system that you want to allow to write to there, just add them to the www group with the usermod -aD www <username> command.

Majenko

Posted 2011-04-10T10:09:07.880

Reputation: 29 007

@Majenko check the /etc/apache/httpd.conf file and edit the "Group" setting accordingly.... I can't edit this file because I don't have permissions to write in that directory! Same problem.. – khaverim – 2014-08-31T02:55:02.353

@Majenko this simple terminal command is what fixed it for me: cd /opt/lampp then sudo chmod 777 -R /opt/lampp/htdocs – khaverim – 2014-08-31T02:57:59.070

@khaverim That may fix it, but it makes your whole web installation inherently insecure. Now anything and anyone can write to your web directory - anyone that has access or could gain access to your system through whatever means fair or foul can now publish anything they want on your website. That is how most phishing sites get hosted. – Majenko – 2014-08-31T09:44:58.940

This right here is why it's difficult to get people to switch to Linux ditros, even when they are technically proficient, cause who wants to bother with all this stuff when it would be much more straightforward in Windows or Mac. – Ghos3t – 2018-11-11T18:14:30.110

Thank you :D. That worked perfectly. (it's strange though that it says "nobody" as the owner?) drwxrwsr-x 4 nobody www 4096 2009-08-27 10:36 /opt/lampp/htdocs – Blub – 2011-04-10T10:56:55.963

"nobody" is just another user, albeit a reserved one. nobody is supposed to have minimal permissions for everything. You'll probably find that "nobody" has a UID of 65535 or something similar. – Majenko – 2011-04-10T11:00:14.137

Excellent answer and walk-through, saved my day- THANKS! – andig – 2011-10-12T18:58:57.600

2

This simple terminal command gave me full permissions to htdocs and I was able to start working on PHP projects

sudo chmod 777 -R /opt/lampp/htdocs

In response to Muhammed's comment, it would be better to use sudo chmod 755 -R /opt/lampp/htdocs

khaverim

Posted 2011-04-10T10:09:07.880

Reputation: 216

please avoid using chmod 777 for htdocs, see here why.. http://askubuntu.com/a/20110/267949

– Mohammed Sufian – 2015-09-30T19:15:36.923

1

you use EITHER +rw OR the octals, not both.

What you're trying to do is remove read and write privileges from a directory called 755 as well as /opt/lampp/htdocs.

In any case, you shouldn't be using xampp - you can get a more up to date, native install of a lamp stack - you can install it with tasksel.

Journeyman Geek

Posted 2011-04-10T10:09:07.880

Reputation: 119 122

I thought I'd use xampp because I know it from Windows and other people from Google searches suggested that it's more user friendly – Blub – 2011-04-10T10:50:33.570

actually, no. install a lamp stack using tasksel and phpmyadmin and you have most of xampp's functionality, sans the email server on the windows version. It also has a few security tweaks. other than needing two commands to install, its just so much easier - i download and extract stuff straight to /var/www, chown the files to www-data, and i'm good to go. – Journeyman Geek – 2011-04-10T11:11:02.577

"chown the files to www-data"? What does that mean? – Blub – 2011-04-10T12:15:32.980

chown - change ownership to a specific user - in this case www-data, which is more secure than changing the priviledges to read/write etc. – Journeyman Geek – 2011-04-10T13:25:14.733