I am using fileZilla ftp server and trying to run my php scipt. Below code to call b.php is not working. I am new to filezilla so let me know if any configuration required to run this code. I am calling b.php from a.php and both of them are in same folder.
<?php
header("Location: b.php");
?>
It will not work like that. You can run PHP file via terminal:
$ php -f file.php
Or you can make it executable with $ chmod +x file.php, add #!/usr/bin/env php on top of file and, finally, you run like that:
$ ./file.php
Or just access it in browser if you have Web Server configured and running.
This code may help you...
Try to write like this
<?php
header('Location: b.php');
exit();
?>
Related
Anyone can assist me on how to execute my php files without preceding php front
Examples instead of typing 'php filename.php' in cli or cloud9
I want to execute them by just typing the file name
command: 'filename'
then the script runs
Well i was thinking of using the htaccess file but i'm not sure if that also works on vps or cli. I know of browser only
Edit your PHP script and add this as the new first line, by itself, before your opening <?php tag:
#!/path/to/php
(Replace that with your actual path.)
Alternatively, if you have the env command, you can use that to figure it out for you:
#!/usr/bin/env php
So your script looks like this:
#!/usr/bin/env php
<?php
echo "Hello, world!\n";
Then make the file exectuable:
chmod u+x filename
Now you can just "run" it directly in the shell:
% filename
Hello, world!
Note, you only want to do this if the script is CLI-only. If it's ever run via the web server, that first line will be output to the browser.
My goal is essentially to run executable(say .sh or .py) with with php code, where executable would potentially create some new files in the directory.
For example, an obvious first try (shell_exec):
<?php
$output = shell_exec('sh shell.sh');
echo $output;
?>
Where the shell file is:
#!/bin/bash
# My first script
whoami
mkdir "NewDir"
Does not fully work if executed by visiting a page. whoami command returns "daemon" (not my account name) and folder "NewDir" is not being created.
I think this is permissions problem, even though my htdocs folder has permissions 777. (What I am trying to do works on Windows).
I think if I could make this simple script create a directory then my original would be resolved.
Any suggestions?
Well actually this is quite simple. Get the .py or the .sh file and use:
<?php
Include_once 'filename';
?>
Thank you for your time
Try using the full path in your bash script
#!/bin/bash
# My first script
whoami
mkdir /tmp/testFolder
Make it executable and set permissions to Folder:
chmod +x bashscript.sh
chmod 777 /tmp/testFolder
Test to start it:
./bashscript
Then everything should woring
I am trying to run a bash script from an html file using php. I've read this question (how to run a .sh file from php?) and followed it exactly but cannot seem to get it to work.
I have two files in my downloads folder on my mac. These are the file names and their content:
hello.sh
echo hello world
test.html
<?php
echo shell_exec('sh /Users/fred/downloads/thing.sh');
?>
I ran this command in command line while in the downloads folder:
open test.html
This resulted in a blank page being opened in chrome while I was expecting to get a page with "hello word" in it.
Thanks for the help.
rewrite your bash file in nano as
#! /bin/bash
echo "hello world"
In the command line type "bash hello.sh" to execute, this will test if it is working or not.
test.html rewrite to test.php
php code only work with *.php extension.
rename 'test.html' to 'test.php'.
also check the file name here
echo shell_exec('sh /Users/fred/downloads/thing.sh');
i think this should be
echo shell_exec('sh /Users/fred/downloads/hello.sh');
If again you face the same issue then may be your apache server doesn't have permission to access 'hello.sh'.
I have a form in html page that has action to run php file. The php file has to run a bash function command which in turn runs a scrapy spider. Since I have the scrapy spider located outside var/www/, I have added a function in .bashrc to run the bash command ($ startscript) from anywhere. When I run it on the terminal from var/www folder or anywhere it works as expected but when I do it in php file it does not work. I am not sure if its because of php file permission, scrapy proprieties or something else.
Any suggestions?
.php file:
<?php
$output = shell_exec('startscript');
echo $output;
?>
.bashrc file:
function startscript
{
cd /home/pi/IndeedCoUkCrawl
./BotScrapy.sh
}
So what you can try:
put the absolute path of the startscript in shell_exec and see if it works.
try running with error_reporting(E_ALL) and see if this give any error/notice
check if your webserver has permissions to run the file. Try putting the file into the same group as the webserver runs in.
I need to execut a bash script which mainly contains a pg_dump and some log, clean,... stuff through a PHP file located in the /var/www/ folder
My server is a Debian Squeeze 6.0.6 with PHP5 and Apache2 recently installed.
My index.php folder contains the code below :
<?php
echo shell_exec('./backup_database');
?>
The script seems to work because I got the logs output in my browers but the pg_dump is not executed.
Obviously, if I run the script manually it works.
The script is located in the same folder as index.php and I used chmod 777 on those two files and on the parent directory.
P.S. I have poor knowledges in server configuration, try to be as specific as possible
Try
<?php
exec('./backup_database');
?>
But i think your backup_database Needs an .sh ending so it can be executed. Then it should look like this
<?php
exec('sh ./backup_database.sh');
?>
Or
<?php
exec('./backup_database.sh');
?>
i'm not quite shure which of the two Solutions might work for you