Publish Laravel 5 in a subfolder

1

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

www.meusite.com.br/portal/admin

I already did the search in google, but what I found was only referring to subdomain

    
asked by anonymous 22.09.2015 / 15:37

2 answers

2

Laravel functions as the root of your site, ie it is a framework that is fully geared towards creating all applications, from your dashboard, to multiple sub-domains (see: link ), example:

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

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

});

So even if you throw your Laravel project into a folder like /etc/www/porta/admin or /public_html/portal/admin it will not recognize when to access:

  • http://site/portal/admin

Because Laravel will search on the routes 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 to create different things for the same task. Note that just because you used Laravel to create the whole application does not mean that you will be able to scale it without having the knowledge and experience with this type of thing (however this is out of the subject here) / p>

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

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

It 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 do not know Laravel thoroughly, maybe with group it is possible to do this more easily.

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

It should look like this 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 accessing http://www.site/portal/admin/ this will do a full redirect to the /public_html/portal/admin/public/index.php file.

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

    
27.12.2015 / 14:39
0

Daniel, selects all folders, files and places them inside the admin folder. Laravel is like your site.

See the image below. Select everything in this directory and put it in the admin folder of your FTP.

Remembering that it will take a while since there are many Laravel files and folders outside of your site.

    
22.09.2015 / 15:40