Trying to delete a file from Apache2 not in /var/www - apache

I am new to apache2 and am having permission issues with respect a functionality of my website.
I have django running apache2 and my django project has a DELETE functionality on the website, where the back-end deletes a folder from /Project/results . Following is my python function which works as expected when I just run it on the django web development server but throws error 'Exception: ', OSError(13, 'Permission denied') when I run it through apache2,
def delPrevGraph(request):
delId = request.GET["delId"]
try:
print("Path deleting: /Project/results/",delId)
shutil.rmtree("/Project/results/"+delId)
except Exception as e:
print("Exception: ",e)
args={}
return HttpResponse(json.dumps(args))
The permission and owner of the results directly is as follows,
drwxr-xr-x 52 www-data www-data 4096 May 19 06:41 results
But all the folders within results directory are owned by root. Just for checking I did try to chown and give permissions as below but showed no difference.
chown www-data:www-data deleteID
chmod 755 deleteID
Also I tried to adding the following in the default-ssl.conf file and tried restarting the apache2 and deleting from the website. Still no difference.
<Directory /Project/results/>
Require all granted
</Directory>
I cannot change the location of the this directory and place it in /var/www.
Is there a way to to get this done? I am stuck at this issue for a while now and would greatly appreciate some help.

I was reading the shutil documentation. And in the box of warning, they advice us to doesn't use copy functions on POSIX (linux) system. Maybe your problem is relation with a POSIX bug, try to use the basic I/O files functions.

Related

Drupal 8 File Upload error: Could not move uploaded File

I have created a new content type, and all of a sudden I can not upload any images to my site. It is a local server so disk space is not an issue.
The error is
The file could not be saved because the upload did not complete.
File upload error. Could not move uploaded file.
This value should not be null."
It is drupal 8.1.8
I have changed the temp directory to a place that www-data has full read and write permissions, as well as changing the files folder to 777, none of which seem to fix the issue.
There isn't even any apache errors that are being thrown, the only error is in drupal logs and on the page
error screen
on drupal root directory try
sudo chcon -R -t httpd_sys_rw_content_t sites/default/files
See the folder premissions here: https://drupal.stackexchange.com/questions/373/what-are-the-recommended-directory-permissions. This is a common folder permissions issue.
I fixed the problem on (Laragon, Drupal 9 & Windows 10) by changing the PHP from NTS to Thread Safe.

Vagrant for web server with shared folders: Apache breaks file permissions if it tries to stat a file before it exists

I'm not sure if this is an issue with vagrant, virtualbox or a configuration issue inside the box itsef, however:
Using the following setup: Apache is running in the guest with its server root set to /srv/http, this is a synched folder which points to ./public_html on the host.
While most of the time it works as expected, the following steps causes an issue
1) Navigate to a file that doesn't exist localhost:8080/test2.css -- shows a 404 error as expected but correctly connects to the guest which is serving the error
2) Create test2.css with some content and place it in public_html
3) Reload localhost:8080/test2.css -- Still shows a 404 error even though the file now exists
4) To debug, run vagrant ssh and then ls /srv/http. Which shows:
ls: cannot access test2.css: No such file or directory
So it's seeing the file, sort of but it shows without any permissions:
-????????? ? ? ? ? test2.css
-rw-rw-r-- 1 vagrant 7 Oct 23 11:13 test3.css
If I then re-save the file as test3.css, a file that hasn't yet been accessed it works perfectly. E.g. on the host, save the file I had open as test3.css and then navigate to it, it works as expected!
Any ideas? On why this might be?
In short: If apache has tried to read a file that doesn't exist, creating that file will then cause it to have invalid permissions. If apache has never tried to read the file before, it can be created and work as expected.
Thanks for any help, I'm really confused by this!
This turned out to be a kernel bug on the guest. Upgrading to 4.2.4 using the same Vagrant/Virtualbox/Guest Modules solved the issue.

Apache + WSGI to run Flask, get Python ImportError: "cannot import name ..." or "No module named ..."

