PHP exec() command not working - php

After hours and hours of trying and searching for an answer i coudn't get it working.
Hosting details:
Windows Server 2012 R2
Plesk 12
IIS 8.5
The problem
My problem is:
I want to execute this command in PHP. The command is necessary to reload the configs for filezilla, after creating a new user with an PHP script.
C:\Program Files (x86)\FileZilla Server\FileZilla Server.exe /reload-config
It does work when i try it directly in CMD.
But in PHP if doens't somehow work. I tried so many things, that im going to try to give you all the manners i tried.
I tried to do this at the following ways:
Trial 1
$command = '"C:\\Program Files (x86)\\FileZilla Server\\FileZilla Server.exe" /reload-config';
exec( $command, $output, $return);
print_r($output);
echo '<br/>' .$return;
Output:
Array ( )
0
Trial 2
$command = '"C:\\Program Files (x86)\\FileZilla Server\\FileZilla Server.exe" /reload-config';
system( $command, $output);
print_r($output);
Output: 0
Trial 3
$command = 'C:\\"Program Files (x86)\\FileZilla Server\\FileZilla Server.exe" /reload-config';
exec( $command, $output, $return);
print_r($output);
echo '<br/>' .$return;
Output: 0
Trial 4 (The only one that returns an error!)
exec( 'C:\\"Program Files (x86)\\FileZilla Server\\FileZilla Server.exe" /stop 2>&1', $output);
print_r($output);
Output:
Array ( [0] => Toegang geweigerd. )
In english:
Array ( [0] => Access denied. )
Privileges:
In allmost all awnsers found they talked about privileges. I did following privileges:
Gave all web users and IUSR privileges to CMD.exe and FileZilla Server.exe,
and tried to set the IIS authentication from anonymous to an Administrator account
Somebody said to try this:
echo '<pre>';
system('set', $retval);
echo ' </pre>';
If i do that my output is: http://pastebin.com/SjzeQpJ0
If you guys want anymore details just ask. I hope you guys can figure it out for me. I tried to be as clear as possible. Thanks.
Finaly found the solution!!
If you encounter the same problem as i did, and you dont know how to fix this, follow this steps.
Login to the Remote of your server (if you have access to it) Open
Open the IIS manager
Select -> Application Pools node underneath the machine node (left panel)
Right click on the desired domainname -> Advanced settings
Scroll to Process Model -> Id
Click on the 3 dots
Check the Custom Account radio button
Fill in an existing administration account which has access to the
remote desktop and of course its password
Press OK
Now go to the .exe or whatever file you want to access throught the
exec command and
Right click on the file and select properties
Go to the security tab
Select Edit
Now grand full rights to the account you selected before. If its
not listed than add it manualy by clicking on Add
If you have done all of this, it now should work.

Finaly found the solution!!
If you encounter the same problem as i did, and you dont know how to fix this, follow this steps.
Login to the Remote of your server (if you have access to it)
Open the IIS manager
Select -> Application Pools node underneath the machine node (left panel)
Right click on the desired domainname -> Advanced settings
Scroll to Process Model -> Identity
Click on the 3 dots
Check the Custom Account radio button
Fill in an existing administration account which has access to the
remote desktop and of course its password
Press OK
Now go to the .exe or whatever file you want to access throught the
exec command and
Right click on the file and select properties
Go to the security tab
Select Edit
Now grand full rights to the account you selected before. If its
not listed than add it manualy by clicking on Add
If you have done all of this, it now should work.

There is a much safer way to do this I figured out by using the above and exploring some. All you need to do is enable "Load User Profile" and it will then have all the normal user permissions assigned by a regular user. Just got it working like this instead of giving administrative access:
Login to the Remote of your server (if you have access to it)
Open the IIS manager
Select -> Application Pools node underneath the machine node (left panel)
Right click on the desired domainname -> Advanced settings
Scroll to Process Model -> Id
Set Load User Profile = True
and working! specifically fixed Windows 2012 R2

Go to IIS
Click on Application Pool
Select the application pool -> Advance Settings
Under Popup -> Process Model -> Set Load User Profile to TRUE
And -> Process Model -> Identity -> Local System
This will act as a current user
Note: If current has high privileges over system, This will be high risk.

