Linux Hosting files outside the htdocs directory - linux

I followed this instructions to be able to host files outside of the htdocs directory, but I alwyas get 'Access Forbidden' (https://gyazo.com/af49cb00720fa4bd80e969320bd51042).
The file those permissions: $ ls -l ~/Documents/code/xampp/
total 4
-rw-r--r-- 1 julian users 3337 Apr 10 2017 test.php
How do i fix this issue ?

Aache is not able to execute the php file, because apache don't have permission to execute the test.php file.
Try giving permission to the file.
sudo chmod +x test.php
Any user can execute the file.So change the file group to www-data and give executable permission.
sudo chown root:www-data test.php
sudo chmod 775 test.php

Related

Git add permission denied ubuntu

My application is hosted on ubuntu in public_html folder. When I run the command git add . it gives me the error:
warning: could not open directory 'public_html/': Permission denied
Entire code is in public_html folder
How can I solve it?
You should make sure so that your user has access or is the owner of the folder and it content. You can check the current owner and permissions by running:
ls -l public_html
Here I list all non-hidden files in a test folder:
who:test who$ ls -l
total 0
-rwxrwxrwx 1 root admin 0 Oct 3 18:04 test1
-rwxrwxrwx 1 root admin 0 Oct 3 18:04 test2
The output shows that both files are owned by the root user and belongs to a group named admin. The first column also shows the access permission, which in this case is set to read and write access to everyone.
If you would like to change the owner you can do:
sudo chown -R <user>:<group> public_html
The above will set the owner of the folder and all its content to the specified user and group; you might need sudo privileges to do this.
There is possible to only change the owner or group with the same command:
sudo chown -R <user> public_html
sudo chown -R :<group> public_html
To change the permission you would use:
sudo chmod -R <mode> public_html
Where mode is the permission, for instance 0777 for full read and write access to everyone. You can also use letters instead of an octal number when setting permissions, for instance:
sudo chmod -R a+rwx public_html
gives the same result as the first chmod command.
References
The chown command: https://ss64.com/bash/chown.html
The chmod command: https://ss64.com/bash/chmod.html

Chmod for application via script

Im creating a script file and I want to add the permission via chmod -R 777 myApp/*
I add to the script the following line
cd /home/abc/aa_tmp chmod -R 777 myApp/*
which doesnt work , when I try to update/edit file I got permission denied, any idea what I miss here?
you can use this;
#!/bin/bash
chmod -R 777 /home/abc/aa_tmp/myApp/*
if the user has enough privileges above script works. But if permissions is as below, throw permission denied
user#host:/tmp/$ ls -arlt
..
d--------- 2 user user 4096 Aug 25 16:38 myApp
..
Either you are not root, or the user does not own myApp.
and you don't need the *, since it goes recursively.
#su
#chmod -R 777 myApp/

chmod: changing permissions of ‘my_script.sh’: Operation not permitted

when I'm trying to make shell script that error is shown ,what i must do ??
[rehamadel#localhost bin]$ sudo vi my_script.sh
[sudo] password for rehamadel:
[rehamadel#localhost bin]$ ls -l my_script.sh
-rw-r--r--. 1 root root 52 Jul 30 19:25 my_script.sh
[rehamadel#localhost bin]$ chmod u+x my_script.sh
chmod: changing permissions of ‘my_script.sh’: Operation not permitted
Resolving the operation not permitted error:
sudo chmod u+x my_script.sh
You created the file via:
sudo vi my_script.sh
# editing
This means, the owner and group of the file is root. You are not allowed to change files of it by default. You need to change permission (chmod does it) or change the owner:
sudo chown you:yourgroup my_script.sh
This should do it. Save the trouble, without creating the file via sudo.
You've created file my_script.sh with the root user as the owner (because you used sudo), which is why you're not permitted to change the permissions as yourself.
Thus, use sudo chmod u+x my_script.sh, but note that that will make the file only executable for the root user.
To make the file executable by everyone, use sudo chmod a+x my_script.sh.
I faced this error because I uploaded the files via winscp and was trying to change permission on Linux window.
I was able to change permissions via winscp.

Though user HDFS is owner of a Dir, I'm unable to view all the directories

As HDFS user (owner of a Dir), I'm unable to view all the directories
Here is a command sample:
[ec2-user#ip-172-31-33-161 ~]$ ls -ltr
drwxrwxrwx 2 hdfs hadoop 4096 Oct 7 22:39 cards2
[ec2-user#ip-172-31-33-161 ~]$ sudo su - hdfs
[hdfs#ip-172-31-33-161 ec2-user]$ ls -ltr
ls: cannot open directory .: Permission denied
The command
sudo su - hduser
will take change the user, and take you to the home folder of hduser.
The command
sudo su hduser
can be used to remain in the current working directory even after the user is switched.
Login to ec2 machine as you previously logged in with ec2-user, change the permissions of /home/ec2-user , atleast give read permissions to other users.
chmod 777 /home/ec2-user
It is not the issue with the folder you are trying to access from the HDFS user.
ls -ltr will read the current working directory and will list the files in it.
you switched the user and you are accessing the ec2-user directory (The directory path is same as we required).
After changing the permissions, you are able to see the sub folders in ec2-user aswell.
I hope it will work for you. Please let me know for additional help.

htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable and that '/files/domain.com/public_html/images/' is executable

Today i migrated my images from one server to another and faced a strange permission issue
[Mon Mar 25 08:42:23.676315 2013] [core:crit] [pid 15182] (13)Permission denied: [client 24.14.2.22:48113] AH00529: /files/domain.com/public_html/images/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable and that '/files/domain.com/public_html/images/' is executable, referer: http://domain.com.com/file.php
what i've tried:
chmod -R 777 root_dir
restorecon -r
disable selinux
Chown -R root:root root_dir
Today I faced this problem. I transferred public_html from the old drive to new one and chown like this:
chown -R owner:owner public_html
This is correct for sub directories and files inside public_html, but the user of public_html must be nobody so apache can check it's content, so this solved my problem:
chown owner:nobody public_html
Note: owner is the user (for example web1)
I had the same problem. For me, it's a problem of SeLinux (CentOS 7).
It works for me:
$ setsebool -P httpd_enable_homedirs true
$ chcon -R -t httpd_sys_content_t /var/www/html/
Note that you should change the above /var/www/html/ to an appropriate directory.
I was using Plesk onyx and I got the same error message, I just changed the folder permission to 775 and it worked for me.
Other way is
sudo setenforce 0
Disable SELinux
I hope this works for you
TL;DR:
sudo chmod a+rx /var{,/services{,/web{,/web-folder}}};
find /var/services/web/web-folder -type d -exec sudo chmod a+rx {} +;
You need to make certain that the directory, and all of its parent directories, are readable and executable (executability is required to open a directory) by the web server. You can do this by making the web server user the owner and making the user perms (EG: chown apache <dir>; chmod u+rx <dir>;), or by a making the group be the web server group a group which includes the web server user and setting the group perms to (EG: chgrp apache <dir>; chmod g+rx <dir>;), or by setting the world perms to (EG: chmod o+rx <dir>;).
open your httpd.conf file and change Deny from all to Allow from all on the .htaccess file
The following lines prevent .htaccess and .htpasswd files from being
viewed by Web clients.
<FileMatch "^\.ht">
Order allow,dey
Allow from all
</FileMatch>
this solved my problem
When I checked httpd/user-error_log, it gave
[Fri Jan 09 18:58:08 2015] [crit] [client 192.168.1.xxx] (13)Permission
denied: /var/services/web/web-folder/.htaccess pcfg_openfile: unable to check
htaccess file, ensure it is readable
chmod 755 is not fixing the problem. Below command is what works for me. I use http since it is the apache user and group used in Synology DSM 5.1-5021
cd /var/services/web
chown http:http web-folder
apache httpd.conf # /etc/httpd/conf/httpd.conf
more details about the new change
Apache / Webserver limitations in 5.0

Resources