Hello dear SO users and welcome to my first ever SO question,
I am currently looking to deploy a Flask application using Apache and mod_wsgi. Everything was coded with Python 3.4 so I had to follow several tutorials / questions to get mod_wsgi working with my version of Python (because apt-get install gets you the 3.4 version which is Python 2.7 compatible, you have to compile it after getting it with pip in a Python 3 virtualenv for it to be the 4.x version).
The Apache server error.log shows Apache/2.4.10 (Debian) mod_wsgi/4.4.13 Python/3.4.2 configured so this seems to be working fine.
My problem lies in the importation of the application in the .wsgi file. Tutorials such as this one usually do from FlaskApp import app as application considering their file tree, and this works as intended with a minimal application, I tried it without any problem.
My application is a little more complicated and uses a manage.py file to run on localhost, which may be part of the problem once trying to deploy on Apache.
From what I have found on countless SO Questions and other sites' questions, this most likely comes from:
A permission problem (if the user executing the current script doesn't have reading right on the script he's looking to import)
A sys.path problem (if the top-level folder is not in the sys.path, Python 3 cannot see it)
Mainly out of frustration, I ended up using chmod 744 LongAppName in /var/www/ resulting in drwxrwxr-x rights.
My file tree is the following:
drwxrwxr-x LongAppName
drwxr-xr-x LongAppName
drwxr--r-- ShorterAppName
-rw-r--r-- app.py
-rw-r--r-- commands.py
-rw-r--r-- __init__.py
drwxr--r-- static
drwxr--r-- templates
<irrelevant files>
-rw-r--r-- __init__.py
-rw-r--r-- manage.py
drwxr-xr-x venv
<more irrelevent files>
-rwxr-xr-x longappname.wsgi
So for the first possible fix, permissions seem fine to me. Regarding the second one, I'm printing sys.path in the .wsgi file and it outpouts ['/var/www/LongAppName', <among others>] which shows that the top-level folder is in the sys.path.
My longappname.wsgi is as follows:
#!/var/www/LongAppName/LongAppName/venv/bin/python3
import os, sys, logging
#Doing some prints to check if we're in the venv and such.
PROJECT_DIR = '/var/www/LongAppName/'
if PROJECT_DIR not in sys.path:
sys.path.insert(0, PROJECT_DIR)
def execfile(filename):
globals = dict( __file__ = filename )
exec( open(filename).read(), globals )
activate_this = os.path.join( PROJECT_DIR+'LongAppName/', 'venv/bin', 'activate_this.py' )
execfile( ativate_this )
#Printing sys.path and sys.executable here
logging.basicConfig(stream=sys.stderr)
from LongAppName.ShorterAppName.app import manager as application
#The previous line changed a lot, I tried importing app, changing the path but this one was the first one I wrote.
Python can't seem to find LongAppName.ShorterAppName.app and I don't know why.
From the number of attempts I have made to test different alternatives to the code I wrote in the first place, I'm starting to lose track of what was good and what might cause the problem so I require your help to figure this out.
Thanks in advance!
Some of your directory permissions are now suspect. You have:
drwxr--r-- ShorterAppName
Better to be using:
drwxr-xr-x ShorterAppName
Same for static and templates.
What we really need to see is the exact Python exception details with traceback from the Apache error logs.

nfsnobody User Privileges

I have setup an NFS file share between two CentOS 6, 64 machines. On the server the folder being shared was originally owned by the root user. On the client it turned up as being owned by nfsnobody. When I tried to write to the folder from the client I got a permissions error. So I changed the folder ownership on the server to nfsnobody and chmod'd it to 777. However, still no joy - I continue to get a permissions error. Clearly, there is more to this. I would be much obliged to any Linux gurus out there (I personally wouldn't merit being called anything more than a newbie) who might be able to help fix this issue.
Edit - I should have mentioned that trying to write to the shared folder from the client actually manages to create a file entry. However, the file size is 0 and the permissions error is reported.
The issue here is to do with the entry in /etc/exports. It should read
folder ip(rw,**all_squash**,sync,no_subtree_check)
I had missed the all_squash bit. That apart, make sure that the folder on the server is owned by nfsnobody. On my setup both my client and server nfsnobodies ended up with a user id if 65534. However, it is well worth checking this (/etc/groups) or else... .
Here are a couple of useful references
How to setup an NFS SErver
NFS on CentOS
For the benefit of anyone looking to setup an NFS server I give below what worked for me on my CentOS 6 64bit machines.
SERVER
yum install nfs-utils nfs-utils-lib - install NFS
rpm -q nfs-utils - check the install
/etc/init.d/rpcbind start
chkconfig --levels 235 nfs on
/etc/init.d/nfs start
chkconfig --level 35 rpcbind on
With this done you should create the folder you want to share
mkdir folder
chown 65534:65534 folder
chmod 755 folder
Now define the folder to be shared/exported. Use your favorite text editor (vi or whatever) to
open/create /etc/exports
folder clientIP (rw,all_squash,sync,no_subtree_check)
Client
Install, check, bind and start as above
mount -t nfs serverIP:folder clientFolderLocation
If all goes well you should now be able to write a little script on your client
<?php
$file = $_SERVER['DOCUMENT_ROOT']."/../nfsfolder/test.txt";
file_put_contents($file,'Hello world of NFS!');
?>
browse to it and find that test.txt now exists on the server with the content "Hello world of NFS". In the example I have placed my mounted drive one level before document_root.

reputation module installation in phpbb3

Hi i am trying to install phpbb-reputation system i followed the xml file for installation but while executing install_reputation.php i am getting this error ERROR: Could not open the file ./styles/afterburnerafterburner_config.html for reading.There are many errors in the same fashin. where i gues it is not going inside afterburner/template folder where .html file exists. where should i check this?
More error samples:
Refreshing the proFormell template
ERROR: Could not open the file ./styles/proFormellcaptcha_recaptcha.html for reading.
Sounds like it's a permissions issue; if hosting on a LAMP server, just run chmod 755 * -R in the website root directory. Alternatively you could also change file permissions using an FTP client