I SSH'd to my server and installed Composer and Ratchet. http://socketo.me/docs/install claims all I need to do now is include "require DIR . '/vendor/autoload.php';" at the top of my php file. My page now gets a "failed to open stream: No such file or directory" error.
I've tried various forms of the directory, like "../vendor/autoload.php", but I keep getting the same error. The error reports that it is trying to find it in "/var/www/html/mo/myDomainName.com".
Should I be able to find a vendor folder in my home directory via ftp? I am confused where I'm supposed to be pointing to after my install.
typically vendor folder for composer is located above /public_html, so if your script is in public_html folder, you'll have to reference this as up one level
example
require_once '../vendor/autoload.php';
Just add base_path(). You will get the actual path of autoload.php C:\xampp\htdocs\ProjectFolder\vendor\autoload.php
require base_path().'/vendor/autoload.php';
Related
I want to include a file that is in a parent folder in my php code using:
include('../defines.php');
However when I deploy to heroku from CLI and run my php file it gives me this error.
PHP Warning: include(): Failed opening '../defines.php' for inclusion (include_path='.:/app/.heroku/php/lib/php') in /app/workers/test.php on line 2
If I run locally from my installed Wamp 3.1.4 server it run fines without issues.
I can make it work if I remove the `../? from the path. But that seems wrong.
Another way I've found on github is doing
include __DIR__ . '/../defines.php';
But i think doing it that way would be using absolute, not relative path.
Is there something i'm missing?
<?php
include('../defines.php');
?>
Folder tree:
www/
defines.php
workers/
test.php
It's depending how you classified your folder.
Maybe you can try this :
require("/../yourFolder.php");
I have a PHP that runs fine on localhost but throws error on the cloud server. On the localhost, the script runs and also fetched the data from datastore.
This is the line thats causing the problem:
require __DIR__ . '/../../vendor/autoload.php';
// this is the line5 of datastore.php
I deploy it using this code:
gcloud app deploy --promote --stop-previous-version app.yaml
After deploying to the Google AppEngine, i get this:
Warning:
require(/base/data/home/apps/myproject/projectID/dialpad_research/api/../../vendor/autoload.php):
failed to open stream: No such file or directory in
/base/data/home/apps/myproject/projectID/dialpad_research/api/datastore.php
on line 5 Fatal error: require(): Failed opening required
'/base/data/home/apps/myproject/projectID/dialpad_research/api/../../vendor/autoload.php'
(include_path='.;/base/data/home/apps/myproject/projectID/;/base/alloc/tmpfs/dynamic_runtimes/php55_dynamic/ef537742f8701211/sdk')
in
/base/data/home/apps/myproject/projectID/dialpad_research/api/datastore.php
on line 5
This file is required inside another PHP file too.
But even if I try to access this file directly, I still get the same error.
Should I be adding the require code differently?
The problem was that the vendor folder was not getting uploaded.
.gcloudignore file was preventing it.
After correcting it, this error is gone.
Thanks everyone from trying.
Your require code should look like this. Your vendor folder should normally be at root directory level of your code on the same level as your app.yaml. In which case, your require should look like this:
require 'vendor/autoload.php';
Also, sanity check and make sure the file is actually there in the vendor folder.
I have searched the forums already, but none of the solutions have seemed to help me.
Basically I have just installed and created a package using composer. I need to autoload the classes, sounds pretty standard.
I followed all the instructions, and have added this line of code to my script:
require_once 'vendor/autoload.php';
The vendor folder is located in the root folder of my server, here:
/root/vendor/autoload.php
So, I added
:/root
To my PHP ini file so that PHP searches in the root folder when looking for includes. I thought that should work but it's not :(
My PHP ini file now looks like this:
.:/usr/lib/php:/usr/local/lib/php:/root
The error message I am getting is this:
[14-Jul-2014 16:46:29 Europe/London] PHP Fatal error: require_once(): Failed opening required 'vendor/autoload.php' (include_path='.:/usr/lib/php:/usr/local/lib/php:/root') in /home/owned/public_html/trythis/ow_plugins/oftokbox/bol/service.php on line 38
Any ideas?
You implicitly state you are using Composer for a project. By doing so you must have a composer.json file somewhere. And Composer will create a vendor folder directly in the folder containing this file.
So if you also have a file index.php in the folder containing the composer.json, to include the autoloader you would use require 'vendor/autoload.php';.
If however you follow some security guidelines and have a dedicated folder containing public files, then the file would for example be called public/index.php, and for this file to reach the autoloader, the relative path would be require '../vendor/autoload.php';.
Composer cannot give a one-instructions-fits-all direction because it depends on which folder structure you have. But including the composer autoloader is just the same task as including any other file with a relative path.
I am new to PHP and trying to figure out issues with autoload.php. I downloaded php-amqplib package and it's dependencies and trying to test PHP page. I am getting failed to open stream: No such file or directory 'D:\inetpub\wwwroot\test\vendor\videlalvaro\php-amqplib\demo/../vendor/autoload.php' (include_path='.;C:\php\pear'). I am using 5.3.13 and it's installed in 'D:\PHP5313' folder. There is no 'pear' folder. Could you please let me know if I am missing something? Thanks for any suggestions.
autoload.php
require_once __DIR__ . '/composer' . '/autoload_real.php';
return ComposerAutoloaderInit5e74aaf68e13rfe5f321c5a586eb96f22::getLoader();
Your path to the required file it not correct (autoload.php).
__DIR__ is the actual directory where the file is located. I think you have to go back to come to the folder where the autoload.php is located.
D:\inetpub\wwwroot\test\vendor\videlalvaro\php-amqplib\demo/../vendor/autoload.php'
I think you have to go back to the vendor folder in your case where normally the autoload file is located. I think its 3 folders higher.
I am trying to write a file to a sub folder of the directory my cron script is in using file_ put_ contents. However, I keep getting a warning "failed to open stream: No such file or directory."
I have this directory structure:
httpdocs/scripts/fileDirectory
The cron script lives in the scripts folder. I call it with the cron command:
php httpdocs/scripts/cron_writeFile.php
In the cron_writeFile file, I first tried:
file_put_contents('fileDirectory/', $fileName, $fileContents);
which works when I load the page in a browser, but not when the cron executes.
When I require_once a file in a cron, I have to put the 'absolute' path to it:
require_once('httpdocs/scripts/requiredFile.php');
So, I tried that:
file_put_contents('httpdocs/scripts/fileDirectory/', $fileName, $fileContents);
No luck. I'm pretty sure it's getting to the right folder because the warning is:
"Warning: file_ put_ contents(httpdocs/scripts/fileDirectory/4.txt):
failed to open stream: No such file or directory in
/var/www/vhosts/myDomain.com/httpdocs/scripts/cron_writeFile.php
on line 93"
The both directories have write permissions.
I am using a VPS running (I know it sucks and I need to upgrade, but I don't have the authority)
Parallels Plesk Panel version 9.2.1
with PHP 5.0.4
The file does not exist and I need a new file each time the script runs.
I am not sure if there is a certain way to define the file path or some other thing I am missing.
Thanks for your help!
What if you use dirname(__FILE__) (see) to get an absolute path to your "fileDirectory" directory ?
Something like this in your script, I guess, if your fileDirectory is a child of the directory where your file resides :
file_put_contents(dirname(__FILE__) . '/fileDirectory/' . $fileName, $fileContents);
That way, you don't depend on relative path, which can be wrong if your script is not launched from the "right" directory.