将 PHP 脚本转换为独立的 Windows 可执行文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9046675/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 06:02:32  来源:igfitidea点击:

Convert a PHP script into a stand-alone windows executable

phpobfuscation

提问by Salman A

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:

我想自动化一个相当简单的任务。为此,我编写了一个小的 PHP 脚本,我使用 PHP-CLI 从命令行运行该脚本。现在我想将此脚本交给某人,但我不想:

  • give away the source code
  • ask him to install PHP on the system
  • 赠送源代码
  • 让他在系统上安装 PHP

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.

有没有办法创建 PHP 脚本的 .exe 版本。我真的不太担心反编译;我比较担心请人安装和配置PHP。

回答by Mark Baker

Peachpie

桃子派

http://www.peachpie.io

http://www.peachpie.io

https://github.com/iolevel/peachpie

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.

Peachpie 是基于 Roslyn 的 PHP 7 编译器,由 Microsoft 开发,并借鉴了流行的 Phalanger。它允许通过将 PHP 代码编译为纯 MSIL 来在 .NET/.NETCore 中执行 PHP。

Phalanger

法郎格

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

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

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

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

https://github.com/devsense/phalanger

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.

Phalanger 是一个在布拉格查尔斯大学启动并得到微软支持的项目。它将用 PHP 脚本语言编写的源代码编译成 CIL(通用中间语言)字节码。它处理由 .NET Framework 的 JIT 编译器组件完成的编译过程的开始。它不涉及本机代码生成或优化。其目的是将 PHP 脚本编译成 .NET 程序集、包含 CIL 代码和元数据的逻辑单元。

Bambalam

班巴拉姆

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

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!

Bambalam PHP EXE 编译器/嵌入器是一个免费的命令行工具,用于将 PHP 应用程序转换为独立的 Windows .exe 应用程序。生成的 exe 文件是完全独立的,不需要 php dll 等。php 代码使用图尔克 MMCache 编码库进行编码,因此如果您想在保护源代码的同时分发应用程序,它是一个完美的解决方案。该转换器还适用于为窗口化 PHP 应用程序(例如使用 WinBinder 库创建)生成 .exe 文件。它也适用于制作独立的 PHP Socket 服务器/客户端(使用 php_sockets.dll 扩展)。它不是真正的编译器,因为它不会从 PHP 源代码生成本地机器代码,但它可以工作!

ZZEE PHPExe

ZZEE PHPExe

http://www.zzee.com/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.

ZZEE PHPExe 将 PHP、HTML、Javascript、Flash 和其他 Web 文件编译成 Windows GUI exe。您可以使用熟悉的 PHP Web 范例快速开发 Windows GUI 应用程序。您可以对在线和 Windows 应用程序使用相同的代码,只需稍加修改或无需修改。它是一种商业产品。

phc-win

phc-win

http://wiki.swiftlytilting.com/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.

PHP 扩展 bcompiler 用于将 PHP 脚本代码编译成 PHP 字节码。只要加载了 bcompiler 扩展,就可以像任何 php 文件一样包含此字节码。创建完所有字节码文件后,将使用修改后的 Embeder 将所有项目文件打包到程序 exe 中。

Requires

需要

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

ExeOutput

执行输出

http://www.exeoutput.com/

http://www.exeoutput.com/

Commercial

商业的

WinBinder

活页夹

http://winbinder.org/

http://winbinder.org/

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.

WinBinder 是脚本编程语言 PHP 的开源扩展。它允许 PHP 程序员轻松构建本机 Windows 应用程序,以最少的努力产生快速和有益的结果。由于 PHP 的强大功能和灵活性,即使只有几十行的简短脚本也可以生成有用的程序。

PHPDesktop

PHP桌面

https://github.com/cztomczak/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 Desktop 是一个开源项目,由 Czarek Tomczak 于 2012 年创立,旨在提供一种使用 PHP、HTML5、JavaScript 和 SQLite 等 Web 技术开发原生桌面应用程序的方法。这个项目不仅仅是一个 PHP 到 EXE 的编译器,它嵌入了一个网络浏览器(嵌入了 Internet Explorer 或 Chrome)、一个 Mongoose 网络服务器和一个 PHP 解释器。您习惯的开发工作流程保持不变,将现有网站转换为桌面应用程序的步骤基本上是将其复制到“www/”目录。使用 SQLite 数据库是可选的,您可以在应用程序的安装程序中嵌入 mysql/postgresql 数据库。

PHP Nightrain

PHP 夜雨

https://github.com/kjellberg/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!

使用 PHP Nightrain,您将能够在 Windows、Mac 和 Linux 操作系统上部署和运行 HTML、CSS、JavaScript 和 PHP Web 应用程序作为本机桌面应用程序。流行的 PHP 框架(例如 CakePHP、Laravel、Drupal 等)得到很好的支持!

