Flush cache in Laravel 5.2 on shared hosting without SSH? - 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.

Related

Laravel application on sub-directory

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.

laravel 5.5 - route to folder

I upload all my laravel 5.5 app in to my shared server (www.example.com/laravel/) folder. now when I goto www.example.com/laravel it will launch my app. but I have 2 route issues:
my route in web.php is not working anymore. when I click:
AboutUs
it will go to www.example.com/laravel/about, and the result is understandably Not Found because in my web.php my route is:
Route::get('/about', 'HomeController#about')->name('about');
I even change to
Route::get('laravel/about', 'HomeController#about')->name('about');
and it still not working. How can I resolve this?
I still have my public folder inside the /laravel/ folder. To make all the css and js file to link, I have to change from:
to
<link href="{{ asset('public/css/app.css') }}" rel="stylesheet">
to make it to work. Is there away to reconfigure this?
I can hardcode both to make them work. But that will heavily affect my constant develop and update process. I am looking for a way to set it once and no need to change between development and production.
Update01
I tried #ben's suggestion and change the .htaccess in the public folder:
<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
RewriteBase /laravel //<-----this is what I add!
RewriteRule ^ index.php [L]
</IfModule>
but nothing seems to work. I am very new to .htaccess so I am not sure of what I am doing there. Any more insight?

.htaccess not working with laravel on production server-Shared hosting

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

Laravel 5 Error 403 forbidden access webhosting

I wanted to deploy my Laravel 5 App on the webhost one.com
I followed along some tutorials on the internet and moved my puplic folders content into the root folder of the host and made the required path changes to the index.php file.
But now I've got the
403 Error: You don't have permission to access / on this server.
I believe it's because of my .htaccess file:
Options -MultiViews
RewriteEngine On
DirectoryIndex public/index.php
# 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 ^ public/index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
I'm new to .htaccess files and maybe you guys can help me! :)
The 403 forbidden status you have, can be triggered by many things. I hope you get started by checking the following:
Create (or access) an existing file with your document root. Is this file accessible? If accessible, something in your .htaccess is off. If not accessible, probably not access is granted (yet), please add to your .htaccess:
Require all granted
When the test file is still not accessible, this could be a side effect of the 'Redirect Trailing Slashes If Not A Folder', please change this to:
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
Another addition to your .htaccess could also solve the issue:
RewriteBase /
Let me know if (or not) your issue is resolved.

Multiple Choices error page in 1and1

I have done my project using laravel. I want to upload my project on 1and1. I set my directory structure on 1and1 is as '/directory' which contains index.html file which links to the other page in /directory/EngageV1/public/auth/login. but when I visits this page I am getting the error page as,
Multiple Choices
The document name you requested (/index.php) could not be found on this server. However, we found documents with names similar to the one you requested.
Available documents:
/index.html (common basename)
Please consider informing the owner of the referring page about the broken link.
My .htaccess file looks like,
<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]
</IfModule>
If enter url as /directory/EngageV1/public/ then it shows me the welcome page which I have set in routes.php file for route as '/'. Only this page works fine,I don't know what to do, Please give any suggestion.
Replace default contents in your .htaccess file under your the public
folder with the following.
RewriteBase /
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
If you still have problems look at this tutorial about how to deploy a Laravel webapp to 1and1
I know this is is an very old topic, but it took us some time today to find out what's going wrong on an old 1and1 (now Ionos) server. Turned out, the "multiple choices" page doesn't com from Option +MultiViews / mod_negotiation, but from a module called mod_speling that's running there by default. You can disable it in the .htaccess file:
<IfModule mod_speling.c>
CheckSpelling off
</IfModule>

Categories