Convert a PHP script into a stand-alone windows executable
Asked Answered
M

8

156

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.

Motherly answered 28/1, 2012 at 16:7 Comment(3)
have you heard about bamcompile (r) ?Trinity
Have been using Bambalam for a number of years. It's been stalled for about forever now - and more to the point, it's only compatible with PHP4.4.4. However, as long as you don't require UTF8 support and similar and can deal with broken foreach() and some others, it should work for you. Do note that it's impossible to deal with, say, UTF8 filenames in a directory, with PHP4.4.4. Also remember it creates files in %TEMP% that are never removed (php[0-F]{2}.tmp), you will need to clean these up.Goncourt
PHP's binaries can run portably. You can just tell people to extract an entire folder and create a batch file that executes something like "php.exe -c php.ini script.php".Popovich
S
212

Peachpie

http://www.peachpie.io

https://github.com/iolevel/peachpie

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

http://v4.php-compiler.net/

http://wiki.php-compiler.net/Phalanger_Wiki

https://github.com/devsense/phalanger

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

https://github.com/xZero707/Bamcompile/

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!

ZZEE PHPExe

http://www.zzee.com/phpexe/

ZZEE PHPExe compiles PHP, HTML, Javascript, Flash and other web files into Windows GUI exes. You can rapidly develop Windows GUI applications by employing the familiar PHP web paradigm. You can use the same code for online and Windows applications with little or no modification. It is a Commercial product.

phc-win

http://wiki.swiftlytilting.com/Phc-win

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.

Requires

  • php5ts.dll
  • php_win32std.dll
  • php_bcompiler.dll
  • php-embed.ini

ExeOutput

http://www.exeoutput.com/

Commercial

WinBinder

http://winbinder.org/ - no longer available

