[php] Convert a PHP script into a stand-alone windows executable

I want to automate a fairly simple task. For this I have written a small PHP script which I run from the command line using PHP-CLI. Now I want to hand over this script to someone but I do not want to:

  • give away the source code
  • ask him to install PHP on the system

Is there a way to create a .exe version of the PHP script. I am really not much worried about de-compilation; I am more worried about asking people to install and configure PHP.

This question is related to php obfuscation

The answer is


I had problems with most of the tools in other answers as they are all very outdated.

If you need a solution that will "just work", pack a bare-bones version of php with your project in a WinRar SFX archive, set it to extract everything to a temporary directory and execute php your_script.php.

To run a basic script, the only files required are php.exe and php5.dll (or php5ts.dll depending on version).

To add extensions, pack them along with a php.ini file:

[PHP]
extension_dir = "."
extension=php_curl.dll
extension=php_xxxx.dll
...

ExeOutput is also can Turn PHP Websites into Windows Applications and Software

Turn PHP Websites into Windows Applications and Software

Applications made with ExeOutput for PHP run PHP scripts, PHP applications, and PHP websites natively, and do not require a web server, a web browser, or PHP distribution. They are stand-alone and work on any computer with recent Windows versions.

ExeOutput for PHP is a powerful website compiler that works with all of the elements found on modern sites: PHP scripts, JavaScript, HTML, CSS, XML, PDF files, Flash, Flash videos, Silverlight videos, databases, and images. Combining these elements with PHP Runtime and PHP Extensions, ExeOutput for PHP builds an EXE file that contains your complete application.

http://www.exeoutput.com/


The current PHP Nightrain (4.0.0) is written in Python and it uses the wxPython libraries. So far wxPython has been working well to get PHP Nightrain where it is today but in order to push PHP Nightrain to its next level, we are introducing a sibling of PHP Nightrain, the PHPWebkit!

It's an update to PHP Nightrain.

https://github.com/entrypass/nightrain-ep


I tried most of solution given in the 1st answer, the only one that worked for me and is non-commercial is php-desktop.

I simply put my php files in the www/ folder, changed the name of .exe and was able to run my php as an exe !!

Also there is a complete documentation, up to date support, windows and linux (and soon mac) compatibility and options can easily be changed.


My experience in this matter tells me , most of these software work good with small projects .
But what about big projects? e.g: Zend Framework 2 and some things like that.
Some of them need browser to run and this is difficult to tell customer "please type http://localhost/" in your browser address bar !!

I create a simple project to do this : PHPPy

This is not complete way for create stand alone executable file for running php projects but helps you to do this.
I couldn't compile python file with PyInstaller or Py2exe to .exe file , hope you can.
You don't need uniformserver executable files.


RapidEXE is exactly for this job:

It converts a php project to a standalone exe. I had enough of all other compilers, tried them one by one and they all disappointed me one way or another. Be my guest, feedbacks are always welcome!

Side note: the mechanism behind it is quite similar to the WinRAR SFX approach; extract engine, extract source, then run. It's just faster and easier to work with. One-command compilation, compressed, smart unpack, auto cleanup, easy config, full control of php engine & version; also extensible with minimal effort.

Happy developing!