Alex C Posted July 12, 2008 Share Posted July 12, 2008 Hi there, Can you use php exec to run a .exe on a linux server? I have a simple keygen.exe that i want to run using php so i can integrate it into my site to generate keys on the fly. I have seen examples using php exec on windows servers but cant find any examples on Linux servers. Well i know you cant run a .exe on Linux without using Wine, so do i have to install wine first? I would really appreciate it if someone could let me know the guidelines to running a .exe on a linux server using php exec as i dont want to start going down the wrong path and get nowhere. I hope someone can help. Thanks, Alex Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted July 12, 2008 Share Posted July 12, 2008 Maybe look into shell_exec(). I wouldn't know, never tried running files with PHP. But check it out. Quote Link to comment Share on other sites More sharing options...
Alex C Posted July 12, 2008 Author Share Posted July 12, 2008 Thanks, I see that shell_exec is defined as "Execute command via shell and return the complete output as a string" So i suppose that would work if Wine was installed maybe, if i can get get the keygen.exe to work from the shell then it should work from running shell_exec on php. Ill give it a go, any other input from anyone would be greatly appreciated. Thanks, Alex Quote Link to comment Share on other sites More sharing options...
rarebit Posted July 12, 2008 Share Posted July 12, 2008 Have you got the source to the exe? Just recompile on linux (pref using cross-compiler or specifically on that machine) Quote Link to comment Share on other sites More sharing options...
Alex C Posted July 12, 2008 Author Share Posted July 12, 2008 Erm i dont think so. The keygen gets created automatically by Chameleon Flash. Im using this program to make single .exe files for my flash projects. It creates custom keygens for each project ID and gives the option to create a command line keygen.exe so you can integrate it into your website to create keys on the fly etc. Im still installing Wine so haven't tried that yet, although im beginning to think this is a long winded solution. Any other ideas guys? Quote Link to comment Share on other sites More sharing options...
Alex C Posted July 12, 2008 Author Share Posted July 12, 2008 Anyone? I still need help on this? Hope someone can help solve this issue. Thanks, Alex Quote Link to comment Share on other sites More sharing options...
marklarah Posted July 13, 2008 Share Posted July 13, 2008 Simple solution - if this is just to generate random keys, just code it in php? Quote Link to comment Share on other sites More sharing options...
dezkit Posted July 13, 2008 Share Posted July 13, 2008 hi sir, why do you need to generate random keys hmm? to do something illegal maybe? am i right? Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted July 13, 2008 Share Posted July 13, 2008 hi sir, why do you need to generate random keys hmm? to do something illegal maybe? am i right? The keygen gets created automatically by Chameleon Flash. Im using this program to make single .exe files for my flash projects. It creates custom keygens for each project ID and gives the option to create a command line keygen.exe so you can integrate it into your website to create keys on the fly etc. What makes you think it's for illegal things? I to am wondering why you can't just code it into PHP, the keygen that is. Quote Link to comment Share on other sites More sharing options...
Alex C Posted July 13, 2008 Author Share Posted July 13, 2008 Haha, no nothing illegal. Well i don't know how the keygen was made, it works by passing two variables, your user name and hardware id of the computer you are on. The keygen is compiled as a separate file at the same time as the flash project is compiled, so it only generates keys that will work with the flash file that was compiled at the same time. Please correct me if im wrong, but how on earth would you go about hard coding a keygen with php that will work with the flash file that was compiled, if the flash file that was compiled will only work with the keygen that was compiled at the same time? On another note, i have installed Wine and can successfully run the keygen on the server via the command line with this command: # wine keygen.exe 'Name=Alex' 'HWID=########' And it outputs the key fine. However i still cant get it to work with PHP. I have tried the using exec and shell_exec with the following code: echo exec("wine keygen.exe 'Name=Alex' 'HWID=########'"); //or try this echo shell_exec("wine keygen.exe 'Name=Alex' 'HWID=########'"); Trying the above calls does not work and just displays a blank screen with no error messages at all. The keygen.exe file is in the same directory as the file that is calling it. Have i used the correct syntax? If anyone could help in anyway i would really appreciate it, if i can get it to work with the command line on Linux surely i can get PHP to output it now? I hope someone can help, Thanks, Alex Quote Link to comment Share on other sites More sharing options...
Alex C Posted July 14, 2008 Author Share Posted July 14, 2008 Anyone guys? Thanks, Alex Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted July 14, 2008 Share Posted July 14, 2008 make sure error_reporting is set to E_ALL error_reporting(E_ALL); Just in case. But other then that, I seriously have NO idea. Quote Link to comment Share on other sites More sharing options...
trq Posted July 14, 2008 Share Posted July 14, 2008 It is likely you need to use the full paths top both wine and the keygen.exe. eg; echo shell_exec("/usr/bin/wine /home/foo/keygen.exe 'Name=Alex' 'HWID=########'"); Quote Link to comment Share on other sites More sharing options...
Alex C Posted July 15, 2008 Author Share Posted July 15, 2008 Hi guys, Thanks for all the help, but after trying loads of things i still couldn't get it to work on Linux. So im now thinking its just going to be easier to have an iframe on my site which calls the keygen that is hosted on a windows server somewhere. Thanks for all the help, Alex Quote Link to comment Share on other sites More sharing options...
mbeals Posted July 15, 2008 Share Posted July 15, 2008 what are the permissions on the keygen program? php system() commands are run as the apache user, which is locked down and may not have the permissions to run the file (or even wine). As root, switch into the user www-data (su www-data). Do it as root to avoid entering a password for www-data. Once you are in www-data's shell, try executing the command again and see if you get an error. Quote Link to comment Share on other sites More sharing options...
trq Posted July 15, 2008 Share Posted July 15, 2008 Apache process owner (you assume www-data in your post) should not be able to login to a shell. If you can login and use that account, there is some serious security issues. Quote Link to comment Share on other sites More sharing options...
Alex C Posted July 15, 2008 Author Share Posted July 15, 2008 Yer i think it probably is a permissions error with running wine as apache. I have now used an iframe loading a php script on a windows server and the keygen works straight away by simply using exec(); Thanks for the help, Alex Quote Link to comment Share on other sites More sharing options...
trq Posted July 15, 2008 Share Posted July 15, 2008 Hehe, that just goes to prove how insecure windows is. Quote Link to comment Share on other sites More sharing options...
anon_login_001 Posted July 15, 2008 Share Posted July 15, 2008 Since I think IFrames are yucky, and because some browser security settings may prevent you from loading contents in your page from an off-site host, you could also have PHP remotely access the Windows server, get the result, and use that in the generated page ... rather than having the generated page access the remote server. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.