Installing Laravel in a subdirectory - php

I've been searching around for an answer to this and can't find anyone with my exact problem and was hoping someone else has had this issue.
I had Laravel installed locally using a vhost, and it was installed at the root. I've now had to move this install to another server at http://domain.com/~username, all my files are in /~username/ and I'm using .htaccess to access the public folder from http://domain.com/~username.
I've also set my paths correctly and my site URL in app.php.
Everything almost works except for my routes.
If I navigate to http://domain.com/~username I get a NotFoundHttpException
This is my route for my homepage:
Route::get('/', function() { ... });
if I change it to
Route::get('/~username', function() { ... });
it shows me the homepage. This isn't exactly ideal and kind of hacky, plus there's a lot more issues than just the homepage.
I'm having other issues with pretty much everything because Laravel thinks it's installed in the root folder, and not /~username/.
My question is how can I get Laravel to see that it's installed to http://domain.com/~username/ and NOT http://domain.com/?
EDITS: adding .htaccess files
My current .htaccess file in root (/~username)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /~username/
RewriteCond %{THE_REQUEST} ^GET\ /public/ [NC]
RewriteRule ^public/(.*)$ $1 [L,R=301,NE]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
</IfModule>
and the .htaccess file in /public
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /~username/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
</IfModule>

I might not have understood your question properly but here is my solution.
Go to /bootstrap/paths.php and change to:
return array(
'app' => __DIR__.'~username/../app',
'public' => __DIR__.'~username/../public',
'base' => __DIR__.'~username/..',
'storage' => __DIR__.'~username/../app/storage',
)
I'm not sure if this will work. I haven't tried it.

Related

Laravel Project in subfolder reroutes to main domain. Is the setup right and how to add prefixes?

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?

links not working when deploying Laravel app to Heroku

I was given a laravel project I need to get up and running. I am new to laravel, but after allot of work, I believe I got everything configured properly and I deployed the project to heroku.
When I do artisan serve on my guest machine in my laravel project and go to the given url everything works fine all the links works.
But I deploy it to heroku and my index page shows but none of the links work.
I get:
Not Found The requested URL /register was not found on this server.
It seems that running php artisan serve kinda activates the links, but how do I make that happen on heroku???
I should note the app is using blade.php files
What am I missing???
This is in the /resources/views
My _htaccess inside my public folder is as follows
<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 tried adding RewriteBase / doesnt help.
I also tried changing htaccess to:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
And my Procfile has:
web: vendor/bin/heroku-php-apache2 public/
Thanks
Well I resolved my issue, it seems that I had some lowercase letters in my web.routes path
that should have been Capital letters. Local host dosen't seem to mind if the words are uppercase or not, but linux does seem to mind.... Not sure if it will help, but i searched a long ass time for something so silly...
I had to restart my dynos for it to work, run heroku restart
Also make sure to have a Procfile in your root with
web: vendor/bin/heroku-php-apache2 public/
I resolved with:
In config/app.php
I changed for:
'asset_url' => env('ASSET_URL', 'https://appcreated.herokuapp.com'),

pretty urls laravel 5.4

Hi I am facing issues with settng pretty urls withput public in url but it is not working for me.
I already tried
Laravel 5.2 Pretty URLs,
Laravel 5 - Remove public from URL
and more similar urls but nothing seems to work for me.
I am using wamp, windows 8
I have make sure mod_rewrite is on, and is working properly.
Here is my htaccess on root.
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
my htaccess in test inside public folder
<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 have also tried pasting the htacess from public folder on root folder and removed the one from public folder but it dint work
actually the error which occurs is that my routes file skips all the patterns say if I have something like Route::get('/api/login', 'api#login') then it does works with urls containing public but when I remove public from url all the patterns are skipped. and it shows 404
I made sure all the requests are reaching public/index.php and mysterious thing is that when I print
var_dump(Request::root());
in routes.php it for url with public it says http://localhost/folderName/subFolderName/public but for the urls without public it says http://localhost/ and I think this is the reason why my patterns in routes file are not working.
P.S. I have set the title pretty urls laravel 5.4 instead of laravel routes not working because I think it is .htaccess which I needs to configure properly to get this working.
I do not want to change the folder structure because I believe in that there is some reason for which it is like this and There should be some work around for this.
Regarding setting vhosts I wont be able to do this on server (For I do not have the rights) so there is no use of setting a vhost on local as a work around as in login run I have to solve this.
Try this in your public/.htaccess
RewriteRule ^ /public/index.php [L]
And the .htaccess in root
RewriteRule ^(.*)$ /public/$1 [L]

