将整个 Slim 应用程序打包到 Phar 文件中时出错
Error Packaging into a Phar file an entire Slim Application
我有一个具有以下目录结构的 Slim 应用程序:
app/
vendor/
www/
config.php
在 app/ 中有项目的相关文件,在 vendor/ 中有由 composer 管理的依赖项,在 www/ 中有 Web 服务器可访问的文件。
所以我想按照以下行创建一个 Phar 文件:
<?php
$full_path = '/home/.../forms/';
$package_name = 'www/package.phar';
try {
$phar = new Phar($full_path . $package_name,
FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME, $full_path . $package_name);
$phar->startBuffering();
$phar->addFile($full_path . 'www/index.php');
$phar->addFile($full_path . 'www/bootstrap.php');
$phar->addFile($full_path . 'www/session_start.php');
// Grab config
$phar->addFile($full_path . 'config.php');
$phar->buildFromIterator(new RecursiveIteratorIterator (new RecursiveDirectoryIterator('../app', FilesystemIterator::SKIP_DOTS)),'../app');
$phar->buildFromIterator(new RecursiveIteratorIterator (new RecursiveDirectoryIterator('../vendor', FilesystemIterator::SKIP_DOTS)),'../vendor');
$phar->setDefaultStub('bootstrap.php', 'bootstrap.php');
$phar->stopBuffering();
echo "Phar created.";
} catch (Exception $e) {
// handle errors here
echo $e->getMessage();
}
所以我用这种方式创建了 phar 然后我有:
deploy.php
<?php
require_once 'phar://package.phar/bootstrap.php';
$app->run();
但是当访问 /deploy.php 我得到:
[Fri May 15 20:07:02 2015] [error] [client 10.0.2.2] PHP Warning:
require_once(phar://package.phar/bootstrap.php) [function.require-once]: failed to
open stream: Cannot open archive
"/vagrant/www/package.phar", invalid alias in
/vagrant/www/deploy.php on line 3 [Fri May 15 20:07:02 2015] [error]
[client 10.0.2.2] PHP Fatal error: require_once() [function.require]: Failed opening required
'phar://package.phar/bootstrap.php'
(include_path='.:/usr/share/php:/usr/share/pear') in
/vagrant/www/deploy.php on line 3
你觉得我应该这样说吗?
谢谢
编辑:
"Creating the phar in a shared folder of a Vagrant box caused that problem. Once I changed "输出“属性到共享文件夹之外的位置错误消失了。”
source
你应该检查你的php.ini:
phar.require_hash = Off
签署您的 Phar
或使用 Phing:
<pharpackage ... signature="sha512"> ...
我有一个具有以下目录结构的 Slim 应用程序:
app/
vendor/
www/
config.php
在 app/ 中有项目的相关文件,在 vendor/ 中有由 composer 管理的依赖项,在 www/ 中有 Web 服务器可访问的文件。
所以我想按照以下行创建一个 Phar 文件:
<?php
$full_path = '/home/.../forms/';
$package_name = 'www/package.phar';
try {
$phar = new Phar($full_path . $package_name,
FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME, $full_path . $package_name);
$phar->startBuffering();
$phar->addFile($full_path . 'www/index.php');
$phar->addFile($full_path . 'www/bootstrap.php');
$phar->addFile($full_path . 'www/session_start.php');
// Grab config
$phar->addFile($full_path . 'config.php');
$phar->buildFromIterator(new RecursiveIteratorIterator (new RecursiveDirectoryIterator('../app', FilesystemIterator::SKIP_DOTS)),'../app');
$phar->buildFromIterator(new RecursiveIteratorIterator (new RecursiveDirectoryIterator('../vendor', FilesystemIterator::SKIP_DOTS)),'../vendor');
$phar->setDefaultStub('bootstrap.php', 'bootstrap.php');
$phar->stopBuffering();
echo "Phar created.";
} catch (Exception $e) {
// handle errors here
echo $e->getMessage();
}
所以我用这种方式创建了 phar 然后我有:
deploy.php
<?php
require_once 'phar://package.phar/bootstrap.php';
$app->run();
但是当访问 /deploy.php 我得到:
[Fri May 15 20:07:02 2015] [error] [client 10.0.2.2] PHP Warning: require_once(phar://package.phar/bootstrap.php) [function.require-once]: failed to open stream: Cannot open archive "/vagrant/www/package.phar", invalid alias in /vagrant/www/deploy.php on line 3 [Fri May 15 20:07:02 2015] [error] [client 10.0.2.2] PHP Fatal error: require_once() [function.require]: Failed opening required 'phar://package.phar/bootstrap.php' (include_path='.:/usr/share/php:/usr/share/pear') in /vagrant/www/deploy.php on line 3
你觉得我应该这样说吗?
谢谢
编辑:
"Creating the phar in a shared folder of a Vagrant box caused that problem. Once I changed "输出“属性到共享文件夹之外的位置错误消失了。” source
你应该检查你的php.ini:
phar.require_hash = Off
或使用 Phing:
<pharpackage ... signature="sha512"> ...