EDIT 01 UPDATE:
ERROR Showing UP Warning: mkdir(): Permission denied in
/var/www/html/projeto01/index.php on line 7 Sucess. Dir Created
EDIT 02
Change to FEDORA and is working.
Thank you guys
before submitting this topic I read and tried all the topics here. No success.
The environment is working great until here. Php 7.4, Apache, Mysql Workbench, Atom... i can code and select from database, everything was great.
The code is working with no error execpt it did not create the directory. :/
If i create the dir manually, return the message that it already exist.
After read a lot of topics and get help from facebook.
I did change on group polices. Not worked.
chmod on the folder, not worked.
On CENTOS the apache user is APACHE instead www:data
ls -l /var/www return:
drwxr-x---. 2 apache apache 6 Nov 16 13:19 cgi-bin
drwxrwxrwx. 3 apache apache 39 Mar 19 13:54 html
ls -l /var/www/html return:
-rw-r--r--. 1 root root 86 Mar 19 00:09 info.php
drwxrwxrwx. 2 apache apache 23 Mar 19 13:58 projeto01
ls -l /var/www/html/projeto1 return:
-rwxrwxrwx. 1 root root 148 Mar 19 15:14 index.php
Thanks for the help!
My code is:
> <?php
$name = "images";
if (!is_dir($name)) {
mkdir($name);
echo "Sucess. Dir Created.";
} else {
echo "Dir already exist. $name";
}
?>
I have a PHP script which accepts data from an incoming POST request, downloads the data to a file, and then runs a shell script. Only some parts of the shells script are executed --- don't know why. The request is
https://knode.work/processLatex.php
where the body is the JSON {data: SOURCE} and SOURCE is LaTeX source text. Here is the PHP script:
<?php
$post_data = $_POST['data'];
if (!empty($post_data)) {
$dir = '/var/www/html/files/';
$file = 'foo';
$filename = $dir.$file.'.tex';
$handle = fopen($filename, "w");
fwrite($handle, $post_data);
fclose($handle);
chdir($dir);
exec("sh texit.sh");
echo("Done!!");
}
?>
And here is the shell script:
/usr/bin/pdflatex foo.tex
/usr/bin/pdfatex foo.tex
rm yuuk.txt
rm *.out *.log *.aux
The /usr/bin/pdflatex lines are not executed, but the other lines are. What the heck? Are not all lines equal?
((Could there be a permissions problem?))
Below is a listing of the ./files directory. I created foo.pdf by running pdflatex foo.tex as root.
-rw-r--r-- 1 root root 207383 Aug 13 17:31 foo.pdf
-rw-r--r-- 1 www-data www-data 11372 Aug 13 18:35 foo.tex
-rw-r--r-- 1 root root 84 Aug 13 17:40 texit.sh
So perhaps the problem lies in the ownership of foo.tex versus that of pdflatex (re comment below) by RiggsFolly. Here is the dope on pdflatex:
lrwxrwxrwx 1 root root 6 Aug 21 2017 /usr/bin/pdflatex -> pdftex
Also, I set everything up as root, e.g.,
drwxr-xr-x 6 root root 4096 Aug 13 18:36 html
What should I do?
I want to run a PHP script from chromium-browser which will print a file. The file is located in /tmp folder on the Raspberry Pi. The file is copied from the server using SAMBA. The script has shell_exec command which attempts to do something with the file. The script works from the command line but not through the browser (chromium). I run the latest Stretch version of Raspbian.
I suspect it is something to do with permissions but I do not know where the problem is located. I have previous image Jessie with similar setup and functionality and it works. I compared all the permissions on both systems and they are exactly the same but I must be missing something.
Here is the PHP script:
<?php
header("Access-Control-Allow-Origin: *");
shell_exec("sudo lpr -P printerName /tmp/sample.pdf");
shell_exec("rm /tmp/sample.pdf");
?>
Here are related permissions:
drwxrwxrwt 15 root root 4096 Nov 23 16:17 tmp
drwxr-xr-x 12 root root 4096 Nov 3 13:58 var
-rwxrw-rw- 1 nobody nogroup 320855 Nov 23 15:31 sample.pdf
I'm building a blog and I need to store images on my server. The images are given with full URL and when I post the article it saves the image with the copy() method.
In local all works well, but on my server nothing changes. However allow_url_fopen is set to On in php.ini file.
The strange thing is that the server changes the name of the file expected to be saved on, but it doesn't store it. For example I want to save this picture : http://s.tfou.fr/mmdia/i/03/8/bob-l-eponge-10479038eajyx.png . I put this URL inside my form, I submit it and then the server is saving this path : content/images/563b62825ab53.png as expected... But the path returns a 404 and the image is nowhere.
Here is my php code (cover is the name of the field where I put the image URL) :
$extension = explode('.', $_POST['cover']);
$uniq = uniqid();
$path = 'content/images/'.$uniq.'.'.$extension[count($extension)-1];
copy($_POST['cover'], $path);
$cover = $path;
here is what I have on the server with existing images pulled from my repo (from my local where all is working well) :
total 1328
-rw-r--r-- 1 root www-data 105331 Nov 5 14:59 563b578484ea1.jpg
-rw-r--r-- 1 root www-data 311132 Nov 5 14:59 563b57cf1db89.png
-rw-r--r-- 1 root www-data 132129 Nov 5 14:59 563b5a33d6c3b.jpg
-rw-r--r-- 1 root www-data 180274 Nov 5 14:59 563b5bbfe649b.jpeg
-rw-r--r-- 1 root www-data 283665 Nov 5 14:59 563b5c068e0bf.jpg
-rw-r--r-- 1 root www-data 311132 Nov 5 14:57 563b5fb480e73.png
But if I delete all and I try to make the server copy its own pictures, nothing appears... And here are the rights of the folders that contain the pictures :
drwxr-sr-x 3 root www-data 4096 Nov 5 14:57 content
which contains :
drwxr-sr-x 2 root www-data 4096 Nov 5 14:59 images
which contains nothing...
I don't know if it's a server issue or a lack in my php.ini or something else.
you need to give write permission to the user/group that nginx is running under (it shouldn't be root). chmod g+w images should do what you want assuming nginx is running as group www-data on your system
Inside my automation.php controller, I have the following function:
public function deploy_test() {
echo json_encode(system("python --version"));
}
When the user wants to deploy a test, by clicking a test button in the webpage, he would be able to accomplish such a task.
However, when I click the test button, my output is:
""
Meanwhile, when I execute the same function with the command:
public function deploy_test() {
echo json_encode(system("ls -l"));
}
I'm getting:
total 32
drwxr-xr-x. 15 philippe philippe 4096 Mar 4 16:48 application
drwxrwxr-x. 2 philippe philippe 4096 Mar 4 17:28 css
-rw-r--r--. 1 philippe philippe 6357 Jan 30 11:53 index.php
drwxrwxr-x. 2 philippe philippe 4096 Feb 27 15:38 js
-rw-r--r--. 1 philippe philippe 2496 Jan 30 11:53 license.txt
drwxr-xr-x. 8 philippe philippe 4096 Jan 30 11:53 system
drwxr-xr-x. 12 philippe philippe 4096 Jan 30 11:53 user_guide
Could someone please help me to get that straighten out?
The problem is not with your code or PHP.
The problem is with your permissions.
php uses permissions which are set in the env-vars of apache.
Which is ideally set as :
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
under your apache2 / httpd conf file.
For example:
Try running:
<?= `whoami` ?>
via your shell and via your browser.
Your browser will probably say www-data and shell will say your username or if you are on AWS - default, you would get root
You do not have to use system() , use exec() instead.
We should be close as :
echo json_encode(exec("python --version"));
Performing operations will require you to have correct User and Groups set.
Look up for : In the shell, what does " 2>&1 " mean?
So your code should be :
echo json_encode(exec("python --version 2>&1"));
Hope it helps!
This works fine for my production server
public function deploy_test() {
echo json_encode(system("python --version 2>&1"));
}
with the output
Python 2.7.3
"Python 2.7.3"
Output of the unix command printed twice as system() itself outputs the result to browser. So exec() can be used in the place of system to avoid this.
public function deploy_test() {
echo json_encode(exec("python --version 2>&1"));
}
which outputs
"Python 2.7.3"
as expected.
I suspect it is not in the path. Try:
Type the full path to the python command (such as /usr/bin/python --version)
Find out with the command which, 'which python'
try executing your script from the command line, 'php script.php' => sometimes the web
server sets up things differently
make sure the error displaying is enabled with
ini_set('display_errors',1);
system returns only last line.
system
public function deploy_test() {
system("python --version", $out);
echo json_encode(implode($out));
}
It's a bit of hack, but you can find out the version number with 1 decimal even if you aren't allowed to execute python (which is the case with the 'user' CI).
//find python path
exec("which python", $path);
//show all subdirs in python
exec("ls -l ".$path[0]."*", $output);
$output = implode("\n", $output);
//preg match on version numbers
preg_match_all("#python(\d+(?:\.\d{1,2})?)#", $output , $matches);
$installed_versions = $matches[1];
//sort in reversing order
$versions_sorted_desc = array_reverse($installed_versions);
//latest version is element 0
$latest_version = $versions_sorted_desc[0];
echo $latest_version;