PHP - Run Php From Command Line Xampp For Linux
Hi guys,
I'm trying to run a php script from command line in linux. I installed xampp for linux a.k.a lampp so typing php /path/to/file.php Just brings up a message saying I need to install php. Whats the correct way to do this? Similar TutorialsHi, I am trying to use php to pass some commands to my linux box.From my webpage I am using the shell_exec function which is working OK but for some administrative tasks in linux I must have root access. As I am sending the commands from the webpage the apache user is used and so I am not allowed to do several tasks. I have also tried to use a bash script to pass the commands but with no result. Any ideas ? Hi everyone, i'm trying to get it so when i visit my webpage called start.php it executes the command (/bigbrotherbot start) in the terminal which then should start the process on my linux machine. I'm currently using this code Code: [Select] <?php shell_exec('sudo /bigbrotherbot start'); ?> This script doesn't appear to do anything though. I'm very new to php and would really appreciate the help. P.S the file bigbrotherbot is the bash script which works if i actually go to the terminal myself and type /bigbrotherbot start yet when i try to make the php do it it doesnt do anything. any ideas? This is probably an easy one, but I can't figure it out and it's pretty much not searchable. on a linux-machine i have installed filezilla the filezilla runs pretty well and all is ok. now i need to have the passwd that i have stored years ago. The passprhase is stored in a plain in a file called sitemanager.xmlfile I want to find that file and open it with a terminal command. find . -name *.sitemanagerwell i thought that this will return the file I'm looking for. Now how do I open it automatically, without typing the name? find . -name *sitemanager.xm | openThis doesn't work. It says it doesn't found the open command. question: why it does not work on opensuse? should i use any other command - eg the following: find . -name *xyz | xargs openor find . -name *sitemanager.xml | xargs openor find . -name *.xyz -exec open {} \;and find . -name *.xyz -exec open {} \; .any and all help will be greatly appreciate again: what is wanted and needet is to find out the passphrase in the filezilla-configuration My IDE (Nusphere's PhpED) runs on Windows but is configured so that both the web server as well as all project files are located on a development Linux server. Since the project files are located on the Linux server, the git repository is located there as well and not on my PC. Every now again, my IDE complains that content was externally modified and whether I wish to reload the file. Also, I was recently asked to set git's core.autocrlf to true on a project I was collaborating on which prevented me from adding any changes to git (git complained that LF will be replaced by CRLF). The IDE allows file encoding to be changed (system default, UTF-8, Windows-1252, or ISO-8859-01) as well as the default file format (Unix, Windows, Mac, or autodetect). Any recommendations on how best to configure git and these ide settings? Thanks I have 2 issues happening, first one I need to get resolved is, line 60 is giving me a 'Notice: Undefined variable: delete'. This codes had multi issues but was able to resolve all but this one and my table not filling in with the data from my database. If you need any other info please let me know, Again I am new at this.
<tr> <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete value="delete"></td> </tr> <?php // Check if delete button active, start this *line 60* -----> if ($delete){ for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql = "DELETE FROM $tbl_name WHERE id='$del_id'"; $result = mysqli_query($sql); } // if successful redirect to delete_multiple.php if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=delete_multiple.php\">"; } } mysqli_close($con); ?> Hi, I'm having a weird issue when I try to run PHP scripts from the command line on my server. I'm trying to just run a very simple script to test it out: #!/usr/bin/php-cgi -q echo "Hello terminal\n"; And I get the following error in the terminal.. Code: [Select] Error in argument 1, char 3: option not found Usage: php-cgi [-q] [-h] [-s] [-v] [-i] [-f <file>] php-cgi <file> [args...] When I try taking out the quiet (-q) parameter, I get the following error.. Code: [Select] -bash: ./socket_server.php: /usr/bin/php-cgi^M: bad interpreterNo such file or directory As you can see, in the second example, a rogue "^M" was appended to the end of the first line of my socket_server.php file. What does ^M correlate to? I realize it is a character code for something that can't be represented with an actual character, but I don't know what it is, and I'm not sure why it is being appended to the end of my first line. My assumption is that this is happening in the first example too, which is why I get the "error in argument 1" message, since undoubtedly -q^M is an invalid argument... Any help is greatly appreciated! nethnet Hi.. I have a php file where i have only one line which says header('Location: index.php'); How do i run this php file in the terminal on fedora 14? Thanks, Rohit I am trying to execute a command line tool, but am having a problem adding a variable to the line. Here is the code Code: [Select] $filename = "devices.txt"; $handle = fopen($filename, 'r'); while (!feof($handle)) { $devices = fgets($handle, 4096); $query = 'ipmitool -I lanplus -H 192.168.1.1 -U admin -P adminpass sdr list'; passthru($query); } flcose($handle); On this line I don't want to have the IP manually added like so. Code: [Select] $query = 'ipmitool -I lanplus -H 192.168.1.1 -U admin -P adminpass sdr list'; Instead I want to be able to insert the $devices variable which contains the values from the text file so it would look something like this: Code: [Select] $query = 'ipmitool -I lanplus -H $devices -U admin -P adminpass sdr list'; Problem is the command line tool does not run this way. How do I properly add the $devices variable so the command line tool ipmitool will run with its value? Thanks, hey guys m using STDIN as input stream in php command line my problem is that some time i get this error Warning: fgets(): supplied argument is not a valid stream resource in D:\myquery \test.php on line 16 $number=fgets(STDIN); anyone knows solution Hello everyone I have a question? I run a PHP script loads about 200 calls simultaneously on Linux environment, so my question is what is best way to run a command line As an example php-f example.php or make it through the apache example "curl http://localhost/example.php" Thank you woren can anyone help me with an overwhelming problem ? I want to use this command in the php curl code. curl -v --data "WSCommunityStringRW?2=1200ve50set&Submit=Submit" http://10.2.3.111/Forms/SnmpCommunityString -u "admin:a1s2d3" --anyauth This topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=350801.0 Hi, suppose I want to write a PHP script that checks whether a valid email address exists or not. There are a number of GUI-based tools to verify this, but is there any command line tool to do the same so that I can use PHP to capture the output? hello dear php-experts how to testrun a drive with command-line? note: i had several blank screens during the last week does this somewhat have to do with the hard-drive? which tests can be done? Hello all
I'm new to this forum. I've been struggling on this problem for a few days now.
I’m writing a script to automatically push code to a git server. exec(‘git config user.name "’ . $userName . ‘"’); exec(‘git config user.email "’ . $userEmail . ‘"’); exec('git checkout -b ’ . $branch); exec(‘git add --all’); exec(‘git commit -m "’ . $message . ‘"’); exec('git push origin ’ . $branch);
When running the last command, the script stops and asks for a user name, then a password. I tried other forums, searching the net. I'm frustrated...
Thanks in advance. So, I'm trying to read a file from a different filepath than the current working directory.
I have some simple PHP like this :
<?php $input_map = "readfile.php"; $map_contents = file_get_contents($input_map); echo $map_contents."<br />\n"; ?>And this'll work fine because it's in the same directory but if I try to set $input_map = "/home/...", the browser will return an empty string. This script will work from the command line though. So how do I get file_get_contents() to read from the server's file structure instead of just the working directory? Edit : For example, this will not work through the browser : <?php $input_map = "/home/..."; $map_contents = file_get_contents($input_map); echo $map_contents."<br />\n"; var_dump($map_contents); ?> Edited by MutantJohn, 21 January 2015 - 06:35 PM. I would like to update the DB when a service ends and thought about doing so in the destructor, but I did not make much progress. Then tried using pcntl_signal(), but also didn't get far. Is doing so possible? Thanks /usr/lib/systemd/system/test123.service [Unit] Description=bla After=syslog.target [Service] ExecStart=/usr/bin/php /var/www/testing/__destruct.php [Install] WantedBy=multi-user.target
/var/www/testing/__destruct.php <?php ini_set('display_errors', 1); pcntl_signal(SIGTERM, function() { syslog(LOG_INFO, 'Caught SIGTERM'); die; }); pcntl_signal(SIGHUP, function() { syslog(LOG_INFO, 'Caught SIGHUP'); die; }); pcntl_signal(SIGUSR1, function() { syslog(LOG_INFO, 'Caught SIGUSR1'); die; }); pcntl_signal(SIGINT, function() { syslog(LOG_INFO, 'Caught SIGINT'); die; }); pcntl_signal(SIGABRT , function() { syslog(LOG_INFO, 'Caught SIGABRT '); die; }); /* pcntl_signal(SIGSTOP , function() { syslog(LOG_INFO, 'Caught SIGSTOP '); die; }); */ /* pcntl_signal(SIGKILL , function() { syslog(LOG_INFO, 'Caught SIGKILL '); die; }); */ class Bla { private $bla; public function __construct($bla) { syslog(LOG_INFO, '__construct'); $this->bla = $bla; } public function __destruct() { syslog(LOG_INFO, '__destruct'); } public function start() { $counter=0; $counter2=0; while(true) { $counter++; if($counter>10000000) { $counter2++; $counter=0; syslog(LOG_INFO, '.'); } if($counter2>5) { die('all done!'); } } } } $bla = new Bla('hello'); $bla->start();
Hi Guys.
Doing an assignment for uni, and stuck on an error. Ill attach some files to show the problem and any help very much appreciated.
Error and the screen it comes on
Code
<?php $select = mysqli_query($con, "SELECT * FROM categories");
while ($row = mysqli_fetch_assoc($select)) { }
function dispsubcategories($parent_id) {
}
function getnumtopics($cat_id, $subcat_id) {
and the structure of the database
Edited March 28, 2020 by Ben555 I have a PHP file that is executed via batch file very frequently for live updating. This is a sort of "sync" file for reading/writing to a MySQL database. I am able to get it functioning absolutely fine when executed manually via a web browser (and my echo debug lines output the expected information), yet when I run the same PHP file via the command line, it seems to just not be capable of opening any file for reading, so the equivalent variables that are correct when executed on a web browser are blank when echoed through the command line. Is there a different way of handling reading of files when running a php script via the command line, or should it function exactly the same as when run via a browser? For instance: $k = "0"; $line = file("examplefile.log")[$k]; echo $line; Hi all, In the process of moving websites off an old win 2008 server and onto a new win 2016 server. I discovered that dns_get_record is failing on the new server. I made a simple test page: $dnsrecs = dns_get_record('google.com'); When i call this as a webpage, it comes back with dns query failed. It comes back instantly, so it's not like it's timing out. But, if i just call the webpage from the command line, it comes back with the dns record. Why would dns_get_record fail when used in a webpage, but work from the command line? I can make outside connections since I was able to send an email to an smtp server. I thought maybe this is a permission issue, but seems odd I'd be able to send an email using php but not do a dns query. Oh, and I have two versions of php installed on this server - 5.4.10 and 7.4.9. The old version is a direct copy from the 2008 server. 7.4.9 is a clean install. Both of them behave the same way. webpage fails, command line works. Also, nslookup works. I also tried switching to using google's name server, but it had no effect on anything. Anyone have any suggestions? |