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.
Related
I am trying to deploy my Laravel 8 app to a folder in CPANEL (first time I've deployed Laravel). I have searched the forum and made changes as the many posts direct. I am getting 404 errors across all pages apart from the homepage and login and register pages. This is a common error but I cant find a solution. Dont shoot me.
1.All files uploaded to url/laravel/blog
Public folder moved outside and renamed public_html
The /laravel folder now has two directories /blog and /public_html
index.php in the public_html folder updated:
require DIR.'/../blog/vendor/autoload.php';
$app = require_once DIR.'/../blog/bootstrap/app.php';
New .htaccess file added to the root of the public_html and set to chmod 755 (detailed below)
Renamed the cache folder in the /bootstrap folder so that new cache is created (I hope)
Database is linked within the .env file
I am out of ideas, I have created a test html file in the public folder and I can see this in the browser when I navigate to it. I am learning and any help will be appreciated.
<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>
I needed to point the subdomain/add-on domain to the public folder. No need to move anything or change Htaccess etc.... Credit to https://stackoverflow.com/users/2325620/james-clark-developer
Try this in your .htaccess
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^$ public/index.php [L]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
</IfModule>
first of all this are my laravel and PHP versions:
Laravel Framework 7.17.2
PHP 7.3.19 (cli)
I am having a wierd problem with my laravel project:
in my vhost file I have:
<VirtualHost *:80>
ServerName www.name.test
DocumentRoot "C:\web\name\name\backend\public"
</VirtualHost>
in the hosts file:
127.0.0.1 www.name.test
when trying to acces the project by typing:
http://www.name.test
it redirects me to the url
http://www.name.test/public/public
I have .htaccess in my root folder and in the public folder with the following :
<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 dont know why this started to happen, previously it was working fine but sth I gues was changed accidentally on the project since it happens in everycomputer, so it does not look like a php configuration problem.
hope someone can give some tip about the issue.
There are 2 ways to fix this issue:
Step 1:
Just rename your server.php to index.php file present in your project root directory.
Step 2:
Copy index.php present inside public folder of your project root directory and paste it inside the root directory. Make sure there is no other index.php present before.
Then replace these 2 lines:
require __DIR__.'/../vendor/autoload.php';
require_once __DIR__.'/../bootstrap/app.php';
with
require __DIR__.'/vendor/autoload.php';
require_once __DIR__.'/bootstrap/app.php';
Hope either of the 2 ways helps!!
For the testing of a new version of a project, I have to deploy a laravel project to a sub folder which was set up for me. I already programmed it on the localhost and only need to upload it.
The subdomain is on example.com/new
The structure I found in Filezilla was like this:
(I do not have access/can't see to the main Versions files-does this mean it is a subdomain?)
htacess
env
newProject(folder)
public
I did not have permission to upload new files above the public folder. The .env and .htacess could be replaced. So I did the following:
htacess
env
newProject(folder)
public
index
project(folder)
(laravel put another.env and .htacess in here are these the right ones to change)
.htacess
.env
rest of laravel files
Out of confusion I always just make a change in both existing .env's and .htacess because I don't know which is the right one. Is this setup right? I already changed the index
require __DIR__.'/project/vendor/autoload.php';
$app = require_once __DIR__.'/project/bootstrap/app.php';
My htacess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
[[rewritebase /new
# 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 PROBLEM:
There is at least something working. Because I have an automatic rerouting for languages in the web.php
Route::redirect('/', '/en');
Route::group(['prefix' => '{language}', ''], function (){
...routes
And when I go to example.com/new it reroutes me to example.com/en instead of example.com/new/en. That means it does come to the routing part, dies this mean htacess and .env are set up right?
the error is of course
"Not Found
The requested URL was not found on this server."
MY QUESTION
How do I stop the rerouting to /en and go to /new/en. Is there a prefix I can add to all my routes. And can I be sure the rest is set up right just because the code routes to /en which is set up in the web.php?
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