How to get around root restriction for development files?

Problems with the Linux version of XAMPP, questions, comments, and anything related.

How to get around root restriction for development files?

Postby bennypr0fane » 28. August 2020 20:59

Using Xampp in Linux, we have the problem that the webroot /opt/lampp/htdocs is in root space - hence we need root privileges to edit files under the webroot, which we want to do all the time when developing.
I've come across some ways one would deal with this, but 1) some are bad practice for security reasons 2) some don't always work on any system.
I find it odd that the correct way to deal with this isn't outlined in the most basic documentation, everybody has this problem, right?

What's best practice for solving this problem?

Ways I have found inlcude:
A) Modyfing permissions of /opt/lampp/htdocs in some way so that the regular Linux user can edit them with, using chmod, chown.
What's the safest way to do this? If not leading to security issues, I suspect owning htdocs to regular user has lead to other issues with mySQL server for me.
B) development files are in some folder in user space. Symlink this folder into a subdirectory of htdocs with ln -s ~/devfiles /opt/lampp/htdocs/subfolder
That sometimes gives 403 error, but I've been able to fix that on one of my systems by setting User to ben in /opt/lampp/etc/httpd.conf, while this fix didn't work for me on another machine - both running Manjaro Linux.
C) Configure an alias in Apache, as described here:
https://wiki.archlinux.org/index.php/XAMPP#Hosting_files_outside_the_htdocs_directory
Hosting files outside the htdocs directory:
The document root (web root) directory is located at /opt/lampp/htdocs/. All files placed in this directory will be processed by the web server.
To host other files on your system with XAMPP, you can configure an alias with apache
Xampp version 7.3.11-0 from Arch Linux user repositories
bennypr0fane
 
Posts: 7
Joined: 28. September 2014 17:38
Location: Austria
Operating System: Ubuntu 14.04

Re: How to get around root restriction for development files

Postby Nobbie » 28. August 2020 21:52

What's best practice for solving this problem?


There is no "best practice". Everything depends on your environment. You have to decide, who and why may have access to which files and folders and who not. For example, I am working on my PC alone, there is no need for any protection. This is not a Xampp issue, you have to define your team member or whatever and you have to decide, who may access what. That is your best practice. Nobody else can answer to your question than yourself.
Nobbie
 
Posts: 13176
Joined: 09. March 2008 13:04

Re: How to get around root restriction for development files

Postby bennypr0fane » 28. August 2020 23:11

Nobbie wrote:For example, I am working on my PC alone, there is no need for any protection.

Me too. So what you do is just give all the permissions to your user?
Xampp version 7.3.11-0 from Arch Linux user repositories
bennypr0fane
 
Posts: 7
Joined: 28. September 2014 17:38
Location: Austria
Operating System: Ubuntu 14.04

Re: How to get around root restriction for development files

Postby inf3rno » 17. February 2024 12:29

bennypr0fane wrote:Using Xampp in Linux, we have the problem that the webroot /opt/lampp/htdocs is in root space - hence we need root privileges to edit files under the webroot, which we want to do all the time when developing.
I've come across some ways one would deal with this, but 1) some are bad practice for security reasons 2) some don't always work on any system.
I find it odd that the correct way to deal with this isn't outlined in the most basic documentation, everybody has this problem, right?

What's best practice for solving this problem?

Ways I have found inlcude:
A) Modyfing permissions of /opt/lampp/htdocs in some way so that the regular Linux user can edit them with, using chmod, chown.
What's the safest way to do this? If not leading to security issues, I suspect owning htdocs to regular user has lead to other issues with mySQL server for me.
B) development files are in some folder in user space. Symlink this folder into a subdirectory of htdocs with ln -s ~/devfiles /opt/lampp/htdocs/subfolder
That sometimes gives 403 error, but I've been able to fix that on one of my systems by setting User to ben in /opt/lampp/etc/httpd.conf, while this fix didn't work for me on another machine - both running Manjaro Linux.
C) Configure an alias in Apache, as described here:
https://wiki.archlinux.org/index.php/XAMPP#Hosting_files_outside_the_htdocs_directory
Hosting files outside the htdocs directory:
The document root (web root) directory is located at /opt/lampp/htdocs/. All files placed in this directory will be processed by the web server.
To host other files on your system with XAMPP, you can configure an alias with apache


Same problem here, never found a working solution. Currently on Manjaro either I edit my files with my IDE and PHP cannot write them or PHP can write them, but I cannot edit, because it needs root permissions. I feel this a pretty bad user experience compared to Windows. The documentations I read were useless and I wasn't able to solve it with chmod either. I was able to do the upper with chown and changing the Apache user. I have no idea why there isn't a decent solution for this very common problem. As if developers would not exist...
inf3rno
 
Posts: 2
Joined: 17. February 2024 12:22
XAMPP version: 8.0.30
Operating System: Manjaro

Re: How to get around root restriction for development files

Postby Nobbie » 17. February 2024 13:24

inf3rno wrote:As if developers would not exist...


Usually developers know their Operating System and of course Linux is not Windows. You have to know the rights management of Linux file systems, but i dont think that this a too sophisticated task. There are so many options to solve the rights problems, it all depends on what you want to do. You wont find an "easier" environment if you use Manjaros Apache etc. from the repository instead of using Xampp. It is at it is. Its not Windows. And Apache, MySQL etc. MUST be run with root permissions.

Instead of changing permissions in /opt/lampp etc., you also might to use Apaches mod_userdir, which gives you the opportunity of putting your HTML files and PHP Scripts in your Home folder (i.e. in public_html), where you can access all files freely. See https://httpd.apache.org/docs/2.4/mod/mod_userdir.html
Nobbie
 
Posts: 13176
Joined: 09. March 2008 13:04

Re: How to get around root restriction for development files

Postby inf3rno » 17. February 2024 22:19

I run Apache with my user and I chowned the document roots on my other SSD, which solved the upper problem. It is working for me.
inf3rno
 
Posts: 2
Joined: 17. February 2024 12:22
XAMPP version: 8.0.30
Operating System: Manjaro

Re: How to get around root restriction for development files

Postby Nobbie » 17. February 2024 22:21

inf3rno wrote:I run Apache with my user and I chowned the document roots on my other SSD, which solved the upper problem. It is working for me.


Yes, of course. As i said, there are plenty of options. But you need to know about the rights management of Linux. That is NOT a problem of Apache or Xampp.
Nobbie
 
Posts: 13176
Joined: 09. March 2008 13:04


Return to XAMPP for Linux

Who is online

Users browsing this forum: No registered users and 58 guests