How to remove laravel 5.2 directory name from url after hosting it online

I have laravel 5.2 project developed.I have hosted it online
I access that project using the url
www.mydomainname.com/laravelproj/admin
Here I don't want the "laravelproj" i.e project directory name , I just want
www.mydomainname.com/admin to be opened
I am unable to change the settings in .htacess properly.
Anyone please assist me in doing so.
My .htaccess file
<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]
RewriteRule ^.env - [F,L,NC]
</IfModule>
My directory structure for project
My routes.php file contents are
//Routes for all admin control panel
Route::get('/admin','Admin\LoginController#viewlogin');
Route::post('/admin/login','Admin\LoginController#checklogin');
Route::group(['middleware' => ['admins']], function ()
{
Route::get('/admin/dashboard','Admin\AdminController#dashboard');
Route::get('/admin/logout','Admin\LoginController#logout');
Route::resource('/admin/movies','Admin\MovieController');
Route::resource('/admin/states','Admin\StateController');
Route::resource('/admin/cities','Admin\CityController');
Route::resource('/admin/tax','Admin\TaxController');
Route::resource('/admin/smsgateway','Admin\SmsgatewayController');
Route::resource('/admin/smtpgateway','Admin\SmtpgatewayController');
Route::resource('/admin/paymentgateway','Admin\PaymentgatewayController');
Route::resource('/admin/news','Admin\NewsController');
Route::resource('/admin/promotion','Admin\PromotionController');
Route::resource('/admin/staff','Admin\StaffController');
Route::get('/admin/staff/resetpass/{id}','Admin\StaffController#resetpass');
});
Go to app/Http/routes.php in the directory where you installed Laravel and just remove laravelproj from the routes. It should look something like this:
Route::get('laravelproj/admin', 'PagesController#admin');
change it to
Route::get('admin', 'PagesController#admin');
If you installed your Laravel project into an extra subfolder on your server, then, depending on how big your project is, it may be a good idea to reinstall it again into the public root directory on your server. Otherwise you may be facing multiple issues with databases and libraries you might want to install in the future.

laravel publish site issue

I need to publish my web app written in laravel 4,
i've followed many tutorial in internet but i'm not able to make it works correctly.
i'm on a dedicate server with centos 6.6 where resides another website so the laravel app should be placed in a sub folder named vols
this is the current folder structure:
/
var/
www/
laravel/
app/
bootstrap/
vendor/
...
html/
vols/
other files of my website
i've changed the paths inside bootstrap/paths.php to
'app' => __DIR__.'/../../laravel/app'
'public' => __DIR__.'/../../html/vols'
'base' => __DIR__.'/../../laravel'
'storage' => __DIR__.'/../../laravel/app/storage'
and the paths inside vols/index.php to
require __DIR__.'/../../laravel/bootstrap/autoload.php';
$app = require_once __DIR__.'/../../laravel/bootstrap/start.php';
my first controller is named volunteers, so if visit http://mydomain/vols i should be redirected to http://mydomain/vols/volunteers
instead i see this error message: The requested URL /vols/volunteers was not found on this server.
if i try to connect to http://mydomain/vols/index.php/volunteers everything works correctly but i don't want index.php in my route.
i think i should work on .htaccess inside vols folder, but i've never studied how it really works, so i'm just copying some random snippets from internet substituting public with vols.
currently it look like this
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^vols
RewriteRule ^(.*)$ vols/$1 [L]
</IfModule>
Some solutions suggests to create vhost, technically i can do that, but i don't know how.
Could you please help me?
You should place the following .htaccess in your vols folder -
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /vols/
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Categories