Publish Laravel 5 in a subfolder

Asked

Viewed 2,151 times

1

I need to publish a system I made using Laravel 5 for my client, however, I only have access to FTP. I installed Laravel via Poser on my localhost, it works very well, but I do not know how to put this system on the air via FTP. In my case, Laravel would need to stay inside the admin folder, that way:

www.meusite.com.br/portal/admin

I already googled, but what I found was only related to subdomain

  • Every time I go to a hosting I put all the files inside the folder I want. Let’s assume it’s admin. After that just access the LINK and put the /public in the end. www.meusite.com.br/portal/admin/public

  • Related or duplicated: http://answall.com/questions/43685/problema-com-subpastas-e-reescrita-de-url-laravel

2 answers

2

Laravel works as the root of your site, that is, it is a framework totally oriented to create all applications, from your Dashboard, to multiple sub-domains (see: https://laravel.com/docs/4.2/routing#sub-Domain-routing), example:

Route::group(array('domain' => '{account}.myapp.com'), function()
{

    Route::get('user/{id}', function($account, $id)
    {
        //
    });

});

So even if you play your Laravel project in a folder like /etc/www/porta/admin or /public_html/portal/admin it will not recognize when accessing:

  • http://site/portal/admin

'Cause Laravel’s gonna search the routes for this /portal/admin and not this /admin, so the idea of Laravel is that you design with it all pages, to take advantage of all Views and Models and also make the application scalable, thus avoiding creating different things for the same task. Note that just because you used Laravel to create the entire application does not mean you will be able to make it scalable without having the knowledge and experience with this kind of thing (however this is off topic here)

Fortunately it is possible to bypass Laravel’s routes and make it accessible, edit the file app/Http/routes.php and edit routes by adding a prefix /portal/admin, so where do you use:

Route::get('/', ...

Will stay:

Route::get('/portal/admin', ...

An example:

$prefixo = '/portal/admin';

//http://site/portal/admin
Route::get($prefixo, function () {
    return view('login');
});

//http://site/portal/admin/dashboard
Route::get($prefixo . '/dashboard', function () {
    //...
});

//http://site/portal/admin/logout
Route::get($prefixo . '/logout', function () {
    //...
});

If the address changes, you will have to change all prefixes /portal/admin. I don’t know Laravel at all, maybe with group it is possible to do this more easily.

Note one very important thing, the folder admin must have the content of public, so the other folders of the Laravel will be out of admin, but if this is not possible, you can put everything inside admin, even the public and create a . htaccess to redirect, as in these responses:

It should stay that way in your case:

./public_html (Pasta root da hospedagem)
    |--- portal
          |--- admin
               |--- .htaccess (arquivo .htaccess que você deve criar)
               |--- /public
                      |--- index.php
                      |--- .htaccess
               |--- /app
               |--- /bootstrap
               |--- /config
               |--- /database

The . htaccess file should look like this:

RewriteEngine On
RewriteRule ^ /public/index.php [L]

When to access http://www.site/portal/admin/ this will make a total redirect to the file /public_html/portal/admin/public/index.php.

All this comes to be a gambiarra, aiming that the Laravel was designed to work as root and there may be some difficulties in using this way, as other possible incompatibilities, what I recommend is to start thinking about maybe redoing the project (as far as possible).

0

Daniel, selects all folders, files and places inside the admin folder. The Laravel it’s like your website.

Look in the image below. Select everything you have in this directory and put inside your FTP admin folder.

Remembering that it will take a while seeing that are many files and folders from Laravel, off your site.

inserir a descrição da imagem aqui

  • So, but I’ve already done it and made a mistake

  • What mistake? That’s the way, the chorionic errors.

  • So, I’m gonna go down and up again, and then I make the right mistake

  • So when I access my site this way: www.meusite.com.br/portal/Adm, give me these two errors: Warning: require_once(DIR/public/index.php) [Function.require-Once]: failed to open stream: No such file or directory in /home/Storage/8/28/D5/conre3/public_html/portal/Adm/index.php on line 21 Fatal error: require_once require() [Function.]: Failed Opening required require 'DIR/public/index.php' (include_path='.:/usr/share/Pear') in /home/Storage/8/28/D5/conre3/public_html/portal/Adm/index.php on line 21

  • Is there any .htaccess in a folder prior to admin FTP ? Or inside the folder admin ? If yes, post in your question along with the error.

  • No . htacces, neither within the portal nor within the admin

  • So create a .htaccess and place inside the folder adm. You gotta have it: <IfModule mod_rewrite.c>&#xA; RewriteEngine On&#xA;&#xA; RewriteRule ^(.*)$ public/$1 [L]&#xA;</IfModule>

  • I put it there, now it gave error 500

  • 500 ? See in the file app.php the line debug = false, place true and passes only that file in its respective folder on FTP. It is on app/config/app.php.

  • So there’s no app. This Laravel is version 5, I think it’s a little different. the app.php I have is already inside the config folder, and it’s already true debug

  • So, it’s the same... it’s pointing to the right page ? Has how you show how is the folder layout of your 'Laravel'' ?

  • So the layout is default, I didn’t change anything, the same way it came from the Komposer I put in the Adm folder by ftp

  • And when you access the page access with or without the /public ?

  • Both ways the same problem

  • Updated the PHP, Fei ?

Show 11 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.