I have found a solution for laravel Deployment
Most of us are stucked in the laravel deployment in server, most reason is changing the public path and modified the server.php
Please find the answer below:-
Just Change the .htaccess and the problem is solved:
Change Two files in root 1..htaccess, 2. .index.php
And Change Two files in public folder 1..htaccess, 2. .index.php
Root Folder
.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
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 ^ index.php
Root Folder
index.php
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* #package Laravel
* #author Taylor Otwell <taylor#laravel.com>
*/
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
/*if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
return false;
}*/
require_once __DIR__.'/public/index.php';
Public Folder
.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>
Public Folder
index.php
<?php
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Check If The Application Is Under Maintenance
|--------------------------------------------------------------------------
|
| If the application is in maintenance / demo mode via the "down" command
| we will load this file so that any pre-rendered content can be shown
| instead of starting the framework, which could cause an exception.
|
*/
if (file_exists($maintenance = __DIR__.'/../storage/framework/maintenance.php')) {
require $maintenance;
}
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| this application. We just need to utilize it! We'll simply require it
| into the script here so we don't need to manually load our classes.
|
*/
require __DIR__.'/../vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request using
| the application's HTTP kernel. Then, we will send the response back
| to this client's browser, allowing them to enjoy our application.
|
*/
$app = require_once __DIR__.'/../bootstrap/app.php';
$kernel = $app->make(Kernel::class);
$response = $kernel->handle(
$request = Request::capture()
)->send();
$kernel->terminate($request, $response);
Find the solution and cheers...
Happy Coding..
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 already upload my project to my host
The link is examplesite.com/Hiflyer/public/index
I want all my route their look like this.
examplesite.com/index
examplesite.com/news
This is 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]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
The question is how to configure it?
Perform 2 simple steps and you could run your laravel project without /public folder.
1.) Move the .htaccess file to the main directory from public folder without any changes.
2.) And do the same with index.php.
Rest .htaccess file working has following content.
RewriteEngine On
#----------------------------------------------
# | this code use for remove public directory |
#----------------------------------------------
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_URI} !(\.ico|\.css|\.js|\.png|\.jpg|\.gif|robots\.txt|\.eot|\.svg|\.ttf|\.woff|\.woff2|\.otf|\.pdf)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(login|uploads|assets|css|js|images|ca|favicons|fonts|)/(.*)$ public/$1/$2 [L,NC]
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
And index.php
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* #package Laravel
* #author Taylor Otwell <taylor#laravel.com>
*/
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
return false;
}
require_once __DIR__.'/public/index.php';
i built a website with codeigniter and when i uploaded it it give me that error The requested document was not found on this server. i know that the problem is with my .htaccess code. so anyone can help me?
RewriteEngine on
RewriteCond $1 !^(index\.php|css|js|robots\.txt|images|itempics)
RewriteRule ^(.*)$ /index.php/$1 [L]
Try this (anything listed in with the js|css etc will not use the rewrite
Options +FollowSymlinks
RewriteEngine on
# On Rackspace and getting 404's? Uncoment this by removing the # :
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_rewrite.c>
RewriteRule ^(.+)\.(\d+)\.(js|css|docs|img|invoices|support|demos|blog|devx)$ $1.$3 [L]
</IfModule>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
On one shared hosting I have this set:
RewriteEngine on
RewriteBase /
Options -Indexes
RewriteCond $1 !^(index\.php|robots\.txt|assets)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/\?$1 [L]
Also,
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://example.com/
|
| If this is not set then CodeIgniter will guess the protocol, domain and
| path to your installation.
|
*/
$config['base_url'] = 'http://example.tld/';
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = '';
I have a problem with setting up a local testing environment using codeigniter and an already existing code.
Well, the problem is, that I can't open a page, without having "index.php" in my URL. So, "test.mydomain.local/index.php/search" works fine while "test.mydomain.local/search" does not. But all links in the code, excluding the action-URLs in form-tags, doesn't have this "index.php" in the URL.
How can I solve the problem, that codeigniter or the xampp need this "index.php" in the URL? Do I need to change something in my code or maybe in .htaccess?
Here is my config.php
$config['base_url'] = "http://test.mydomain.local/";
$config['index_page'] = "index.php";
$config['uri_protocol'] = "AUTO";
Well, this code forces the "index.php" in the action-URL in form tags. But actually I dont want to have this index.php in any URL. So that my config.php should look like this, I guess:
$config['base_url'] = "http://test.mydomain.local/";
$config['index_page'] = "";
$config['uri_protocol'] = "AUTO";
Here is the .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
### force www
RewriteCond %{HTTP_HOST} ^mydomain.com [NC]
RewriteRule (.*) h t t p : / / w w w . m y d o m a i n . c o m/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^domain.local [NC]
RewriteRule (.*) h t t p : / / t e s t . d o m a i n . l o c a l/$1 [R=301,L]
### if the is not a request for an existing file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
### and the URI does not end with a /
RewriteCond %{REQUEST_URI} !^([^?]*)/($|\?)
### redirect and add the slash.
RewriteRule ^([^?]*) $1/ [L,R=301]
### if the is not a request for an existing file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# rewrite to index.php passing the URI as a path, QSA will preserve the existing query string
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
Can anybody help me? It is driving me nuts!
I use xampp and have found this htaccess is best. Do not for get to put your base url in config/config.php and remove index.
.htaccess
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Your config.php
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://example.com/
|
| If this is not set then CodeIgniter will try guess the protocol, domain
| and path to your installation. However, you should always configure this
| explicitly and never rely on auto-guessing, especially in production
| environments.
|
*/
$config['base_url'] = 'http://localhost/project name/';
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = '';
I am using a reference book called PHP and MVC with CodeIgniter, and I’m following the examples of projects putting in my personal pc.It runs fine at my local PC and but gives some error at webserver. Diagnosis: The problem in question is the routes of pages. in my personal pc works normally, but when I put it on the web server can not find the requested page.
http://orion.locadados.com.br/~wladi/Carrinho_Compras/
http://orion.locadados.com.br/~wladi/Carrinho_Compras/categoria/artigos-esportivos
The routes defined in my project are as default for any server, because they are in the project folder itself. Just do not put the line of code, it would not know which part of the code put online.
How can i fix this?
file .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
the file routes.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------------
| URI ROUTING
| -------------------------------------------------------------------------
| This file lets you re-map URI requests to specific controller functions.
|
| Typically there is a one-to-one relationship between a URL string
| and its corresponding controller class/method. The segments in a
| URL normally follow this pattern:
|
| example.com/class/method/id/
|
| In some instances, however, you may want to remap this relationship
| so that a different class/function is called than the one
| corresponding to the URL.
|
| Please see the user guide for complete details:
|
| http://codeigniter.com/user_guide/general/routing.html
|
| -------------------------------------------------------------------------
| RESERVED ROUTES
| -------------------------------------------------------------------------
|
| There area two reserved routes:
|
| $route['default_controller'] = 'welcome';
|
| This route indicates which controller class should be loaded if the
| URI contains no data. In the above example, the "welcome" class
| would be loaded.
|
| $route['404_override'] = 'errors/page_missing';
|
| This route will tell the Router what URI segments to use if those provided
| in the URL cannot be matched to a valid route.
|
*/
$route['default_controller'] = "home";
$route['categoria/(:any)'] = "home/categoria/$1";
$route['produto/(:any)'] = "produtos/detalhes_produto/$1";
$route['404_override'] = '';
/* End of file routes.php */
/* Location: ./application/config/routes.php */
try with this .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^sys.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^app.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
assuming that your system folder is sys and application folder is app
For me this htaccess works with the latest CI version
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
Try with this