phc-win "fork"

phc-win“叉”

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

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.

phc-win 或多或少的分支版本,它使用与 phc-win 相同的技术,但支持几乎所有现代 PHP 版本。(5.3, 5.4, 5.5, 5.6, etc) 也可以使用Enigma VB将php5ts.dll与你的exe结合起来,以及UPX对其进行压缩。最后,它已将 win32std 和 winbinder 静态编译为 PHP。

EDIT

编辑

Another option is to use

另一种选择是使用

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

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

一个在线编译器,可以为许多不同的平台构建可执行文件,使用多种不同的语言,包括 PHP

TideSDK

潮汐SDK

http://www.tidesdk.org/

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.

TideSDK 实际上是改名后的 Titanium Desktop 项目。Titanium 仍然专注于移动设备,并放弃了桌面版本,该版本被一些开源并命名为 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.

通常,TideSDK 使用 HTML、CSS 和 JS 来呈现应用程序,但它支持 PHP 等脚本语言作为插件模块,以及其他脚本语言,如 Python 和 Ruby。

回答by toster-cx

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.

如果您需要一个“可以正常工作”的解决方案,请将 php 的基本版本与您的项目一起打包在 WinRar SFX 存档中,将其设置为将所有内容提取到一个临时目录并执行php your_script.php.

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

要运行基本脚本,唯一需要的文件是php.exephp5.dll(或php5ts.dll取决于版本)。

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

要添加扩展,请将它们与 php.ini 文件一起打包:

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

回答by 538ROMEO

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

我想大部分是在第1个答案给定的解决方案中,只有一个是工作对我来说,是非商业性的PHP的桌面

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

我只是将我的 php 文件放在www/文件夹中,更改名称.exe并能够将我的 php 作为 exe 运行!

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

还有一个完整的文档、最新的支持、windows 和 linux 兼容性以及可以轻松更改的选项。

回答by dkellner

RapidEXEis exactly for this job:

RapidEXE正好适合这项工作:

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!

它将一个 php 项目转换为一个独立的 exe。我已经受够了所有其他编译器,一个一个地尝试它们,但它们都以一种或另一种方式让我失望。做我的客人,随时欢迎反馈!

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.

旁注:其背后的机制与 WinRAR SFX 方法非常相似;提取引擎,提取源,然后运行。它只是更快,更容易使用。一键编译、压缩、智能解包、自动清理、轻松配置、完全控制php引擎和版本;也可以轻松扩展。

Happy developing!

快乐发展!

回答by srinath madusanka

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

ExeOutput 还可以将 PHP 网站转换为 Windows 应用程序和软件

Turn PHP Websites into Windows Applications and Software

将 PHP 网站转变为 Windows 应用程序和软件

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 制作的应用程序本机运行 PHP 脚本、PHP 应用程序和 PHP 网站,并且不需要 Web 服务器、Web 浏览器或 PHP 分发版。它们是独立的,可在任何装有最新 Windows 版本的计算机上运行。

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.

ExeOutput for PHP 是一个强大的网站编译器,可以处理现代网站上的所有元素:PHP 脚本、JavaScript、HTML、CSS、XML、PDF 文件、Flash、Flash 视频、Silverlight 视频、数据库和图像。将这些元素与 PHP 运行时和 PHP 扩展相结合,ExeOutput for PHP 构建了一个包含完整应用程序的 EXE 文件。

http://www.exeoutput.com/

http://www.exeoutput.com/

回答by M Rostami

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 !!

我在这方面的经验告诉我,这些软件中的大多数都适用于小型项目。
但是大项目呢?例如:Zend Framework 2 和一些类似的东西。
其中一些需要浏览器才能运行,这很难告诉客户“请http://localhost/在浏览器地址栏中输入”!!

I create a simple project to do this : PHPPy

我创建了一个简单的项目来做到这一点: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.

这不是创建用于运行 php 项目的独立可执行文件的完整方法,但可以帮助您做到这一点。
我无法使用 PyInstaller 或 Py2exe 将 python 文件编译为 .exe 文件,希望您可以。
您不需要uniformserver 可执行文件。

回答by zeddex

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!

当前的 PHP Nightrain (4.0.0) 是用 Python 编写的,它使用 wxPython 库。到目前为止,wxPython 一直很好地将 PHP Nightrain 带到今天的位置,但为了将 PHP Nightrain 推向更高的水平,我们将推出 PHP Nightrain 的兄弟,PHPWebkit!

It's an update to PHP Nightrain.

这是对 PHP Nightrain 的更新。

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

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