Using Ubuntu 20.04.
I want to copy this file:
-rwxrwxrwx 1 www-data www-data 197801 Jan 15 17:33 /home/user/programming/masterFile
to:
drwxrwxrwx 2 www-data www-data 4096 Jan 14 12:27 html
The script is:
sudo -u user -p password cp /home/userprogramming/masterFile /var/www/html/masterFile
I have tried using exec(), system(), passthru() both putting the command in the function or calling the script with the command inside it.
I added this line to apache2.conf
<Directory /home/user/programming>
AllowOverride None
Require all granted
</Directory>
What am I missing?
Related
I am trying to self host a PHP script called sngine. (facebook clone)
When trying to install it I get an error:
config.php - Required includes folder to be writable for the installation
when I run ls -l I get this: drwxrwxrwx 5 mbeck mbeck 4096 Aug 25 23:00 includes
I don't know why it is saying that it's not writable.
The script is in var/www/{domain name}/
I am on Apache/2.4.41 (Ubuntu) and PHP version: 7.4.22
EDIT:
I found someone saying to run chown www-data:www-data <directory> So I did, and permissions now return drwxrwxrwx 5 www-data www-data 4096 Aug 25 23:00 includes and the error is still there.
Ok, I found it!
I had to run sudo chown -R www-data /var/www/example.com/mydomain/includes/
Now it works!
Running Ubuntu 18.04, Apache/2.4.29, PHP 7.2.10.
I am unable to read/write into my mounted drives from PHP.
this is my sample code:
<?php
ini_set('display_errors', '1');
error_reporting(E_ALL);
$folder = '/media/superuser/HDD4TB_CRYPT/nextcloud_data';
var_dump(ini_get('open_basedir'));
file_put_contents($folder.'/x.txt', "AA");
echo file_get_contents($folder."/x.txt");
phpinfo();
This is output:
string(0) ""
Warning:
file_put_contents(/media/superuser/HDD4TB_CRYPT/nextcloud_data/x.txt):
failed to open stream: Permission denied in
/var/www/html/nextcloud/x.php on line 9
Warning:
file_get_contents(/media/superuser/HDD4TB_CRYPT/nextcloud_data/x.txt):
failed to open stream: Permission denied in
/var/www/html/nextcloud/x.php on line 10
these are folder details:
superuser#SuperTower:/var/www/html/nextcloud$ ls -al /media/superuser/HDD4TB_CRYPT/
total 28
drwx------ 4 superuser superuser 4096 feb 3 20:55 .
drwxr-x---+ 4 root root 4096 feb 2 00:06 ..
drwx------ 2 root root 16384 feb 1 22:49 lost+found
drwxrwxrwx 2 www-data www-data 4096 feb 3 21:29 nextcloud_data
I tried editing open_basedir, but this did not help to solve any issues, so I just commented it out. Therefore open_basedir has no value in phpinfo(). Folder is chowned to www-data (this is apache user) and also chmoded to 777.
/media/superuser/ contains folders with mounted drives on my PC. superuser is my username in Ubuntu.
Thanks for any ideas!
P.S.
I have also tried adding a symlink to my folder:
superuser#SuperTower:/var/www/html/nextcloud$ ls -al data
lrwxrwxrwx 1 www-data www-data 45 feb 3 21:05 data -> /media/superuser/HDD4TB_CRYPT/nextcloud_data/
and using
$folder = '/var/www/html/nextcloud/data';
but the results are exactly the same.
I also tried adding
<Directory /var/www/html/nextcloud/data>
Options +FollowSymLinks
Allow from All
</Directory>
no change in the resulting behavior :/
For some reason no matter what ownership/permissions I set on folder, /media/superuser is never accessible by www-data.
I edited /etc/fstab to mount drive into /opt/ folder and I chowned it to www-data user and group.
Works like a charm now.
it is my first question here.
I get 403 - Forbidden for every php file. Tried with index.php and other names like test.php. Tried different subfolders and in /var/www/html directly.
Raspberry Pi 2 Model B Rev 1.1
Server version: Apache/2.4.10 (Raspbian)
Server built: Jul 18 2017 22:21:17
All updates installed. Have owncloud, pihole, mysql installed. It worked fine and after a restart it stopped working and more restarts don't fix it. Had to fix some network issues with 'no route to host' and a new external HDD.
I set permissions with
sudo find /var/www -type d -exec chmod 755 {} +
sudo find /var/www -type f -exec chmod 644 {} +
so folders are 755 and files are 644. Owner is also www-data:www-data everywhere in /var/www
so th structure to my index.php example would be
drwxr-xr-x 12 root root 4096 May 4 05:01 var
drwxr-xr-x 4 root root 4096 Jul 25 20:47 www
drwxr-xr-x 6 www-data www-data 4096 Jul 25 19:52 html
-rw-r--r-- 1 www-data www-data 29 Jul 24 20:08 index.php
also tried chmod 777 on index.php but still 403 error.
index.php:
<?php echo "hello world"; ?>
or
<?php phpinfo(); ?>
both don't work. No .htaccess files used.
part of apache2.conf:
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/html>
Order allow,deny
Allow from all
Require all granted
</Directory>
added the last Directory in an attempt to fix it.
So what is causing the error?
So I decided to purge everything and all configs plus folders. After reinstalling i realized it migth just be
drwxr-xr-x 4 root root 4096 Jul 25 20:47 www
needed also to be
drwxr-xr-x 4 www-data www-data 4096 Jul 25 20:47 www
owned by www-data www-data
Because now it is. But what i don't understand is how can index.html work in this folders and php does not.
I have a web app that will execute a perl script via PHP to allow users to clear out old logs. The same script is to be used by cron.
Currently I get a permissions error when this is run. www-data is executing the script.
If I chmod 777 the directories it works but don't want to do that.
Created a new group and added the directory owner and www-data to it. Chowned the directory for the owner and new group and ran chmod -R g+s. This still doesn't work.
Have found a few posts that said to do exactly what I did for the solution.
What am I missing here?
logs1 is directory containing files/directories to be cleared, logs1 itself will not be deleted.
Does not work:
drwxrwxr-x 9 foo foo 32768 Jun 9 2017 logs1
Works (don't want to do):
drwxrwxrwx 9 foo foo 32768 Jun 9 2017 logs1
Works (don't want to do):
drwxrwxr-x 9 www-data www-data 32768 Jun 9 2017 logs1
groupadd newgroup
usermod -a -G newgroup foo
usermod -a -G newgroup www-data
chown foo:newgroup logs1
chmod -R g+s logs1
Still doesn't work:
drwxrwxr-x 9 foo newgroup 32768 Jun 9 2017 logs1
Thanks
Ubuntu 14.04, Apache2, php 7, perl v5.18.2
Did you restart your webserver? Changes to secondary groups of a user do not affect running processes.
I can't run command line script from Exec
$exec = exec($command, $output, $return );
I have tried passthru,shell_exec,system but obviously this is not the problem.
sudo chown -R www-data:www-data /root/path/nonce.py
sudo chmo 775 /path/nonce.py
sudo chmo 777 /path/nonce.py
sudo chmo 755 /path/nonce.py
didn't helped
exec("python -V 2>&1");
works
But
/usr/bin/python /root/path/nonce.py
Array ( [0] => /usr/bin/python: can't open file '/root/path/nonce.py': [Errno 13] Permission denied )
dosent
running on nginx and php5-fpm
You need to consider the permissions for each directory on the path to the Python script. This means:
/root
/root/path
/root/path/nonce.py
The permissions for the root account are naturally restricted. If you look a root's home directory:
$ ls -ld /root
dr-xr-x---. 9 root root 4096 Aug 20 23:50 root
You will see that only the root user, and users within group root, can read or list the contents of /root.
It's a bad idea to place your script in root's home. There are more appropriate places such as /var/www/cgi-bin assuming that your script is a CGI script. On my system:
$ ls -ld /var/www
drwxr-xr-x. 4 root root 4096 Jul 17 17:22 /var/www
$ ls -ld /var/www/cgi-bin
drwxr-xr-x. 2 root root 4096 Jul 17 17:22 /var/www/cgi-bin/
which can be read and listed by any user. You should install the script in a directory appropriate for nginx.
one of the directories on the path probably lacks r permisison for the relevant user - most likely /root
can you move the python script to a dir that is world readable?