LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 07-04-2016, 03:10 AM   #1
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 922

Rep: Reputation: 61
Question Need help with permissions for a LAMP server


Hi LQ,

I'm trying to write my own mini-code editor using codeMirror.

I use PHP scripts called over Ajax to perform PHP functions such as rename(). This comes back with a permission error.

How can/should I setup the permissions to be able to do this? I don't really like the idea of setting everything in /var/www/html to 777 and I'm assuming there is another way? Something tells me it has to do with group wheel?

Your help, greatly appreciated as always.

<3
Wh33t
 
Old 07-04-2016, 03:16 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,309
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
Look in the http server's log files for the specific errors. They will tell you which directories need permissions changed. The default user for the web server in Xubuntu, if that's what you are using, is www-data, so you can set the user or group for the one or two directories you need.
 
Old 07-04-2016, 03:21 AM   #3
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 922

Original Poster
Rep: Reputation: 61
Quote:
Originally Posted by Turbocapitalist View Post
Look in the http server's log files for the specific errors. They will tell you which directories need permissions changed. The default user for the web server in Xubuntu, if that's what you are using, is www-data, so you can set the user or group for the one or two directories you need.
I want the entire web directory to be read/writable by PHP over the web. It's a code editor designed to be able to build webpages from the browser itself.

So would I try to add www-data to /var/www/html? Is that what PHP uses?

I tried this out: https://superuser.com/questions/1931...in-linux#19333

That seemed to solve the issue. Thanks for your help anyhow

Last edited by wh33t; 07-04-2016 at 04:12 AM.
 
Old 07-04-2016, 07:11 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,309
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
Quote:
Originally Posted by wh33t View Post
Taken as a whole, that link gives very bad advice. The whole DocumentRoot hierarchy should not ever be writable by the web server, but in particular no users should ever be in the web server's group either. In your case, the web server run as the user www-data by default. The purpose of the user www-data is to provide an unprivileged user for the web server. That would be so that the web server can read what it needs to but not be able to do anything else. The ideas behind that are those of privilege separation and least privilege. What the superuser.com post really meant to do was something like sharing write access for multiple users to a single directory. As seen in the blog post, that can be done without giving write access to the web server.

But what you are trying to do is different. The task you've described is that of needing write access for a single, specific user to various directories. Or it may be enough to just give write access to some specific files, depending on your situation. So if the directory is /var/www/html/target/ then you could "chgrp" that directory to www-data and the "chmod" to g+w to give the web server and, thus, PHP write access. If you can please avoid giving write access for the web server to any directories capable of running PHP scripts. The idea there is Write XOR eXecute, where a region should not be able to both write and execute. That prevents the situation where if someone gets in via your PHP scripts they won't be able to write their own scripts on your server.

Yes, it may seem close but the difference will save you a lot of trouble.
 
1 members found this post helpful.
Old 07-05-2016, 05:49 AM   #5
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 922

Original Poster
Rep: Reputation: 61
Quote:
Originally Posted by Turbocapitalist View Post
Taken as a whole, that link gives very bad advice. The whole DocumentRoot hierarchy should not ever be writable by the web server, but in particular no users should ever be in the web server's group either. In your case, the web server run as the user www-data by default. The purpose of the user www-data is to provide an unprivileged user for the web server. That would be so that the web server can read what it needs to but not be able to do anything else. The ideas behind that are those of privilege separation and least privilege. What the superuser.com post really meant to do was something like sharing write access for multiple users to a single directory. As seen in the blog post, that can be done without giving write access to the web server.

But what you are trying to do is different. The task you've described is that of needing write access for a single, specific user to various directories. Or it may be enough to just give write access to some specific files, depending on your situation. So if the directory is /var/www/html/target/ then you could "chgrp" that directory to www-data and the "chmod" to g+w to give the web server and, thus, PHP write access. If you can please avoid giving write access for the web server to any directories capable of running PHP scripts. The idea there is Write XOR eXecute, where a region should not be able to both write and execute. That prevents the situation where if someone gets in via your PHP scripts they won't be able to write their own scripts on your server.

Yes, it may seem close but the difference will save you a lot of trouble.
I can't quite make sense of what you are saying. I need to be able to read and write the entire web root (I'll be using HTTPS if that helps at all). Is there a way I can achieve that safely? If there isn't, perhaps I could make the scripts that run the code editor only work if the connection is coming from a specific IP address? I could ssh in and adjust a config file when my personal IP address changes...? I suck at security.
 
Old 07-05-2016, 06:15 AM   #6
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,309
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
Quote:
Originally Posted by wh33t View Post
I can't quite make sense of what you are saying. I need to be able to read and write the entire web root (I'll be using HTTPS if that helps at all). Is there a way I can achieve that safely? If there isn't, perhaps I could make the scripts that run the code editor only work if the connection is coming from a specific IP address? I could ssh in and adjust a config file when my personal IP address changes...? I suck at security.
There are two issues. One is the superuser.com sites inadvisable recommendation to add users to the group www-data. The other is allowing either the group or user www-data to write the document root. Both should be avoided, but since your current arrangement needs at least some write access the question becomes what is the minimum write access that will still get the job done. (Or, ideally, finding a different way.)

Can you put your AJAX scripts into directories that www-data does not have write access to, but still allow them to write to the other directories?

Or can you put your AJAX scripts into directories which are limited to access from your ip number? Which web server are you using, Apache2 or nginx?

What is important to avoid is an arrangement where, if someone gains illicit access to your script, where they could write their own PHP scripts and run them on your server.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Install LAMP Server (Apache, MySQL or MariaDB, PHP) On Ubuntu 13.10 Server LXer Syndicated Linux News 0 10-22-2013 03:50 AM
Centos LAMP Server with unidentified script causing server to port scan ZS- Linux - Security 48 01-30-2011 07:27 AM
Fixing permissions for lamp on Ubuntu server jagrave Linux - Newbie 1 12-13-2010 04:43 PM
LAMP questions: distros, install methods, permissions & user to run as whitestar73 Linux - Server 21 06-26-2010 07:04 AM
LAMP File and Directory permissions dashnaam Linux - Security 1 08-01-2005 11:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration