Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I just installed Ubuntu and LAMPP. I am very new to all of this so bear with me. I've installed LAMPP to /opt/lampp

My /opt/lampp/htdocs folder is where http://localhost points at. For the past hour, I wasn't able to write in that directory. I finally did sudo chown rondog /opt/lampp/htdocs and now I cant write. (rondog is me, the only actual "user" on the machine)

When I run one of my PHP scripts, I get a permission denied error when I attempt to call an fopen method. What do I need to do so I am able to write to this folder as well as PHP can execute commands such as fopen and fwrite? Thank you

share|improve this question

migrated from stackoverflow.com Sep 6 '11 at 22:37

This question came from our site for professional and enthusiast programmers.

    
What group this directory [have][1]? [1]: stackoverflow.com/questions/5771736/… –  Shara Sep 6 '11 at 20:12
add comment

3 Answers

up vote 2 down vote accepted

One possibility is setting the Apache user and group to rondog. This way, folders and files created can always be used by you and the server. It can be done as follows:

Edit (or create if it doesn't exist) /etc/apache2/httpd.conf and add the following lines:

User rondog
Group rondog

Save the file and restart the server:

$ sudo /etc/init.d/apache2 restart

Your newly added user should pop up whenever you use:

$ ps aux | grep apache 

One advice though: keep your localhost files in your home directory. If you ever want a clean update of a new Ubuntu version, it's much easier to switch if you keep personal documents in your home directory. Furthermore, in that case you don't have to use the sudo chown command every time you create a new folder.

share|improve this answer
    
ah this worked for me..I first went through the finder window to open it but I could only get it read only, so I went through terminal, used sudo nano /path, edited and saved, restarted and now it works! –  Ronnie Sep 7 '11 at 1:33
add comment

You have several options here. Either you do what Tim H suggests:

chmod -R 777

This will set read and write permissions for everyone.

But usually this is too broad. You can instead create a new group, place yourself and the web server user inside it and allow only you two to access and write the files:

$ sudo -i
# addgroup lamppusers
# adduser rondog lamppusers
# adduser www-data lamppusers # check, that www-data is the correct user
# chown -R :lamppusers /opt/lampp/htdocs
# chmod g+srwx /opt/lampp/htdocs

If you're not sure, if www-data is the right LAMPP user, issue

cat /etc/passwd

and look for a line, that might look like being the user used by LAMPP. Otherwise, if you had the chmod 777 in place before, look at PHP-generated files with ls -l to see whom they belong.

The g+srwx is another way to write 777 access rights, but additionally sets the sticky bit.

Finally, if you need more fine-grained access rights, google for File Access Control Lists (ACLs). They allow definitions of access rights on a per-user base.

share|improve this answer
    
ok so following what you laid out, I got to the www-data part and found that user using cat /etc/passwd. It points to /var/www which to me seems like it has no relation to the htdocs folder. I couldnt find any other user regarding lampp. Anyway, I followed this step by step and no luck, still getting a permission denied error. After all that, I stopped XAMP, logged out and back in, started it up and same error. I havent tried chmod -R 777, because I dont like the idea of compromising security –  Ronnie Sep 7 '11 at 1:23
add comment

Have you tried

chmod -R 0777 /opt/lampp/htdocs
share|improve this answer
    
bad advice from a security standpoint –  knittl Sep 6 '11 at 20:14
add comment

Your Answer

 
discard

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.