So my environment is Windows server 2008 R2 with php 5.3 and 5.5 installed. I have set fastcgi.impersonate =1 in php.ini, and added the IIS_IUSRS to the Administrator group (that is not permanent, it was just a temporary action to try and eliminate problems).
If I run:
exec('dir',$output)
$output shows what I would expect. However, if I run
exec('shutdown -s -f', $output)
I get nothing from $output, and the machine does not shut down.
No errors/warnings are reported either.
I have tried putting that same command in a .bat file and running
exec('shutdown.bat',$output);
but it produces the same results as running the shutdown command via command line.
If I run the shutdown.bat file by double clicking it, or if I type the shutdown command in a cmd window, the machine will shut down. So I know that command is good. Obviously there is a higher permissions issue that I am missing, but I have no idea what it is.
So, I found out through much trial and tribulation that (at least in server 2008 r2 w/IIS7 ) executing the shutdown command from fast_cgi or php is not possible. I only had to install apache and execute the shutdown command under it, and the command worked perfectly.
Related
I would like to configure PHPStorm so that I can run Artisan commands directly from my IDE's terminal. For example php artisan key:generate. However, when I do, I receive the error 'php' is not recognized as an internal or external command.
Background:
running Windows 10 as host machine
using Docker to run my webserver (Nginx) and PHP interpreter (7.2-fpm).
I followed this tutorial.
https://www.digitalocean.com/community/tutorials/how-to-set-up-laravel-nginx-and-mysql-with-docker-compose.
One thing the tutorial didn't cover was how to set up my remote PHP CLI interpreter. For that, I followed https://www.jetbrains.com/help/phpstorm/configuring-remote-interpreters.html and can make a successful connection as it picks up the correct PHP version 7.2.21 as seen in the screenshot.
After this, I restarted my Windows 10 host machine, fired up the container, opened my IDE and tried to run php -v from the terminal but hit the error again.
I know it has something to do with my PATH environment variable being set incorrectly, or not at all but I am not sure how to point it to the container's PHP interpreter. Any help would be greatly appreciated.
EDIT
For what it is worth, I know that I can exec into the container and run PHP commands from there, but thought I might be able to do it directly from my host machine by pointing to the container's interpreter.
The terminal in PHPstorm is the same as any other terminal on your computer. It doesn't automatically connect to docker to run the php -v command. If you want to run php from PHPstorm in docker you can right click the file:
Choose run:
And select your created docker interpreter as your runtime:
If the fix button doesn't show it can be configured through:
settings > Languages & Frameworks > PHP
And then clicking on the 3 dots at the end of "CLI interpreter"
I face this error only when "php artisan serve" command is not running. If this command is running then there is no such a error, but as i closed command prompt this error occurs. i have also changed port but no vain.
Kindly help me.I would like to mention here that I'm using Window 10 OS.
Thanks in advance.
If you don't have a HTTP server (like WAMP or similar installed), you'll need to keep the Command Prompt / Terminal window running at all times. Closing the window or stopping the php artisan server command will terminate the server that's running the website.
If you want a persistent server, you should look into server software like WAMP or XAMPP.
Note that this is expected behavior for the php artisan serve command.
because with this kind of server (like: LARAGON), running 'php artisan serve' is necessary, so if you close the terminal, 'php artisan serve' will automaticaly stop running, then the server will stop too, then you can't reach anymore your localhost.
If you want a persistent server, you should look into server software like WAMP or XAMPP.
Note that this is expected behavior for the
php artisan serve command
I have been using mySQL for a few weeks now with PHPMyAdmin with no problems. But just lately it stopped working - MySQL server will run for a few seconds when I start my machine (Mac OS X 10.9.5)then it crashes and wont restart. It also wont let me log in PHPMyAdmin.
When i try to run mysql through terminal it returns the following error:
Can't connect to local MySQL server through socket '/tmp/mysql.sock
I'm not really sure what could cause this after it working for so long.
mysql on the command line/terminal is just another MySQL client, like phpMyAdmin or your web application. The error you're seeing is the same error as phpMyAdmin is displaying. On linux/OSX the command is actually mysqld (d for Daemon or server).
Homebrew/Macports/etc installs
During installation it should have installed a launchctl script. Find it on the terminal with ls ~/Library/LaunchAgents/ and inspect the output, in my case:
homebrew.mxcl.lighttpd.plist
homebrew.mxcl.mysql.plist
homebrew.mxcl.php55.plist
There in the middle - now I can use launchctl to start it at the terminal:
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Although the handy launchctl script is called "mysql" it's actually launching mysqld, usually from /usr/local/bin/mysqld
Standard MySQL install
If you installed MySQL directly from their website, you should have a "MySQL" option in your System Preferences. From there you can stop/start the service.
If you didn't install mysqld with a package manager, perhaps you installed/compiled it yourself, then search your disk for mysqld and launch it from the command line or find an init.d folder with a mysqld script inside.
I have installed MAMP on my OSX and tried to run a shell command from my php file but it seems I can't access the terminal or the command is not being sent to terminal.
$cmd = "some shell command"
$output = shell_exec($cmd);
if($output == null)
echo "returned null";
else echo $output;
I'm always getting "returned null" and there shell command is not being executed. The command is correct, if I copied "some shell command" and paste it in terminal, the command gets executed. I have tested the same file in Windows and the command line is executed from php, this problem only appears in mac. So how can I access terminal in mac?
PS:
OSX 10.6.8
MAMP 2.0.5
PHP 5.3.6
There is lot of difference between Windows/Mac/Linux OS working. In Windows shell_exe command has provided the access. Even if the user has limited resources in Windows the shell_exe command can be execute.
In case of Mac/Linux OS there are lot of restrictions on running shell_exe commands. It is also highly recommended not to shell_exe commands from PHP. The host machine will become target easily. You have to edit the PHP.INI for providing shell_exe access to the user.
If you are not admin of host machine of Mac/Linux then ask the Machine admin to do so. If, Admin Provides access then ok less you have to try another way around and that depends on your project requirements.
Editing PHP.INI
Which is the correct PHP.INI file for editing depends on the OS used by Machine. The location generally changed according to the required things.
If you are using WHM CPanel then it becomes little easy. The general location of php.ini file
/usr/local/lib
and if you are using any other 3rd Party Program the location would generally changed to
/usr/local/cpanel/3rdparty/etc/php.ini
I'm running an Apache server on CentOS and would like to be able restart the webserver from a protected page using the following:
PHP:
<?php
ignore_user_abort(true);
shell_exec('sh sh/restart.sh');
?>
restart.sh:
service httpd restart
My question is if the web server shuts down and the PHP stops executing will the sh script continue running to bring the web server back online?
You should be fine since Apache doesn't shutdown until after the command is issued. But if you really wanted to be safe, use nohup:
shell_exec('nohup sh sh/restart.sh');
If your PHP runs as apache module, then once you kill httpd your script will be terminated instantly. So you need to delegate restart to i.e. command line script (called using exec() or shell_exec())
You might be able to add an & at the end of the command. This will fork the process and run it in the background. This way it will not depend on apache still running.
shell_exec('sh sh/restart.sh &');
If this works, you should not need ignore_user_abort().