I have a Slim Application with the following directory structure:
app/
vendor/
www/
config.php
In app/ I have the relevant files of the project, in vendor/ the dependencies managed by composer and in www/ the files accesible by the web server.
So I am thinking to create a Phar file along the lines of:
<?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();
}
So I create that way the phar and then I have:
deploy.php
<?php
require_once 'phar://package.phar/bootstrap.php';
$app->run();
But when accesing /deploy.php I am getting:
[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
Do you think I should be addressing it like this?
Thanks
EDIT:
"Creating the phar in a shared folder of a Vagrant box caused that problem. Once I changed "output" property to a location outside the shared folder the error went away."
source
You should check your php.ini:
phar.require_hash = Off
Or sign your Phar with setSignatureAlgorithm()
Or with Phing:
<pharpackage ... signature="sha512"> ...
Related
I have a smarty project:
in the devidate_server.php:
<?php
include($_SERVER['DOCUMENT_ROOT'] . '/ax/ax_conf/CONSTANTS.php');
include($_SERVER['DOCUMENT_ROOT'] . '/ax/utils/utils.php');
...
there I will get error, but I can not get the error information, because I am develop WHMCS, I don't know the traceback's place. Give me information is the interface is blank.
But if I comment the include($_SERVER['DOCUMENT_ROOT'] . '/ax/utils/utils.php'); there will not get error.
There will shows the interface content.
in the utils.php there is:
<?php
include($_SERVER['DOCUMENT_ROOT'].'/qi_cloud/utils/http_util.php');
include($_SERVER['DOCUMENT_ROOT'].'/qi_cloud/qi_cloud_config/urls.php');
include($_SERVER['DOCUMENT_ROOT'].'/qi_cloud/libs/Requests/library/Requests.php');
Requests::register_autoloader();
function fetch_qicloud_access_tokens($params){
$result = Requests::post('http://localhost:8000/o/token', [
// headers
'Accept'=>'application/json'
], $params, [
// options
'auth' => new Requests_Auth_Basic([QICLOUD_whmcs_pj_client_id, QICLOUD_whmcs_pj_client_secret])
]);
return $result;
}
I don't know why I get include error, who can help me why I comment that line there will be normal?
EDIT-01
I get the error log:
[Wed Jul 18 11:26:52.040872 2018] [proxy_fcgi:error] [pid 29189:tid 139662983087872] [client 118.113.136.133:29440] AH01071: Got error 'PHP message: PHP Warning: require(/usr/local/httpd/htdocs/whmcs/qi_cloud/libs/Requests/library/Requests.php): failed to open stream: No such file or directory in /usr/local/httpd/htdocs/whmcs/qi_cloud/utils/http_util.php on line 9\nPHP message: PHP Warning: require(/usr/local/httpd/htdocs/whmcs/qi_cloud/libs/Requests/library/Requests.php): failed to open stream: No such file or directory in /usr/local/httpd/htdocs/whmcs/qi_cloud/utils/http_util.php on line 9\nPHP message: PHP Fatal error: require(): Failed opening required '/usr/local/httpd/htdocs/whmcs/qi_cloud/libs/Requests/library/Requests.php' (include_path='.:/usr/share/pear:/usr/share/php') in /usr/local/httpd/htdocs/whmcs/qi_cloud/utils/http_util.php on line 9\n', referer: http://www.example.net/clientarea.php
EDIT-2
the qi_cloud/utils/utils.php
<?php
include($_SERVER['DOCUMENT_ROOT'].'/qi_cloud/utils/http_util.php');
include($_SERVER['DOCUMENT_ROOT'].'/qi_cloud/qi_cloud_config/urls.php');
include($_SERVER['DOCUMENT_ROOT'].'/qi_cloud/libs/Requests/library/Requests.php');
Requests::register_autoloader();
...
the urls.php
<?php
require('./CONSTANTS.php');
define('qicloud_oauth_token_url', QICLOUD_BASE_API . 'o/token/'); //
the CONSTANTS.php:
<?php
define('QICLOUD_BASE_API', 'http://103.200.32.76:8000/');
...
You should not rely on documents root.
Do something like:
require_once(DIR . '/relative/path/from/current/directory/file.php');
The require once will stop execute ifbfile is not there since it's require. The once will make sure you don't include the file twice if you pass by this code a second time. You should never include a file that as finction/class/constant declaration more than one. And if you use a proper IDE (like phpstorm) you will have a warning if the file path is invalid. This cannot be achieved with the document root variable.
But I don't know your exact contalext but you should check something like composer.json to handle your dependencies.
P.s. there is 2 underscore before and after the DIR magic constant but formatting on the mobile web version is limited and force bold...
I now upload my project to server in digital ocean,but I get this error in apache2 error log
require_once(/var/www/html/example/v1../include/DbHandler.php): failed
to open stream: No such file or directory
The 2 line that occur error is this,is working well in localhost,but when go to server it having the error above
require_once '../include/DBHandler.php';
require_once '../include/PassHash.php';
My directory is as below,I have to required DBhandler.php which in include folder,and index.php is from v1 folder(the place that require_once calling from).
-include
-DBhandler.php
-PassHash.php
-v1
-index.php
Here is the error log I got
[Fri May 19 12:33:19.621030 2017] [:error] [pid 5236] [client 115.133.247.14:575 22] PHP Warning: require_once(/var/www/html/example/v1../include/ DbHandler.php): failed to open stream: No such file or directory in /var/www/htm l/example/v1/index.php on line 9
What I tried so far
require_once $_SERVER['DOCUMENT_ROOT'].'/include/DBHandler.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/include/PassHash.php';
And this,but none of this solve the problem
require_once __DIR__."/../include/DBHandler.php";
require_once __DIR__."/../include/PassHash.php";
Someone please help!Give me the a right direction,so I can proceed
Your require :
require_once '../include/DbHandler.php';
Your filename:
DBhandler.php
The name is different.
Change your require to:
require_once '../include/DBHandler.php';
May be your file name case: DBHandler intead of DbHandler
Just Remove the symbol / this on staring of file path your problem will be sovled.
require_once(var/www/html/example/v1../include/DbHandler.php): failed to open stream: No such file or directory
I have just installed propel orm and done the setting, but after including the lib/propel.php file, it couldn't find the propel.php file, here is my code
<?php
$projectPath = realpath( dirname( __FILE__ ) . DIRECTORY_SEPARATOR. '..');
$modelPath = $projectPath . "/model/classes";
// Include the man Propel script
require_once $projectPath . '/propel/lib/Propel.php';
// Initialie Propel with the runtime configuration
Propel::init('model/conf/ehm-conf.php');
// Add the generated 'classes' directory to the include path
//set_include_path("model/classes" . PATH_SEPARATOR . get_include_path());
set_include_path($modelPath . PATH_SEPARATOR . get_include_path());
?>
and here is my error output
[client 127.0.0.1] PHP Warning: require_once(C:\Apache Software Foundation\Apache2.2\htdocs/propel/lib/Propel.php) [function.require-once]: failed to open stream: No such file or directory in C:\Apache Software Foundation\Apache2.2\htdocs\ehm\propel_init.php on line 5
[Tue Nov 12 22:54:42 2013] [error] [client 127.0.0.1] PHP Fatal error: require_once() [function.require]: Failed opening required 'C:\Apache Software Foundation\Apache2.2\htdocs/propel/lib/Propel.php' (include_path='.;C:\php\pear') in C:\Apache Software Foundation\Apache2.2\htdocs\ehm\propel_init.php on line 5
Well your error message is clear enough : file "C:\Apache Software Foundation\Apache2.2\htdocs/propel/lib/Propel.php" was not found. So just check in which path is stored propel and set this path in your code.
Test if $projectPath contains the good path
var_dump($projectPath);
You appear to be looking for this:
propel/lib/Propel.php
when I think in fact you want this:
propel/runtime/lib/Propel.php
I'm assuming here you're using the 1.6.x branch, and not the new 2.0.x alpha.
I have looked through all the threads on this forum, before posting this one. None of the solutions were able to solve my issues so I am forced to open a new thread.
I have the below include in my code but it errors out with "failed to open stream: HTTP request failed! " error. I already have this set in php.ini:
allow_url_include = On and
allow_url_fopen = On
but it still fails.
1.Below is the include defined in /test/foo.php which includes the file on the same server under /test/bar.php
<div class="tab-content" style=''>
<div class="tab-pane active" id="my1"><?php include('http://'. $_SERVER['SERVER_NAME'] . ':' .
$_SERVER['SERVER_PORT'] . "/bar.php?env=test1&days=3&start=$start&end=$end");?></div>
</div>
2.Here is the dir structure:
a) /test/foo.php --> this has include to my own server.
b) /test/bar.php
3.Apache document root is pointing to /test like
/var/www/html --> /test
4.echo __DIR__ shows me "/test" so its definitely pointing to the right directory.
5.I have given full permission to this directory in case that's the issue, but no luck.
6.Exact error in apache error log for one of the above includes. It doesn't for any of the above includes. Server Name and port are intentionally removed from below log.
[Sun Jul 07 15:01:47 2013] [error] [client ] PHP Warning: include(http://:/bar.php?env=my1&days=3&start=2013-06-07&end=2013-07-07): failed to open stream: HTTP request failed! in /test/foo.php on line 36
[Sun Jul 07 15:01:47 2013] [error] [client ] PHP Warning: include(): Failed opening 'http://:/bar.php?env=my1&days=3&start=2013-06-07&end=2013-07-07' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /test/foo.php on line 36
if
include('http://'. $_SERVER['SERVER_NAME'] . ':'
. $_SERVER['SERVER_PORT']
. "/bar.php?env=test1&days=3&start=$start&end=$end");
is trying to fetch from
http://:/bar.php?env=my1&days=3&start=2013-06-07&end=2013-07-07
It implies that $_SERVER['SERVER_NAME'] and $_SERVER['SERVER_PORT'] are blank. Are you running this from the command line?
(I assume you know that even with literal values you have created a big security hole in your system, that the resulting script will run massively slower than including the file directly, and that even if the variables were populated it doesn't mean that the routing / DNS on many hosts would allow you to access the code in this way)
I have a group on linux named mygroup. and have a user named apache. apache is the member of mygroup.
i created a sample php file and uploaded on sever
<?php
$structure = '/my_repo/hello';
if (!mkdir($structure, 0, true)) {
die('Failed to create folders...');
}
?>
myrepo dir is at root level and is group is mygroup and owner is root. permissions are 764.
when i accessed my file on http://mydomain.com/sample.php
it gives me the following error
[warn] mod_fcgid: stderr: PHP Warning: dir(/my_repo/hello)
[<a href='function.dir'>function.dir</a>]: failed to open dir:
Permission denied in /var/www/clients/client1/web2/web/sample.php
problem resolved. there was permission issue on server. the code was uploaded through a different user, that was not having permission to myrepo directory.