如何打包 PHP 应用程序以便它们可以在任何用户计算机上运行?
有没有一种方法可以像桌面应用程序一样分发 PHP 程序,这样即使应用程序的用户在 PC 上没有设置本地服务器环境,应用程序仍然可以运行?
我在想,如果有某种类型的便携式服务器环境程序包含 PHP/Apache,那么我们可以创建一个批处理文件,单击该文件时将在便携式程序中启动 apache 并在用户的默认浏览器中启动 PHP 应用程序。这样 PHP 应用程序就可以像桌面应用程序一样分发。
但问题是,是否有这样一个可移植的服务器环境程序可以用于此目的?
Is there a way to distribute a PHP program like a desktop app, so that even if the user of the app doesn't have a local server environment setup on there PCs, the app will still work?
I was thinking, if there was some type of portable server environment program which includes PHP/Apache, then we could create a batch file which when clicked would start up apache in the portable program and launch the PHP app in the user's default browser. That way PHP apps could be distributed like desktop apps.
But the question is, is there such a portable server environment program that can be used for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,如果您在 google 上搜索
XAMPP portable
,您可以找到多个版本的完全可移植、功能齐全的 xampp 服务器。您必须确保它包含您需要的所有安全设置和扩展。您的用户启动的文件应该是 .html 文件,以确保它在您的浏览器中打开。由于您需要将用户指向他自己的本地主机来运行您的应用程序(否则 PHP 将不会被执行,他会看到一个纯 html 文件),因此您必须创建一个重定向,可能使用 javascript 或一个简单的“单击此处开始”链接。
Yes, if you google for
XAMPP portable
, you can find several versions of fully portable, fully functioning xampp servers for the go. You would have to make sure it contains all the security settings and extensions you need.The file your user launches should be an .html file to be sure it opens in your browser. As you need to point the user to his own localhost to run your app (otherwise PHP won't be executed and he'd see a plain html file), you'd have to create a redirect, possibly using javascript or a simple "click here to start" link.
XAMPP 只提供了解决方案的一半:
除了 XAMPP 之外,您还可以使用 Phar 文件,这些文件使您能够将 PHP 应用程序打包为一个单元以进行安装和/或部署。
您可以配置一个单独的 php 文件,该文件将处理任何数据库创建和可设置为首次运行的初始配置。
如需有用的入门指南,请考虑以下链接:
http://phpmaster.com/packaging-your-apps-with-phar/
最后,如果您想让用户无缝(更容易),请考虑编写一个批处理脚本来处理运行一些所需的任务(例如启动 apache 和 mysql 并运行 run.php)。请注意使用相对目录而不是绝对目录以使脚本开发更容易。
The XAMPP only provides half of the solution:
In addition to the XAMPP you can use Phar files that give you the ability to package your PHP applications as a unit for installation and/or deployment.
You can configure a separate php file which will handle any database creations and initial configuration which can be set to run on the first time.
For a helpful start guide consider the following link:
http://phpmaster.com/packaging-your-apps-with-phar/
Finally if you want to make it seamless (easier) to the user, consider writing a Batch script which will handle running some of the task required (Such as starting apache and mysql and running run.php). Take note of using relative rather than absolute directories to make script development easier.