Related

could not configure domains in zpanel vps

I'm working on a vps server with zpanel.I really new in this area .I don't know how to set up WordPress and use it . I have gone through this manual .But this is not really helping . I got stuck at the 5th step.there is no ajax explorer in my zpanel.Then i gone through another manual which says to add a repo in zpanel .I don't know how to add that also .Can anyone please help me in setting up a wordpress site manualy into my zpanel.Thanks !
1) first download some SSH client, I recommend Putty (http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html). Choose the version that suits your operating system.
2) login to your VPS via SSH. In putty under "hostname your IP adress" put your VPS's IP or a domain name you have configured for that server. Check that the port number on the right to the hostname is 22. Click OPEN button in the bottom.
3) after providing your root username/password combo. follow all the steps from this page: http://www.servermom.org/install-ajaxplorer-file-manager-module-zpanel-cp/951/
Step 1 – Login to your server as root. I assume you knew how to do
this.
Step 2 – Then add additional repo for zPanel:
shell> zppy repo add zppy.alineofcode.co.uk
Step 3 – Now issue this command to update the repo:
shell> zppy update
Step 4 – Finally, here it is the main command to download and install
Ajaxplorer on your server:
shell> zppy install ajaxplorer
Step 5 – Open up your favorite web browser, visit the login page of
your zPanel server then login as zadmin.
login zpanel
Step 6 – Go to Server Admin >> Module Admin menu.
enable ajaxplorer
Step 7 – Next, enable Ajaxplorer module for Administrator, Reseller
and Client then hit the Save Changes button.
activate module
Step 8 – Before you test it, you better do some necessary checks. Now
go to Putty / Terminal window again then issue this command;
shell> nano /etc/zpanel/configs/apache/httpd.conf
Step 9 – Make sure the following line as below:
"php_admin_value upload_tmp_dir /var/zpanel/temp"
and not as below (the wrong one):
"php_admin_value upload_tmp_dir /etc/zpanel/temp"
Otherwise you might find some errors.
Step 10 – Go back to zPanel configuration page in your browser. Click
on File Management menu >> then Ajaxplorer >> followed by clicking the
Launch Ajaxplorer button.
launch ajaxplorer
Step 11 – You’ll notice that a new browser window appears launching
Ajaxplorer main UI up. Wait for few seconds till the interface fully
loaded.
loading
And Voila!
4) back to your original instructions page and continue from step 5

Run on IIS server shell command in php

I use an IIS server and I want to execute some shell commands, but do not know exactly what the problem is.
For example, you want to set the time, or to create a new user, or whatever, does absolutely nothing (return null)
<?php
$output = shell_exec("time 11:50 PM");
echo '<pre>';
print_r($output);
echo '</pre>';
?>
And I thought to show username that is connected to see if with Administrator rights or not.
"echo %username%"
instead return my username, it returns me "COMPUTERNAME-PC$"
How can I run shell commands as administrator?
The short answer is you can't as it's configured now. You're restricted to the application pool identity. More than likely you're using the NETWORK SERVICE user, which is why you're getting the PC name as the username.
The solution would be to change the application pool identity to a user that the permissions you need. But you could still run into issues if User Account Control (UAC) is enabled, and you run a command that requires elevation which it sounds like you want to do.

shell_exec not running for a particular code in php

When i try to use *shell_exec(cmd)* or system(cmd) for a command like ping google.com then it works properly.
Code 1:Will work in PHP
<?php
echo shell_exec(ping google.com)
?>
But when i try executing the following code it returns a blank page.
Code 2: Will not work in PHP
<?php
echo shell_exec(ec2-describe-addresses --region us-west-2)
?>
Both the commands
1.ping google.com
2.ec2-describe-addresses --region us-west-2
Works in windows command prompt properly.
Can someone please guide me as in how can i run the second command in PHP?
PS:ec2-describe-addresses --region us-west-2 is a AWS EC2 command to Describing Elastic IP Addresses for Account http://aws.amazon.com/articles/Amazon-EC2/1346
The issue was that PHP was running not as root user changing the user to root actually solved the problem.
For those who wants to know how to Switch PHP user to ROOT.
Just Follow the following steps.
Step 1: Open httpd.conf
Step 2: Search for User/Group
Step 3: Under it you will find
User (your default user name)
Group (your default group name)
Change it to root so that your file looks like this:-
User root
Group root
Step 4: Restart Apache
PS:Switching PHP to work as root user is not suggested for production servers. Please change this only if you are sure about this.