(original: https://github.com/stefan-loewe/WinBinder)

(fork: https://github.com/wagy/WinBinder)

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.

PHPDesktop

https://github.com/cztomczak/phpdesktop

PHP Desktop is an open source project founded by Czarek Tomczak in 2012 to provide a way for developing native desktop applications using web technologies such as PHP, HTML5, JavaScript & SQLite. This project is more than just a PHP to EXE compiler, it embeds a web-browser (Internet Explorer or Chrome embedded), a Mongoose web-server and a PHP interpreter. The development workflow you are used to remains the same, the step of turning an existing website into a desktop application is basically a matter of copying it to "www/" directory. Using SQLite database is optional, you could embed mysql/postgresql database in application's installer.

PHP Nightrain

https://github.com/kjellberg/nightrain

Using PHP Nightrain you will be able to deploy and run HTML, CSS, JavaScript and PHP web applications as a native desktop application on Windows, Mac and the Linux operating systems. Popular PHP Frameworks (e.g. CakePHP, Laravel, Drupal, etc…) are well supported!

phc-win "fork"

https://github.com/RDashINC/phc-win

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.

EDIT

Another option is to use

http://www.appcelerator.com/products/titanium-cross-platform-application-development/

an online compiler that can build executables for a number of different platforms, from a number of different languages including PHP

TideSDK

http://www.tidesdk.org/

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.

Smudge answered 28/1, 2012 at 16:20 Comment(12)
I can confirm that phc-win works for creating console exe file with PHP 5.3 code. Just have the PHP script in same folder as php-win exe is.Spermatium
I used bambalam compiler. It's pretty cool and easy and also support win-builder, but do not support php5 :(Vertical
PHP-Nightrain is an very good alternative to PHPDesktop - and is cross-platform (Windows, OSX, Linux). While it had a bad reputation because of the dependency on Java, it has now switched to Python as a wrapper, and is a very good choice for developing cross-platform software based on PHP. -- github.com/naetech/nightrainIsagogics
Just lost a all sunday with a Bambalam problem/beaviour. In this install it executes like 50 time a day. It creates temporary files with fixed name size he never deletes (4 chars)... result no more free file names. Sysinternals procmon helped figure out what happened. Was not easy and leaves a bad vibe on Bambalam.Chappell
I tried Bambalam and ExecOutput for a single php test app. Both could create executable but both hanged forever. May be I missed some thing. However, PHPDesktop worked without any problem!Justiceship
great job men! I will try some of them. Which is the best for use mysql database with php site?Roberto
I'd like to point out, this is list is little bit outdated. Currently the most recent PHP compiler is Peachpie github.com/iolevel/peachpie which compiles PHP 7.1 code to .NET and .NET CoreDither
Bambalam at its latest version is PHP4.4.4. One more note that requires attention: it will unpack the PHP code into temporary files in %TEMP% each time one of its exe files is started, and these files are not cleaned up afterwards. It also supports any PHP .dll for PHP4.4.4 you can find, incl. sockets, OpenAL, SDL (poor performance), SQLite etc. If you're really into it, download the PHP4.4.4 source and build/fix more.Goncourt
i want to convert zend framwork project to exe file which will used for thatUnterwalden
Your explanation is quite exhaustive. I like it. I will test that.Insubstantial
all these are outdated. is there a newer one that should support php 8 and free of costSawn
Same issue as @Sawn above, these are all outdated, ancient, not in development, or even completely gone. But while searching I found PHPBrowserBox at phpbb.africoders.com and I'm about to test it these days. It promises PHP 8.2, Chromium for GUI apps, MySQL for larger DBs, compatibility with large PHP frameworks, is still developed and updated, 10 years of development behind the project, not a single person it seems, etc. Also has (external) solutions to source code encryption, and packaging. But can also be portable. Seems they covered all aspects, so now it's just to test it all.Drucill
M
13

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
...
Maxma answered 13/11, 2015 at 0:22 Comment(2)
hi your solution is very interesting. Is similar to quickphp web server. Do you have simple example for that? I'm hoping you could provide a source. Nice idea by the way.Mucker
This is really interesting! But the thing is, that OP does not want to "give away the source code", and even a rookie could just extract the script from SFX.Opium
S
11

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.

Snook answered 17/3, 2016 at 11:52 Comment(1)
PHP Desktop now supports Linux, see its initial release: github.com/cztomczak/phpdesktop/releases/tag/linux-v72.0Epoch
M
8

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!

Marcelenemarcelia answered 26/12, 2017 at 18:38 Comment(9)
I tried using your tool but I get the following error Cannot find myself (D:\Desktop\phpflexer\phpflexer.exe)Padus
It's promising but could you add a few libraries to this? For example I need GD2 so my scripts can work on images.Conscious
@Tom: sure, there's a new version and if you feel like testing it I can give you a download link. (No malware, I promise.) It's actually a lot better now and it's php 7.2, plus I think it will be capable of handling other languages. My gmail is kellnerdenes.Marcelenemarcelia
@Padus - yes, sorry for that, others reported it as well. It's a file handling thing in the underlying PHP; try downloading now, I have a hopefully-fixed phpflexer version on the same link.Marcelenemarcelia
Just gave this a try, pretty neat solution for compiled command-line scripts! I have been using ExeOutput4PHP for most of my GUI projects for quite a while now, but for console apps RapidEXE also looks great, if not better.Opium
@JayDadhania Music to my ears! Version 3 coming soon, stay tuned!Marcelenemarcelia
very nice tool, her remember bamcopile , but updatedSpaulding
Wish this was still updated, unfortunately it got left at PHP 7.2 (2017).Drucill
You can add your own engine (php 8+) in a jiff. But I will come up with a new version, I promise.Marcelenemarcelia
O
2

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/

Overelaborate answered 29/11, 2013 at 8:55 Comment(0)
D
2

I wrote an article about this, this can be done using a packer, resulting size is about 2.7mb, faster & flexible execution rather than most php compilers today.

Enigma Virtual Box is used for embedding small PHP executable (version of your choice), you can embed any extension you like. After first execution and seamless unpacking of files, following executions take less than a second as usual.

Merkle calculation

Desiree answered 7/5, 2023 at 9:27 Comment(2)
Link only answers are considered very low quality and can get deleted, please put the important parts from the linked resource into the answer body.Crossquestion
worked flawlessly following the instructions.Numerable
E
1

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.

Electrodynamometer answered 8/12, 2013 at 10:26 Comment(1)
Create a shorcut to localhost it's a hard work, dont? :) Anyway you have reason on "works well on small projects". The unique full "as you want" is the phpdesktop.Vertical
H
1

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

Hylan answered 24/6, 2015 at 12:13 Comment(1)
naetech.com has been stolen. Cannot download anything.Astronomer

© 2022 - 2024 — McMap. All rights reserved.