How should I properly develop laravel app on hosting - php

I'm trying to develop Laravel project on hosting server, but I have a problem with public_html/index.php
Structure of files is:
/laravel/(all laravel files except /public)
/public_html/(all files from laravel /public folder)
File /public_html/index.php (without comments):
<?php
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;
define('LARAVEL_START', microtime(true));
if (file_exists(__DIR__.'/../laravel/storage/framework/maintenance.php')) {
require __DIR__.'/../laravel/storage/framework/maintenance.php';
}
require __DIR__.'/../laravel/vendor/autoload.php';
$app = require_once __DIR__.'/../laravel/bootstrap/app.php';
$kernel = $app->make(Kernel::class);
$response = tap($kernel->handle(
$request = Request::capture()
))->send();
$kernel->terminate($request, $response);
And I'm receiving following problem:
Warning: PHP Startup: failed to open stream: No such file or directory in /index.php on line 34
Fatal error: PHP Startup: Failed opening required '//../laravel/vendor/autoload.php' (include_path='.:/:/usr/local/php74/lib/pear') in /index.php on line 34
I'm accessing website by https://my_domain.com.

Related

Laravel Shared Hosting: /www/../vendor/autoload.php: failed to open stream: No such file or directory

I am trying to host a Laravel application on shared hosting. The default folder is '/www' and can't be changed, there is no public_html folder. However when surfing to the website I get an Error 500 and in the logs I get:
Got error 'PHP message: PHP Warning: require(/absolutepath/www/../vendor/autoload.php): failed to open stream: No such file or directory in /absolutepath/www/index.php on line 34PHP message: PHP Fatal error: require(): Failed opening required '/absolutepath/www/../vendor/autoload.php' (include_path='.') in /absolutepath/www/index.php on line 34'
Everything works locally and I have followed a guide on how to setup a Laravel project for Shared Hosting. I did the following:
Move index.php and .htaccess to the root of the project
Changed require __DIR__.'/../vendor/autoload.php'; to require __DIR__.'/vendor/autoload.php'; in index.php
Changed $app = require_once __DIR__.'/../bootstrap/app.php'; to$app = require_once __DIR__.'/bootstrap/app.php'; in index.php
Changed require_once __DIR__.'/public/index.php'; to require_once __DIR__.'/index.php'; in server.php
My file structure looks as follows:
File structure
I have already tried:
composer update & composer dump-autoload
composer install
php artisan key:generate
Also:
php artisan route:cache
php artisan view:clear
php artisan config:cache

PHP Startup: Failed opening index.php after composer install/update

I've uploaded my webapp (made with Laravel 5.8). I run composer install via SSH so vendor is created, but when opening website I get:
Warning: PHP Startup: failed to open stream: No such file or directory in /index.php on line 24
Fatal error: PHP Startup: Failed opening required '//../vendor/autoload.php' (include_path='.:/:/usr/local/php72/lib/pear') in /index.php on line 24
When I change server's PHP default version, for example to 7.1, in second line path changes to: usr/local/php71/lib/pear .
On localhost, and on different with the very same vendor everything works fine.
So I assume something is wrong with php's path?
I've already run composer update or dumb-autoload with no success.
E1:
define('LARAVEL_START', microtime(true));
require __DIR__.'/../vendor/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
try to run following command in your application
sudo chmod -R 777 bootstrap/cache storage

Project running on local server (WAMP) but on live server Error: failed to open stream: No such file or directory

I know, that's stupid, but I can't solve the problem with my project.
I wrote project on WAMP firstly and all works.
After, I try to migrate on live server, and find a problem - server don't require my files.
Project structure is:
application
core
Controller.php
Model.php
View.php
Route.php
models
views
controllers
included
config.php
app.php
index.php
when I try to run it, server return error:
Warning: require_once(core/model.php): failed to open stream: No such
file or directory in /home/u224052355/public_html/application/app.php
on line 4
This is the app.php code:
session_start();
require_once 'config.php';
require_once 'core/model.php';
require_once 'core/view.php';
require_once 'core/controller.php';
require_once 'core/route.php';
spl_autoload_register(function($class_name){
include 'included/' . $class_name . '.php';
});
Route::start();
When I try solve this by adding __DIR__ to require_once I gave this message:
Warning:
require_once(/home/u224052355/public_html/application/core/model.php):
failed to open stream: No such file or directory in
/home/u224052355/public_html/application/app.php on line 4
Fatal error: require_once(): Failed opening required
'/home/u224052355/public_html/application/core/model.php'
(include_path='.:/opt/php-5.5/pear') in
/home/u224052355/public_html/application/app.php on line 4
Using the $_SERVER['DOCUMENT_ROOT'] and etc. - same result.
How can I solve this problem?

