Running windows 10, php 8.1.13, community mysql 8.0, localhost:8000 on mozilla firefox.
I'm new to web development, I'm trying to use mysql with php to maintain a user database for a website. I test my development on a php localhost run from the windows command prompt (php -S localhost:8000 -t ) and then enter localhost:8000 as the URL in firefox. I've gotten lots of generic php code to run fine on localhost in this manner.
After downloading mysql, I'm able to successfully use procedural mysqli database instructions through php on the windows php shell. Through the php shell, I've created a mysql database with php, added simple entries with php, and then later retrieved them, so php is playing nicely with mysql.
Php is playing nicely with mozilla/localhost, and php shell is playing nicely with mysql, but when I try to combine the two processes (manipulate mysql database through a php server run as localhost) I just get a blank, white screen on firefox with no errors in the console or the terminal window.
The problem seems to happen almost immediately (this exact code executes fine (returns "success!") from the php shell window):
echo "test1";
$conn = mysqli_connect("localhost", $username, $password);
echo "test2";
if ($conn)
{
echo "success!";
}
mysqli_close($conn);
echo "test3";
conn appears to be declared OK. If I comment out the if statement then both test1, test2, and test3 echoes are visible, and I can close $conn. It's only when I actually try to DO anything with the connection (even this if statement) that the white screen appears.
Advice? Do I need to initialize the mysql server or something when run in this manner? Thanks!
I was expecting at minimum a relevant error message. The individual components work (A talks to B, B talks to C, so I expected A -> B -> C no problem.
Related
I have a Windows Server 2016 VPS with Plesk and PHP 7.1x.
I am trying to execute a simple AutoHotKey script from PHP using the following command:
<?php shell_exec('start /B "C:\Program Files\AutoHotkey\AutoHotkey.exe" C:\inetpub\vhosts\mydomain.com\App_Data\myahkscript.ahk'); ?>
This is the only line on the page. I have tried different ahk scripts, the current one simply creates a MsgBox.
When I execute my php page, on VPS Task Manager I see three processes created with the expected USR: cmd.exe, conhost.exe and php-cgi.exe. However, my PHP page just sits waiting on the server and nothing actually happens on the server.
I have also tried the same line except replacing shell_exec with exec. This seems to make no difference. I have tried without start /b with both commands. In that case the PHP page completes but no new processes are started.
I cannot find any errors in any logs: Mod_Security, Plesk Firewall, IIS.
Any ideas?
EDIT:
I tried my command from the VPS command prompt and immediately slapped in the face with the obvious issue of the space in 'Program Files'. I quoted the string as shown above and the command works. This eliminated the hang when running from PHP. However, the command still does nothing when executed from the web page.
EDIT:
Based on suggestions from the referenced post 'debugging exec()':
var_dump: string(0)""
$output: Array()
$return_val: 1
One point was that I would probably not be able to invoke GUI applications. That puts a damper on the idea.
I've been working on a webinterface for a game server deployment system. The game in question requires the user to enter their authentification key to allow the server to run in their name.
I can get the server to start using the exec() function however I need to be able to read the console output and allow the user to send things to the console via a php form.
I've tried looking around, google searches etc. If anyone could give me a hand with this I'd be very grateful.
The webserver is running XAMPP on Windows Server 2008 with up to date PHP etc.
Thanks in advanced.
From my understanding, you need shell_exec() function:
Return Values
The output from the executed command or NULL if an error occurred or
the command produces no output.
Example usage:
<?php
$output = shell_exec('ls -lart');
echo "<pre>$output</pre>";
?>
I have a Python (2.7) script that connect to a remote device through SSH and configure it.
This script works fine when I run it.
I have a PHP page that execute other Python scripts and they are also working fine.
The problem: the SSH script doesn't work when I'm running it from the PHP page.
(there is no problem with the PHP page nor the Python script)
To be more specific, the script (when executed by PHP) is running until it gets to the first SSH related code (import paramiko).
How can it be, and is there anything I can do to make it work?
Thanks!
(OS: windows XP. Server:Wamp (Apachi http server)
for example, consider this simple code:
fp=open("file.txt","w")
fp.write("text")
import paramiko
fp.write("another text")
fp.close()
if executed by me, everything works fine. If by the PHP page- only the code until "import paramiko" is executed.
or:
fp=open("file.txt","w")
fp.close()
import paramiko
fp2=open("file2.txt","w")
fp2.close()
Executed by me- both files created. by php- only the first.
Moreover: I tried using Try & Catch but nothing comes up. No exception is thrown.
My guess is that paramiko is not in your PYTHONPATH environmental variable for the Apache user.
When Apache fires up PHP, it is calling PHP as the whatever the "Apache" user happens to be (in Linux normally apache (or httpd) user in group www-data). Sometimes this user will have different environment variables set than the ones that users normally have. While this generally doesn't matter, sometimes it will cause bizarre interactions (and I can see it happening with Pip).
I would add a try... except around paramiko:
try:
import paramiko
except Exception as e:
# log your exception here.
pass # I put this here so the example can compile.
#rest of the script
That should let you know whether or not it is installed (and I suspect it isn't).
I'm making a Minecraft control panel, but are sort of confused on how to send a command to each screen. I understand how to execute a command to a screen, but I don't understand to read the output.
Ex. I have screen A and screen B. I want to execute something in screen A, and get the output, and then exit the screen.
Here's an easier solution:
Use Websend bukkit plugin (Download&info) in both servers. PHP can simply execute commands and receive outputs when plugin is installed and php classes setted up, also this can be more complex than bash screen, and much easier to setup and use.
Here's an example use of this:
<?php
include_once 'Websend.php';
//Replace with bukkit server IP. To use a different port, change the constructor to new Websend(ip, port)
$ws = new Websend($ServerIP, $ServerPort);
//Replace with password specified in Websend config file
$ws->connect("password");
$ws->doCommandAsConsole("give ".$PlayerName." 64 1");
$ws->disconnect();
?>
In this example the script item to a variable-definied player.
You can execute a custom variable command with replacing $ws->doCommandAsConsole("give ".$PlayerName." 64 1");' to$ws->doCommandAsConsole("$_REQUEST['customCMD']"); where customCMD is a field in a GET or POST form.`
Don't actually need a plugin, but keep in mind using shell_exec could open a massive world of pain for you when it comes to security.
However, I was having a similar issue with implementing a control panel in drupal, I managed to run commands to a screen using the following code.
shell_exec("screen -S ScreenName -X stuff \"echo hello world\"'\n'");
You're welcome.
I have been trying unsuccessfully so far to write a php script that will run when a page is opened and that will launch metasploit!
I ve tried shell_exec and exec and all the other alternatives but although I can get it to do simple things (i.e. ls, cds etc) if I try msfconsole it doesnt do anything!
I have also tried a different script that launches firefox and again nothing happens!
Now i know that php runs on the server and I m not expecting to see a console or firefox opening in the clients machine! Instead in order to check if it works I am trying to echo out the output of the shell_exec!But anyway since im hosting the files on my machine (i.e. this is the server and a VM is the client) if it could actually launch firefox i should be able to see the app opening here in the same way as by just doing this from the command line!
What am I missing?
Is there any other way to do this?(i.e. Launch metasploit everytime a user opens up my page)
NOTE: I've tried specifying the full path for msfconsole but that didnt work either!
Heres what I have so far:
$output = shell_exec('/opt/local/libexec/metasploit3/msfconsole;show');
echo "<pre>$output</pre>";
The ";show" bit was used in order to actually make it run something and print some stuff but didnt make any difference!
When you run a gui application from the command prompt in a X window system, it will use the default display. When you run it using php which is embedded in apache webserver, the program may not know where to display the gui application.
there are 2 things to make this work.
The program that executes the gui application must have permission to use display
you need to tell the program which display to use.
I used the following in my php script
<?php
$cmd = `export DISPLAY=:0; gedit`;
shell_exec($cmd);
?>
and ran the script from terminal using php -f test.php
I got the gedit up and running.
You can test the same with the script in apache too.
Please add apache user with privileges to access display server
update: I just added the following in /etc/apache2/apache2.conf (I am using ubuntu)
User poomalai
Group poomalai
and restarted the web server
sudo service apache2 restart
now I accessed localhost/test.php
and Presto!! I got the gedit :)
Hope this helps