Folder permissions to Nodejs Express + Apache with Proxy - node.js

I have a Linux Ubuntu with Apache serving files (PHP app) from "public/" folder. Inside this folder (public/node/), I have a nodejs express running via Apache ProxyPass/ProxyReverse. Everything works. But when I try to upload a file with the nodejs application (a simple/small API) and save to "public/node/fileupload", I got an error:
code: "EACCES"
errno: -13
This directory (and all others inside public/) has 775 permissions, and the user that started the nodejs application (my own user, not root) is at the same group as Apache (www-data).
If I change the public/node/fileupload directory permission to 777, the upload works and the owner of file is the user that started the nodejs express (my own user, as said above). But, you know, set a directory as chmod 777 is not a good choice.
Do you know how can I avoid the use of chmod 777 on "public/node/fileupload" to allow file upload to a configuration like this?
Thank you in advance.

Related

apache2 on ubuntu webserver rejects permission to access any other file than the delivered index.html

I am trying to set up a webserver running on Ubuntu. I have installed Apache and changed the root directory to an other directory within /var/www/. When I copy the index.html provided by Apache to that directory, I can access that file via remote webbrowser. But if I want to use a different index.html file, even really basic ones, I get an error: "Forbidden You don't have permission to access this resource". I have also tried to download that html, alter just a few lines and put it back on to the server with the result that it also shows that error. If I rename the initially provided index.html to index2.html I can still access it. I do not understand how it is possible that only this exact file is working.
I have tried to grant more permissions with Directory and restarted Apache but it won't work. I am rather new to Linux and Apache, can only use the terminal on my webserver and I do not know what else to do. Please help.
Change the permissions on the file, too, not just the folder. Pretty sure this fix it.
For diagnostic correction, allow permission for all by typing:
sudo chmod -R 777 /path/to/index.html

Laravel 5.6 "failed to open stream: Permission denied in filesystem.php"

I upload my laravel 5.6 project on Linux Server but the website is not running in the browser and I am getting the given error. Please Help.
The framework is unable to create a cache of the views from the looks of the logs. You need to update the permissions on the storage folder.
If the storage folder is owned by a different user to your server software (i.e. user is not www-data), you need to set the permissions using:
chmod -R 777 storage
If the storage folder is owned by www-data (or the appropriate system user for your server software), you can use the less open:
chmod -R 755 storage
If you run into permission issues, you may need to prefix the above commands with sudo.

Apache: wrong owner and permission of uploaded file

I have a website running on apache server.
Yesterday, I logged in to my server and restarted passenger, apache server.
I restarted using command:
touch /tmp/restart.txt
After that, I noticed that the new uploaded files are changed ownership to paelz (my username) and permission to -rw-------. The files were uploaded by some other users using the website.
The older files has owner apache and permission: -rw-r--r--.
As a result, the website cannot load the new uploaded files. However, it can load the older ones.
If I run chmod 644 on the new uploaded files, the website can load the files normally. However, I want a permanent solution.
I want the new uploaded file owned by apache and has permission as the old ones.
My question is what caused this issue and how can I fix it.
Finally I found the answer.
It is not related to apache. It is related to passenger instead.
https://stackoverflow.com/a/4232091/1319283
By default, passenger will run your app as the user who owns the
config/environment.rb or config.ru file, see
The config/environment.rb is owned by my account so passenger will run the app as my account.

Yii web application ownership and permissions

I have a php application uploaded on my server. It is written in yii framework.
www-data is the owner and group of the project root folder.
permission is set currently to 775 recursively.
but app is not working. I get following error in the browser:
Not Found
The requested URL /task/site/login was not found on this server.
Any idea how can I correct the situation?

Error: ENOENT, no such file or directory './assets'

After setting up koa-static-folder, my image loads great when I test over localhost with http://localhost:3000/assets/myimage.jpg
But after deploying our node code to an Ubuntu server, we get:
Error: ENOENT, no such file or directory './assets'
What's Ubuntu's issue here? Not sure how to resolve this.
The code that is working locally is:
var koa = require('koa')(),
serve = require('koa-static-folder');
koa.use(serve('./assets'));
Sounds like a permission issue (but I could be wrong!) such that the user that node.js is running under does not have access rights to the assets folder. If this is the problem you have to change access permissions to the folder (see chmod) or run node.js as a user that has the access rights.
If the server isn't publicly accessible you could run the application as sudo to verify if it is a permissions problem or not. Note that using sudo is not a long term solution since it is highly irresponsible/unsecure to run the application as the root user.

Resources