Fatal error: require(): Failed opening required "required directory" - laravel

I am uploading laravel project to cpanel ,I have set the path in index.php
but it return the fatel error
error
Fatal error: require(): Failed opening required '/home/customer/www/easy-websites.online/public_html/../quickquiz/vendor/autoload.php' (include_path='.:/usr/local/php73/pear') in /home/customer/www/easy-websites.online/public_html/index.php on line 24
I have not seperate directory for quickapp but it show in error
I am uploading all my project files and folder in public_html
index.php
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
.htacess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
file structure
publichtml{
app
bootstrap
etc..
index.php
.htaccess
vendor { autoload.php}
}
index.php and .htaccess under public_html and autoload.php under vendor folder

Deploy laravel app on Cpanel requires some different steps and can be handled by different ways for me this is the best way
we can summarize in
uploading files inside laravel public folder to Cpanel public_html
create another directory in Cpanel /home that will contain the rest of your laravel app (at the same level of Public_html)
upload the rest of the files exclude public to the new directory you just created
Open the index.php file on public_html/index.php and Replace the require path to be ./../YOUR_DIRECTORY_NAME/vendor/autoload.php
same for bootstrap in the same file replace app.php require path to the correct path by adding Your DIRECTORY_NAME
you may also need to change the import path of index.php in your DIRECTORY_NAME/server.php file
For more information and a good explanation with images you can follow this tutorial Deploy Laravel Project on Shared Hosting CPanel

Related

how to access website from a sub folder inside the root folder?

I am about to deploy a laravel project. I uploaded all the files and the website is working fine but the only problem is when i try to access my website i.e for example if i try to write mywebsitename.com in the url then public directory is shown which is because i have symblinked my laravel's public folder to the public_html folder. I don't have any idea about how to edit the .htaccess file in order to load the website with mywebsitename.com and not mywebsitename.com/public. My htacess files code is
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
my file directory structure is shown in this image
please help me
I am guessing it is an apache server. If yes;
Ensure your domain mywebsitename.com points to the public_html
Add a .htaccess file in your root directory(public_html) and paste this in
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
I found a solution to this question.
1.Copy all the laravel files inside the public_html folder including the .htaccess file and the index.php file which is suppose to be inside the public folder(keep both the files inside the public folder).
2.Then link your storage to the public folder using SSH, for that open your SSH enter id and password and change directory using "cd domains/yourdomainname.com/public_html"
then give the php artisan command i.e "php artisan storage:link"
(note:- after changing the directory you can give all the php artisan commands like migrate and config:cache or clear:cache as you wish.
3.Now after the all the necessary commands are given you can access your fully functional website including the image display function if you type yourdomainname.com/public on the URL but if you type just your domain name then all the laravel files will appear on the browser to avoid this and to to jump inside the public folder directly create one more .htaccess file outside the public folder but inside the
public_html folder the copy the below given code and then if you just your domain name on the URL then your website will be directly displayed
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteRule ^ public [L]
You can use it with RewriteBase directive,
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteBase /public_html/ # or '/' only depends on your vhost config
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I'm not familiar with apache server but the problem should be in the default index file.
For long terms considered, I advise you to use nginx or openresty, it's easier to configurate.

How to upload the laravel project on cpanel?

How to upload larval project on cpanel using only.Htaccess file. I saw already more of the example, but not worked properly. This is throwing the error is This page isn’t working. I put my project inside http://www.domainname.com/laravelproject. Inside this we change the index.php file in the public folder.
file is this-
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
public/index.php
require __DIR__.'/../filename/vendor/autoload.php';
$app = require_once __DIR__.'/../filename/bootstrap/app.php';
from my experience so far, when you are done with coding your project
create a folder outside of public_html. you can call it maybe "project"
copy all your project files and upload to the project folder created.
open the public folder in your laravel project and copy all the files including the .htaccess and index.php files to the public_html folder.
then open index.php files and change the following pointing to the project folder you created.
define('LARAVEL_START', microtime(true));
require DIR.'/../project/vendor/autoload.php';
$app = require_once DIR.'/../project/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);
in your case, http://www.domainname.com/laravelproject
1. create a folder name "project" outside of the public_html and place all the laravel files inside it.
2. also create a folder name laravelproject inside public_html/laravelproject.
3. then open the laravel public folder inside "project" folder and copy all the files to the public_html/laravelproject.
4. open index.php inside public_html/laravelproject and change the
require DIR.'/../../project/vendor/autoload.php';
$app = require_once DIR.'/../../project/bootstrap/app.php';
or
require DIR.'/../project/vendor/autoload.php';
$app = require_once DIR.'/../project/bootstrap/app.php';

Laravel showing directory file instead of redirecting to public/index.php

I am kinda new to Laravel and I am trying to do the next thing:
I have a Centos 7 running Apache and PHP on which I have different web apps running.
I have all apps in /var/www/html under folders and index.php links them all. Now i installed composer, Laravel and added a new Laravel project in /var/www/html/play/play1.
The problem is that when I try to access https://example.com/play/play1 I should get the Laravel index page (the one under public/index.php) correct?
Instead I get a directory with all Laravel project files.
If I access https://example.com/play/play1/public I can see the index page.
I've searched it over and I checked if AllowOverwrite all is present, if mod_rewrite is on. Inside public folder there is a .htaccess file.
Can anybody who dealt which such a problem help me please ?
Within the root of the project folder (where you see app/ resources folders etc) create a .htaccess file and paste the below:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Laravel's root directory should not be the one accessed publicly - you have to point to public/ directory (where the index.php and .htaccess are located).
So in your server config http://example.com/play/play1 should point to var/www/html/play/play1/public

Laravel on a shared hosting server returns error 500

I'm using a shared hosting server, I installed my first Laravel 5.4 application and everything is still working fine. A few days ago I installed another Laravel 5.4 application on a different domain, but same server, but when I try to access the URL, I get 500 INTERNAL SERVER ERROR.
Below is my .htaccess code
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
I also tried the following, but same error:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
### Add two lines for fix error 500 ###
Options -Indexes
php_flag xcache.cacher 0
#######################################
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
You moved everything inside your public_html folder which you should not do. Only files inside /public needs to be in public_html, hence the name public. The Laravel files should be placed higher directory where it is not accessible from the public.
Install Laravel with Softaculous, or with composer via SSH in /home/username/laravel
Move everything in /home/username/public_html folder to
/home/username/laravel
Move everything in /home/username/laravel/public to /home/username/public_html and delete the public folder after move.
Edit this file: /home/username/public_html/index.php
Change to require '/home/username/laravel/vendor/autoload.php';
Change to $app = require_once '/home/username/laravel/bootstrap/app.php';
Save this file and close window.
Edit this file: /home/username/laravel/server.php
Change to:
if ($uri !== '/' && file_exists('/home/username/public_html'.$uri)) {
return false;
}
require_once '/home/username/public_html/index.php';
Replace username with your hosting username. :)

Laravel 5.2 Error 500 (Internal Server Error)

I am trying to deploy a laravel project to a shared hosting platform but it keeps giving me this error 500 -Internal Server Error. It is currently working in my localhost. I have checked other site but with no avail even though .htaccess has been said to be the course but i am yet to figure it out. I have been trying for 5days but have not gotten it.
This is my .htacess file
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
If any other file is needed, i would provide. I need to deliver to a client.
If you cannot check the logs ( what would be the prefered way ) you can put this in your code
error_reporting(E_ALL);
ini_set("display_errors", 1);
Simply add it to the index.php of your public folder - if this is not working add it within the bootstrap of your app ( basically the very first thing called )
Then open the page and you will see the error.
Do not forget to remove these lines when the error is resolved
Usually the problem is missing access rights to the storage folder. If you use Filezilla for example simply rightclick the storage folder of your app and select File permission Ensure 777 is set and cascade it for every file and folder.

Resources