vendor autoload file cannot be loaded because of the public folder in codeigniter 4 - composer-php

I already installed GuzzleHttp using composer but the require 'vendor/autoload.php'; returns an error. I've tried using FCPATH . 'vendor/autoload.php'; and it returns C:\xampp\htdocs\local\public\vendor\autoload.php". I think the problem is the public folder in the url. When I tried it without the public folder it works.

Notes:
FCPATH
The path to the directory that holds the front controller.
ROOTPATH
The path to the project root directory. Just above APPPATH.
Solution:
Instead of:❌
require FCPATH . 'vendor/autoload.php';
Use this:✅
require_once ROOTPATH . 'vendor/autoload.php';
You could alternatively, use COMPOSER_PATH:✅
I.e:
require_once COMPOSER_PATH;
Composer Path
The path that Composer's autoload file is expected to
live. By default, the vendor folder is in the Root directory, but you
can customize that here.

Related

Move Laravel project to subdomain where Wordpress is already installed

I created a subdomain and move whole project except public folder. Create mysql database and upload my database there. Now, in public_html folder I already have wp files so I created new folder there which I named same as subdomain. So, subdomain is something.something.com and now I have path public_html/something/public where I upload all from public folder. I try to rename files in index.php public foder:
require __DIR__ . '/../bootstrap/autoload.php';
$app = require_once __DIR__ . '/../bootstrap/app.php';
to this:
require __DIR__ . '/../something/public/bootstrap/autoload.php';
$app = require_once __DIR__ . '/../something/public/bootstrap/app.php';
but still I get this:
And I edit .env file to find database. Where am I wrong?
Solved! It was PHP version mismatched. In local it was 7.1 but on server was 5. When I update on server it worked.

Laravel Project Directory Structure

i have developed a project with default directory structure.
But on production, i don't want public in URL.
What can be done.?
I tried changing the app path, but still not working.
Just copy index.php and .htaccess file from public directory and paste it in project root folter.
Then change bootstrap path in project root folder index.php file like below,
require __DIR__.'/bootstrap/autoload.php';
and
$app = require_once __DIR__.'/bootstrap/app.php';

Can't use public_path() in a helper file Laravel 5.4

I have a helper.php file in app/Helpers directory. I included that file in composer.json:
...
"files": [
"app/Helpers/helpers.php"
]
...
Helper works fine but I can't use public_path() method there. I need to include another file (please don't ask me why because it's old code that I don't need to rewrite). So I have the following:
require_once public_path() . '/appadmin/bootstrap.php';
I know that by default Laravel looks in /public/ folder but I faced with a problem. If I need to perform composer update I have to use public/appadmin/bootstrap.php path in helper.php, but after performing I have to change that path to /appadmin/bootstrap.php for correct work. That's why I decide to use public_path() method to receive correct path for both cases. And if I use it I'm getting an error:
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postUpdate
Script Illuminate\Foundation\ComposerScripts::postUpdate handling
the post-update-cmd event terminated with an exception
[ReflectionException]
Class path.public does not exist
Thank's in advance!
Have you tried updating your app to the current revision?
There are some files in the framework itself who need to be updated.
Check out the config files, the bootstrap files, server.php and the start files here https://github.com/laravel/laravel/tree/develop.
You could open index.php (in your public directory) and change:
$app = require_once __DIR__.'/../bootstrap/app.php';
// set the public path to this directory
$app->bind('path.public', function() {
return __DIR__;
});
Now you dont need to change your public path when your public directory has changed.

How to host laravel web application in Shared Hosting

I have developed a web application using Laravel 5.8, now I want to host that to a shared web server. What will be the folder structure and exact what to configure.
I have created a folder named laravel and kept all the project folders into that laravel folder, except project's public folder. I kept all the files and folders of public folder into public_html folder.
I have configured the index.php file of public_html folder as below.
a. require __DIR__.'/../bootstrap/autoload.php';
to,
require __DIR__.'/../laravel/bootstrap/autoload.php';
b. $app = require_once __DIR__.'/../bootstrap/app.php';
to,
$app = require_once __DIR__.'/../laravel/bootstrap/app.php';
$app->bind('path.public', function() {
return __DIR__;
});
*** I have solved the problem myself.
Step 1: I have found and installed laravel app into public_html folder from the cPanel
Step 2: Then I have moved everything into a folder named laravel except public folder into a new folder outside public_html folder
Step 3: Then I have moved everything from public folder into public_html folder
Step 4: Later I have followed the 2nd step above
Step 5: Then I have changed folder permission for storage folder and it works fine.
Step 6: Finally I have kept all other files and folders of the app developed in my local server into this newly installed app directories
Laravel default structure always better. its depend on your hosting place.
if your hosting place support for laravel framework then use default structure automatically public word redirect to project path.
Or if you need to ignore Public word in your Url
Copy all files form files put in to one folder ex:psl
copy public folder paste in to folder directory
change the index.php file in two place
require __DIR__.'/psl/bootstrap/autoload.php';
$app = require_once __DIR__.'/psl/bootstrap/app.php';
I had similar errors on my deploy and then I noticed that the path is kind of wrong:
require __DIR__.'/../laravel/bootstrap/autoload.php';
the leading / changes to the root of the drive, and then the .. are not doing anything. Removing that leading / on both require __DIR__ fixed it for me.
if you can not provide a link to the web root of the shared folder!
All except the Public folder to move to a higher level, such as a folder laravel - http://prntscr.com/bryvu7
(Maybe on hosting your folder - public. not a folder public_html)
Change file publi_html/index.php
line
require __DIR__.'/../bootstrap/autoload.php';
to
require __DIR__.'/../laravel/bootstrap/autoload.php';
And line
$app = require_once __DIR__.'/../bootstrap/app.php';
to
$app = require_once __DIR__.'/../laravel/bootstrap/app.php';
$app->bind('path.public', function() {
return __DIR__;
});
Change file laravel/server.php
line
require_once __DIR__.'/public/index.php';
to
require_once __DIR__.'/index.php';

Laravel url without public folder

hi i am using wampserver for my project
and my project is in folder sss
so i must type this Url localhost\sss\public
and want to have this
localhost\sss\
to show my index page
Copy the public folder contents outside the public folder and open index.php which you copied outside the folder, than change the:
require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/start.php';
to
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/start.php';
and you can access directly.

Resources