Jump to content

How to use php exec to run a .exe on a Linux Server


Alex C

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

 

:(

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.