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.
Peachpie is PHP 7 compiler based on Roslyn by Microsoft and drawing from popular Phalanger. It allows PHP to be executed within the .NET/.NETCore by compiling the PHP code to pure MSIL.
Phalanger is a project which was started at Charles University in Prague and was supported by Microsoft. It compiles source code written in the PHP scripting language into CIL (Common Intermediate Language) byte-code. It handles the beginning of a compiling process which is completed by the JIT compiler component of the .NET Framework. It does not address native code generation nor optimization. Its purpose is to compile PHP scripts into .NET assemblies, logical units containing CIL code and meta-data.
Bambalam PHP EXE Compiler/Embedder is a free command line tool to convert PHP applications to standalone Windows .exe applications. The exe files produced are totally standalone, no need for php dlls etc. The php code is encoded using the Turck MMCache Encode library so it’s a perfect solution if you want to distribute your application while protecting your source code. The converter is also suitable for producing .exe files for windowed PHP applications (created using for example the WinBinder library). It’s also good for making stand-alone PHP Socket servers/clients (using the php_sockets.dll extension).
It’s NOT really a compiler in the sense that it doesn’t produce native machine code from PHP sources, but it works!
The PHP extension bcompiler is used to compile PHP script code into PHP bytecode. This bytecode can be included just like any php file as long as the bcompiler extension is loaded. Once all the bytecode files have been created, a modified Embeder is used to pack all of the project files into the program exe.
http://winbinder.org/ – no longer available
WinBinder is an open source extension to PHP, the script programming language. It allows PHP programmers to easily build native Windows applications, producing quick and rewarding results with minimum effort. Even short scripts with a few dozen lines can generate a useful program, thanks to the power and flexibility of PHP.
A more-or-less forked version of phc-win, it uses the same techniques as phc-win but supports almost all modern PHP versions. (5.3, 5.4, 5.5, 5.6, etc) It also can use Enigma VB to combine the php5ts.dll with your exe, aswell as UPX compress it. Lastly, it has win32std and winbinder compilied statically into PHP.
Another option is to use
an online compiler that can build executables for a number of different platforms, from a number of different languages including PHP
TideSDK is actually the renamed Titanium Desktop project. Titanium remained focused on mobile, and abandoned the desktop version, which was taken over by some people who have open sourced it and dubbed it TideSDK.
Generally, TideSDK uses HTML, CSS and JS to render applications, but it supports scripted languages like PHP, as a plug-in module, as well as other scripting languages like Python and Ruby.
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
To run a basic script, the only files required are
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 ...
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.