Trouble with custom PHP extension

A couple of months ago, I built a serial connection library in C for the Arduino Micro-controller. I was thinking about how awesome it would be if I could write a PHP wrapper for the library.
I wrote a PHP extension with just one function called "acm_get_door()," which should either return a -1, 0, or 1, depending upon the status of a certain pin on my Arduino. If it returns -1, then that means that the connection wasn't set.
So after loading up the custom extension and changing both of my php.ini files, and restarting everything else, I ran this test via the CLI:
$ php -r 'echo acm_get_door();'
It returned a '1'. I was excited, so I played with the circuitry to see if I could get a '0'. Well I did and I thought my extension was working perfectly.
I then went to a .php file in my test webserver (same computer) and tried to run the function. I got a '-1' result from it. The extension does load, but I can't seem to initiate a connection to the Arduino.
I am wondering if it might be a permissions thing regarding access to certain files. The function needs to get access to a file called "/dev/ttyACM0" which it is able to in the CLI version. It is possible that my Apache web server doesn't have the permissions to access that file, and if so, how would I be able to adjust stuff so that it does?
Thank you for your time.
Probably the group has permissions to read/write the device.
Therefore, find out the group owner of the device using ls -l /dev/tty/ACM0. Then, add yourself to the group using:
sudo adduser <me> <the_group>
(where me is your username and the_group is the group of the device)
You might need to log out/in to gain the effect of the changed group permissions.
Okay, thanks to John Jesus, I just had to change the permissions of the file /dev/ttyACM0.
It was set to 660, 666 seems to work (though it it probably a bad idea).

Mapped Network Drives

I have mapped a network drive to a computer in my home network. Now I am trying to access it via PHP - I did this quick test:
echo opendir('Z:\\');
This gives me:
Warning: opendir(Z:\) [function.opendir]: failed to open dir: No error in C:\wamp\www\webs\tester-function.php on line 3
What have I done wrong here?
I don't want my users typing in the UNC path so is there a way to get the UNC path for them and maybe that will work when I try to access it? This is possible in Microsoft languages but I am not sure how to get PHP to do this - maybe using a cmd.exe command?
Please note, the mapped drive does exist as I can see it and I can access it. It also does not appear to be a permissions problem as I am assuming it would of complained about this IF it could access that drive...right?
Thanks all for any help
The User Contributed Notes to opendir() have this:
I was trying to access network drives using this opendir function. I read so many posts saying that it was almost impossible to access a network drive and finally, I found the answer; there are 2 steps to be followed to access a network drive with PHP either on the same machine or another machine.
in this case, the user rights seemed indeed to be the problem, which can be different from your rights depending on what user PHP / the web server are running on.
Open the Services MMC by going to Start -> Run (or by using the search box, if using Windows 7) and typing Services.msc and pressing enter.
Find the Apache service. Having never used WAMP, I have no idea what it's been named. Hopefully it starts with the word "Apache" though, and thus shouldn't be too hard to find.
Right-click on the service and select Properties.
Switch to the Log On tab.
Select the radio button next to "This account:" and enter in the credentials for the user account you want to run Apache under. If it's a network/domain account, use the "DOMAIN\user" syntax (or search for the account using the Browse button).
Select OK and restart the Apache service.
Verify that your changes worked by looking for the "httpd.exe" process in Task Manager and checking to see which user name the process is running under.
reference http://board.phpbuilder.com/board/showthread.php?t=10371870&page=2
simple, use: "\\\\server\\dir\\subfolder" as the path. make sure you can access the "server".
works for me.
$arquivo = "\\\\server\\dir\\subfolder\\file.txt";
echo is_file($arquivo); //print 1.

Categories