通过引用这个链接,我已经成功地打包了我的简单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
构建(目录)
- config.ini
- myphartest.phar
src(目录)
- [under src => my yii2 advanced applications files and folders]
create-phar.php(文件)
这是我的config.ini(内部构建&www dir)
[database]
host=localhost
db=mydb
user=root
pass=root
我在src dir
中添加了index。php<?php
require_once "phar://myphartest.phar/backend/web";
$config = parse_ini_file("config.ini");
AppManager::run($config);
run.php (inside www)
<?php
require "myphartest.phar";
我建议使用box来创建PHAR。它只是工作:),如果你喜欢,还有其他功能。
它可以通过3个简单的步骤使用:
- 下载
box.phar
,参见框自述 - 创建配置文件
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的控制台程序-工作得很好!