1

I want to exec php file test1.php in file test.php. My problem is when I manualy run script test.php in terminal on the server(php /home/users/xh/*****/WWW/BP/test.php) it will do the job and exec the test1.php. But when I open test.php in the browser, it will not exec the test1.php. I added the +x permissions to the folder and to the .php files but it do not work anyway- ls -ld : drwxr-xr-x,ls -l: -rwxr-xr-x (on both test1 and test)

Here is test.php:

<?php
echo "including test1\n";
exec('php -f /home/users/xh/*****/WWW/BP/test1.php');
echo "end";

test1.php:

<?php

$db = mysql_connect('localhost:/var/run/mysql/mysql.sock', '*******', '*******');
if (!$db) die('cannot connect'.mysql_error());
if (!mysql_select_db('******', $db)) die('db not available '.mysql_error());

$var=mysql_set_charset("UTF8", $db);

if (!($result =   mysql_query("INSERT INTO table VALUES ('abcdefg','100','20','3','3')", $db))) {
    echo "insert not successful";
}
else
    echo "insert successful";

EDIT: when in run script test1.php by shell_exec() it whill show this warning:

Warning: shell_exec() [function.shell-exec]: Cannot execute using backquotes in Safe Mode
nocturne
  • 627
  • 3
  • 12
  • 39
  • 1
    Apache may not have the correct permissions to execute the file. Try outputting the result of exec into a log file – Ryan Burke Feb 27 '17 at 09:51
  • output:array(0) { } return code:127 – nocturne Feb 27 '17 at 09:54
  • I added +x permissions, but it not helped,on the directory and on the .php files – nocturne Feb 27 '17 at 10:02
  • Eddited the post, seems like Safe mode preventing from exec. I have read that safe mode has been removed from php 5.6, but this is exactly version I am using. Is it possible that when I run script by `php test1.php` it will run another version of php? – nocturne Feb 27 '17 at 10:32

0 Answers0