I made a website with laravel and forwarded my domain to the folder of the project. However when I enter the website it shows me the error: 404 not found
The requested URL / was not found on this server
Server.php:
<?php
$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';
.htaccess:
<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>
Index.php:
require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
EDIT #1
I made a public_html folder and placed the contents of laravel/public in it. changed the paths to use '/../laravel/bootstrap/app.php' and '/../laravel/bootstrap/autoload.php'. When I enter the website now it gives me the HTTP 500 error
Revert the changed files to their defaults and point your virtual host to the public folder.
Related
I created the Laravel Project in a local machine and I created the database also. In the local machine, a project is working without any issues but I uploaded my project file into the shard server Cpanel inside the public_html folder and I access the URL it's saying This page isn’t working, HTTP ERROR 500.
Cpanel PHP version is 7.0
Laravel version is 5.6
But I moved the content file inside the public folder to root folder (public_html) and I changed the path in index.php file
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
And server.php file also I change the path Like this.
if ($uri !== '/' && file_exists(__DIR__.'/public_html'.$uri)) {
return false;
}
require_once __DIR__.'/public_html/index.php';
And 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>
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “alt-php70” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-alt-php70 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
Please help to fix this issues.
You should put all the public folder files inside public_html folder and the rest of your project files inside another folder which you can name it laravel. Then you shoud change your index.php file like this:
require __DIR__.'/../laravel/vendor/autoload.php';
$app = require_once __DIR__.'/../laravel/bootstrap/app.php';
The laravel application seems to have routes issue with the sub-directory on server. With the running application on local machine does not work on temporary domain in sub-directory on live server. Playing around .htaccess seems to have different results.
This question is almost identical to what I would be looking for but he hasn't got any solution while I have got some work around.
The .htaccess within the laravel public have been modified to something like:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteBase /~timely/email-client //<--base has been modified
# 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 application will redirect you to host gator 404 page.
Also I've added .htaccess to the main directory which will forward every request to public directory.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Upon removing the home/main .htaccess just works for / route: e.g
http://gator4057.temp.domains/~timely/email-client/public will work but all other routes are redirected to the same host gator 404 page.
Your comments and answers will be appreciated.
Thanks
Step 1. Move all email-client/public to email-client/. Now we're getting somewhere. Warning: Don't forget to copy the .htaccess file too
Step 2. Open email-client/index.php in your favorite editor and change
$app = require __DIR__.'/../bootstrap/app.php';
to
$app = require __DIR__.'/../email-client/bootstrap/app.php';
or may be
$app = require __DIR__.'/email-client/bootstrap/app.php';
and change:
require __DIR__.'/../bootstrap/autoload.php'
to
require __DIR__.'/../laravel/bootstrap/autoload.php'
or may be
require __DIR__.'/laravel/bootstrap/autoload.php'
Run command:
php artisan cache:clear
php artisan config:clear
php artisan optimize
OR
If you dont wana to do more changes try this:
Put this in index.php file
$app->bind('path.public', function() {
return __DIR__;
}
Hope work for you.
2 questions actually:
How do I setup a Laravel site in a subfolder?
How do I flush/clear the cache?
My current situation:
I'm on shared hosting (don't mock me....I know dedicated server is better....trying to figure out how much budget to allocate for it so currently using shared since I can pay monthly) and can't use SSH.
URL structure is like this: website.com/v2 where "v2" is the subfolder where the site is installed on.
Is this the way my .htaccess and index.php are supposed to be setup?
.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /v2/
# 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}]
index.php
require __DIR__.'/../v2/bootstrap/autoload.php';
$app = require_once __DIR__.'/../v2/bootstrap/app.php';
For clearing the cache, I got this code in routes.php:
Route::get('/v2/configcache', function() {
$exitCode = Artisan::call('config:cache');
print_r($exitCode);
});
Are all of the codes above setup correctly? When I go to mywebsite.com/v2/configcache, I get an "Under Construction" message.
I need to clear the cache because I updated the database info.
I have this .htaccess in the laravel installation directory
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
And this .htaccess in the public directory of the laravel installation directory (this one came with the laravel)
<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>
So, if I access the root/installation directory in the browser, like this http://something where something is the installation directory and has it's own virtual host on localhost, then it works and if I access it like this http://something/public then it works too. But this setup doesn't work on the production server. If I access my website(which is a subdomain) on production server like this http://sub.something.com then it doesn't work, this shows me Page not found error, but this works http://sub.something.com/public
What am I doing wrong?
I have namecheap.com shared hosting
On share hosting subdomain, it's good your folder structure look like this:
I assume it's a linux server (Apache)
--public_html
----subdomainFolderName (content of public folder)
-------.htaccess
-------index.php
-------etc
-------laravelFolder [Public folder will not be inside here]
----------app
----------bootstrap
----------config
----------etc
Edit subdomainFolderName/index.php
Change line 22
require __DIR__.'/../bootstrap/autoload.php';
TO
require __DIR__.'/laravelFolder/bootstrap/autoload.php';
Change line 36 $app = require_once __DIR__.'/../bootstrap/app.php';
TO
$app = require_once __DIR__.'/laravelFolder/bootstrap/app.php';
This way you will not have issues with .htaccess and your URL will not contain /public
I'm trying to deploy a laravel app on shared hosting. Here is what I did.
I zipped the entire laravel-app directory on my local machine.
I uploaded it and then unzipped the app in the public_html folder on the server.
I changed the file permissions of the public_html/larvel-app and public_html/laravel-app/storage and public_html/laravel-app/public to 777.
I removed the line 'public' in the .gitignore file.
I then copied the index.php and .htaccess file from laravel-app/public to the homepage and pointed to the necessary autoload folders (the ones about require and the $app variable to laravel-app/public).
Problems: If I navigate to my-website homepage, all the HTML for the homepage is being pulled in but no CSS or JavaScript or images. If I navigate to my-website/laravel-app/public, I see an internal server error message (error 500). However I have been able to view the files of other folders in the laravel-app subdirectory.
I include a copy of my .htaccess file code here.
<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>