I am in the process of setting up a website for users to sign up for accounts to access applications on a server running Windows Server 2019 with IIS, MySQL, PHP, and FastCGI.
The website works fine, the applications work fine, but it becomes rather tedious to have to login via RDP to restart an application if it hangs up, needs a manual update, etc. I have tried searching via google, and came up empty on this, but is there a way via php, jquery/AJAX, etc., to click a button on my website's admin panel to send a command to Windows to shutdown and/or restart an application?
Example:
Let's say I have my website located at C:/webroot/htdocs/" and an application at "C:/servers/server1/server.exe
I want to send a command from the website to close any active windows for server.exe (the console window(s)) if I hit "Stop Server" on the webpage. If I hit "Start Server" it will send a command to launch the server.exe program. Finally, if I hit "Restart Server" it will perform the stop action, followed by the start action in a single click.
Is this possible without needing to purchase any type of third-party application?
I know there are cron jobs, but I am not sure exactly how to utilize them, especially in this type of scenario.
Related
I'm new to web development. I'm trying to execute a shell script using PHP's shell_exec(). Inside the script, I'm trying to invoke a GUI application(Qt). When I executed the PHP script from a terminal the application started as expected. But when I opened it from browser an empty blank page appeared.
I'm using Ubuntu with apache2 server running as service. When I searched in google, the similar problem is solved in the Windows environment by allowing apache service to interact with the desktop.
PHP Script:
<?php
$log = shell_exec('sh testcmd.sh');
?>
testcmd.sh:
./Program1
Any help provided will be highly appreciated.
It is somewhat unclear what you're asking.
If you wish that browsing to a certain web site will run a PHP script that will open a GUI app for the client to interact with, the answer is "you can't". The reason is that the way the setup works is that the server and the client run on different machines, and your PHP runs on the server machine. As such, the client never gets to see the running program.
The above is true also for Windows. The answer you quote in your question does not apply to a server running on a different machine than the client.
If, for whatever reason, you want something that works only when the server and client run on the same machine (or there is someone watching the server's display), then you need to do the equivalent of the Windows answer.
The graphics display on Linux (assuming you're not running wayland) is using a protocol called X11. In order for the display to appear, your GUI program needs two things. The first is to know which display it needs to use. This is supplied with an environment variable called DISPLAY. The second is an authorization to actually use that display.
So in order for your PHP script to run a GUI app that will show its GUI, you will need to first do the following steps:
Set the DISPLAY variable to the correct value (copy from your desktop environment).
Run xauth add something, where you can get what something is by running xauth list on your desktop environment.
If you do these two things (in this order), your GUI should show up.
i have used simple PHP script to execute exe file through php script, below is my PHP code
<? exec('"C:\Windows\notepad.exe"');?>
my problem is, when i check task manager after executing above code, notepad.exe is there but it is not diplaying
same way if i execute below mentioned code
<? exec('"C:\Program Files\WinSCP\WinSCP.exe"'); ?>
task manager shows WinSCP.exe, but winscp is not diplaying
can anyone tell me why applications are not showing ?
Whatever your web server is (Apache, Nginx, IIS...) it's clearly not configured to run with the credentials of your administrator user account. That's the sensible default. Background services are designed to run unattended.
You have several choice, from worse to better:
Kill security in your web server configuration. If web server runs as service, open Windows Service Manager and configure it to run with your account (don't forget to come back here if you change your password in the future). This way you allow any stranger in your computer, local network and/or internet to run programs in your name, in this case Notepad and WinSCP.
If the web server allows it, run it from a command-prompt in your own session. It's similar to #1 but will at least not run 24/7.
Any of the above, with a restricted account.
Don't use a web server. PHP can run from the command-line just fine, what means that you can even create a *.bat file and assign an icon to it.
As about your code, when it finally works your script will sleep until you close Notepad. This can be a bug or a feature depending on your needs.
Had the same problem with WAMP 2.4 & windows XP, the following helped:
Win+R, services.msc
edit wampapache and wampmysqld to allow affecting desktop.
Alternatively you can try:
Win+R, services.msc
edit wampapache and wampmysqld to log on as the same user.
I have a server A where some logs are saved, and another server B with a web server (IIS) on it.
I can access serverA from Windows Explorer with zero problems, but when I want to access it from serverB with some PHP code, it doesn't work.
I made a python script that accesses the file from serverA on serverB. It works if I run that script from CMD, but when I run that script from PHP code it doesn't work anymore.
I run IIS server as a domain account that has access on serverA
I try to run that as LocalService, NetworkService, System, LocalUser but no success.
That script is a simple open command, so problem it's not from python.
Since you provide no example code or describe what you are doing... There are a few things to consider.
Anything running in the context of a webpage in IIS is running in a different context than a logged in user.
The first part of that is simply what file system level permissions might be different for the IIS user account. The proper way you want to handle that is by assigning the necessary changes at the filesystem level for the IIS user. Do not change the IIS user if you do not understand the ramifications of doing that.
The next part is that certain operations cannot be done in the context of the IIS user account (regardless of account permissions), because there are certain things that only a logged in user with access to the console/desktop can do.
Certain operations called from IIS are purposely blocked (shell.execute) regardless of permissions, account used, etc. This occurs in versions of IIS in Windows Server 2008 and later and is done for security.
Resolved.
Uninstall IIS and use XAMPP.
No problem found till now, everything works okay.
So use XAMPP/WAMP!
I am running a server on my localhost.
through my index HTML page I am executing proccesses, (with the help of php page).
Now, if I am running those programs by myself and not throught the web browser in the html page,
I can see them as applications in the Windows Task Manager (in the Applications bar), and also the windows of the applications themselvs, and the output in running time.
But when I am executing those apps throught the web page, I cannot see them at all (The server and the applications are on my computer)
Why is that? I want to be able to see the result they show me in running time but I cant.
Is there any way to change that?
OS: Windows XP
Server: WampServer 2.2
Did you enable Show processes from all users ?
I developed a chat application with an attendant chat server. Everything is working fine. The issue now is the fact that whenever the chat server goes down (for instance, the server system shuts down as a result of power failure or some other problem), by the time the server system come back on, the chat server would have to be restarted manually.
I believe (and I know) it is more appropriate for the chat server application to restart itself when the computer comes back on (and of course regardless of who is logged in and of course, even before anyone logs in). I have a batch file that executes the chat server. My attempt was to create a windows service that start automatically and runs this batch file using a Network Service account on the server system. Although, I'm having a hard time with this (temporarily), I would love to ask if there are any alternatives to using a windows service. Suggestions are highly appreciated.
Creating a windows service will be the better solution, but you can add your batch file into the startup folder.
I think you are already having the better solution (Wibndows Service). Along with adding an email alert or some sort of alert when the server restarts will be handy (?).
I would probably just start the server using the Windows Task Scheduler. You can set a task to start on system startup: