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';
Related
I'm trying to upload my Laravel project to my shared hosting cPanel its not my first time that I've uploaded the Laravel project but this time I think I'm out of luck I'm facing 500 server error.
here is the screenshot
I already try all the solution even I turn on debug too but nothing seems to work.
what I did is upload public files into my subdomain folder and rest into an other folder outside of subdomain folder I also try php_info(); and everything is enabled. could you please help me out.
Also nothing is in error log for this error.
The way i deploy on shared hosting. I do have the files in the public folder in the root directory. while in the index.php i point it to the laravel folder.
Here is how the directory will look like, take for example my laravel project is called willa:
willa
favicon.ico
.htaccess
index.php
My index.php look like this:
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* #package Laravel
* #author Taylor Otwell <taylor#laravel.com>
*/
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| I removed the comments.
|--------------------------------------------------------------------------
*/
require __DIR__.'/willa/vendor/autoload.php';
$app = require_once __DIR__.'/willa/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);
My .htaccess:
<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]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I use hostinger and I have two folders in my parent hosting directory
my-laravel-app-folder
public_html
in public/index.php I changed
require __DIR__.'/../vendor/autoload.php'; to require __DIR__.'/../my-laravel-app-folder/vendor/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php'; to $app = require_once __DIR__.'/../my-laravel-app-folder/bootstrap/app.php';
in public/.htaccess file I changed
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
Options +FollowSymLinks
# 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]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ index.php [L]
</IfModule>
From parent / directory ,I have already run
ln -s my-laravel-app-folder/storage/app/public public_html/storage
But I still cannot access to linked storage files and got 404 error.
Finally I found the solution, it's when creating a symlink ,I have to include absolute path for folders instead of current path .For example,
For my-laravel-app-folder/storage/app/public replaced with /home/u440262284/domains/mysite.com/my-laravel-app-folder/storage/app/public
instead and
For also public_html/storage replaced with /home/u440262284/domains/mysite.com/public_html/storage
It worked !!!
do symlink
ln -s my-laravel-app-folder/storage/app/public public_html/storage
Remove the index.php and .htaccess file from public_html/storage and copy manually from your laravel project to public_html/storage.
You don't need to change your index.php file, try to change your domain path into public_html/storage/public
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
I want to remove public from my web URL simply step by step
I have done some steps already like copying the file from public the index and htaccess file but still I am getting not found page
I tried to solve this problem simply by making a .htaccess file. This file configures the apache server and solves the problem. Simply put this code in a file named '.htaccess' and save it in the root folder.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
</IfModule>
If you have done 2 steps already have you change the index.php having vendor folder path inside remove the /../ and everything work fine
$app = require_once __DIR__/../'/bootstrap/app.php';
to
$app = require_once __DIR__.'/bootstrap/app.php';
It's possible to remove public from url in laravel5. Follow these steps:
step 1 : copy all file from public and paste on root directory
step 2 : open index.php file replace with
require __DIR__.'/../bootstrap/autoload.php';
to
require __DIR__.'/bootstrap/autoload.php';
and
$app = require_once __DIR__.'/../bootstrap/app.php';
to
app = require_once __DIR__.'/bootstrap/app.php';
Then Remove all cache and cookies.
php artisan cache:clear
Steps I followed till now:
create sub-domain.
uploaded project files of public inside public_html/subdomain-name/
create a folder subdomain-name in root
upload every files of laravel project except public folder inside subdomain-name folder
change 2 lines of index.php which is inside public_html/subdomain-name/ as to:
require __DIR__.'/../../../staging/bootstrap/autoload.php';
and
$app = require_once __DIR__.'/../../../staging/bootstrap/app.php';
And my htaccess files looks like:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I am getting error as:
This page isn’t working
staging.mydomain.com is currently unable to handle this request.
HTTP ERROR 500
Can somebody guide me with this? Thank You
2. uploaded project files of public inside public_html/subdomain-name/
When you create a subdomain, a folder appears in your root directory, you should upload project files of public into created subdomain folder. ie (example.your site.com) and not into public_HTML/subdomain
You should also try this in your .htaccess
Options -MultiViews
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]