Missing Classes in Authorize.net PHP SDK

I'm trying to generate a custom report from Authorize.net using their API but cannot get the SDK to load without errors.
I created a post on the developer board HERE as well as sending an email request to their support team. The issue was supposed to have been fixed with a temporary patch HERE. But the errors persist.
Does anyone have any ideas as to how to work around this issue?
My Code:
<?php
error_reporting(-1); ini_set('display_errors', 'On');
date_default_timezone_set('UTC');
/* autoload through composer */
//require 'vendor/autoload.php';
/* autoload through git clone */
//require 'git/sdk-php/autoload.php';
/* autoload through .zip download */
require 'download/sdk-php-master/autoload.php';
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
function getSettledBatchList($startDate, $endDate) {
$api_id = "MY_API_ID";
$account_key = "MY_ACCOUNT_KEY";
$start_dt = new DateTime($startDate);
$end_dt = new DateTime($endDate);
$merchAuth = new AnetAPI\MerchantAuthenticationType();
$merchAuth->setName($api_id);
$merchAuth->setTransactionKey($account_key);
$request = new AnetAPI\GetSettledBatchListRequest();
$request->setMerchantAuthentication($merchAuth);
$request->setIncludeStatistics(true);
$request->setFirstSettlementDate($start_dt);
$request->setLastSettlementDate($end_dt);
$controller = new AnetController\GetSettledBatchListController($request);
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
if(($response != null) && ($response->getMessages()->getResultCode() == "Ok")){
/* Do Nothing For Now */
}else{
$errorMessages = $response->getMessages()->getMessage();
echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
}
return $response;
}
$api_response = getSettledBatchList('2016-05-01T00:00:00Z', '2016-05-10T00:00:00Z');
var_dump($api_response);
?>
The Errors:
/* Loaded with git clone https://github.com/AuthorizeNet/sdk-php.git */
Warning: include(sdk-php/vendor/jms/serializer/src/JMS/Serializer/Annotation/Type.php): failed to open stream: No such file or directory in sdk-php/autoload.php on line 16
Warning: include(): Failed opening '/sdk-php/vendor/jms/serializer/src/JMS/Serializer/Annotation/Type.php' for inclusion (include_path='.:') in sdk-php/autoload.php on line 16
Fatal error: Class 'JMS\Serializer\Annotation\Type' not found in /sdk-php/lib/net/authorize/util/SensitiveDataConfigType.php on line 6
/* Loaded by downloading .zip from github page */
Warning: include(/sdk-php-master/vendor/jms/serializer/src/JMS/Serializer/Annotation/Type.php): failed to open stream: No such file or directory in /sdk-php-master/autoload.php on line 16
Warning: include(): Failed opening '/sdk-php-master/vendor/jms/serializer/src/JMS/Serializer/Annotation/Type.php' for inclusion (include_path='.:') in /sdk-php-master/autoload.php on line 16
Fatal error: Class 'JMS\Serializer\Annotation\Type' not found in /sdk-php-master/lib/net/authorize/util/SensitiveDataConfigType.php on line 6
/* Loaded with Composer using recommended composer.json */
Fatal error: Class 'Goetas\Xsd\XsdToPhp\Jms\Handler\BaseTypesHandler' not found in /vendor/authorizenet/authorizenet/lib/net/authorize/api/controller/base/ApiOperationBase.php on line 82
I'm open to all ideas at this point. Thanks!
Simple mistake. The patch was to the composer.json file that updated the required-dev version of Goetas. Did not realize I needed to update my composer.json before running composer update.
Updated composer.json Language
I just had the same issue, and I realized that the problem is that I was using require on the wrong autoload.php and I think you're doing that too.
You probably have figured it by now but in case someone else has this problem the solution is this:
You have to load/require the autoload.php that's inside the vendor folder, not the one inside the sdk (root) folder.

Adding vendor directory to heroku application

I have created and deployed a php app on heroku, but loading vendor is not working from config.php file. Checkout following...
config.php
require_once __DIR__ . '/vendor/autoload.php';
index.php
include('config/config.php');
Directory structure
config
--config.php
index.php
vendor
Its working on localhost but when i try to run after deploying to heroku, i get following error...
Warning: require_once(/app/config/vendor/autoload.php): failed to open stream: No such file or directory in /app/config/config.php on line 10 Fatal error: require_once(): Failed opening required '/app/config/vendor/autoload.php' (include_path='.:/app/.heroku/php/lib/php') in /app/config/config.php on line 10
Please help, i have tried google for an answer, but no luck. thanks
There is no way that works on localhost. __DIR__ points to the directory the current file is in, so in your case, that's config/, meaning you're including config/vendor/autoload.php.
You want a relative path instead:
require_once __DIR__ . '/../vendor/autoload.php';

Categories