通过引用this此链接,我已经成功打包了我的简单PHP应用程序。现在我想打包(创建.phar文件)我的整个Yii2 Advance应用程序,将其部署在服务器上。
我已经按照上面链接中给出的所有步骤进行了操作,但是当我运行它时给出了这个错误:
Warning: require(phar://D:/www/myphartest.phar/../../vendor/autoload.php): failed to open stream: phar error: "vendor/autoload.php" is not a file in phar "D:/www/myphartest.phar" in phar://D:/www/myphartest.phar/index.php on line 5
Fatal error: require(): Failed opening required 'phar://D:/www/myphartest.phar/../../vendor/autoload.php' (include_path='phar://D:\www\myphartest.phar;.;C:\php\pear') in phar://D:/www/myphartest.phar/index.php on line 5
以下是我的结构:
d:\ WWW \ myphartest
build(目录)
src(目录)
create-phar.php(file)
这是我的config.ini(在build& www dir中)
[database]
host=localhost
db=mydb
user=root
pass=root
我在src目录中添加了index.php
<?php
require_once "phar://myphartest.phar/backend/web";
$config = parse_ini_file("config.ini");
AppManager::run($config);
run.php(在www内)
<?php
require "myphartest.phar";
任何帮助都将不胜感激。
答案 0 :(得分:2)
我建议使用box来创建PHAR。它只是工作:)并且如果你愿意,还有其他功能。
它可以用于3个简单的步骤:
box.phar
,请参阅box readme box.json
,请参阅下面的示例php box.phar build --verbose
(详细信息,查看进入phar的文件列表)示例配置:
{
"alias": "main.phar",
"chmod": "0755",
"directories": [
"src"
],
"files": [
"README.md",
"LICENSE"
],
"finder": [
{
"name": "*.php",
"exclude": [
"tests",
"Tests"
],
"in": "vendor"
}
],
"git-version": "package_version",
"main": "bin/main.php",
"output": "main.phar",
"stub": true
}
你可以扔掉大部分选项。只需离开main
,output
以及files
,directories
或finder
中的一个,该框就知道您的内部信息。
我已经尝试过基于Yii2的控制台程序 - 工作正常!