Can Laravel be installed in a shared hosting?

5

I will start to develop a project but I have a great doubt, can you install laravel in a shared hosting? Can I see the errors online and work directly? I have researched about Laravel and I see that Compoiser is used to install libraries, but being a shared hosting and being uploaded to the server is it possible to generate conflicts?

    
asked by Fercho Jerez 30.08.2016 в 14:36
source

3 answers

5

If it can be installed in a shared hosting, I have already installed several projects like this:

  • Install all dependencies on your local or development server.
  • Upload all the files of your project to the server (including the vendor folder), leaving in your public directory of the server only the contents of the public directory.
  • The rest of the files can / should be located in a folder OUT of the public site, for security.
  • In the index.php file of your public folder, modify the following variables so that they find the entry points according to your directory structure:

    require __DIR__.'/../bootstrap/autoload.php';
    
    $app = require_once __DIR__.'/../bootstrap/app.php';
    
  • Depending on the hosting provider may allow you to use directly or not Composer and artisan, this must already prove it.

        
    answered by 30.08.2016 в 14:41
    4

    For the installation of laravel projects on shared servers this is what I do:

    Prerequisites:

    • SSH access to shared server
    • Have your project in a remote GIT repository (github.com)
    • Version of PHP v7 or greater

    After you have that, you log in through SSH to your shared server. you place yourself at the root of your user with cd .

    Verify that you have GIT, Composer installed on your server. You can verify this with:

    GIT

    git --version
    

    Composer

    composer -v
    
      

    If you do not have any installed, or you are missing one, Install Composer by command line For GIT if you have to request that they install it, since you can not use many of the BASH commands. As apt-get, yum among others.

    Once you keep in mind that you have these two, you only need to clone your repository with:

    git clone https://url.de.tu.repositorio.git [nombre_de_carpeta_contenedora]
    

    you enter your folder created with the clone of your repository

    cd [nombre_de_carpeta_contenedora]
    

    You install all the dependencies of your laravel installation with

    composer install
    

    With this, your laravel project will install all the necessary dependencies.

    Then you enter the public laravel

    folder
    cd public
    

    and copy all the contents of this directory to your public folder of the url

    cp -r ./ ../../nombre_de_carpeta_publica_de_tu_url
    

    This will copy the index.php, and the public folders of your project. as the JS /, css /, images / , among others.

      

    This means that every time you make a modification to these files, you can usually include *. js * .css images You have the obligation to do this process again

    Now you have already copied the data to the public folder of your url, you must enter it

    cd
    cd nombre_de_carpeta_publica_de_tu_url
    

    And here you have to modify the index.php file, since it has some routes related to the inclusion of the boot files.

    Placing the command

    nano index.php
    

    a text editor will open, look for the line that says something like:

    and modify so that it remains

    require __DIR__.'/../carpeta_de_tu_proyecto_laravel/bootstrap/autoload.php';
    $app = require_once __DIR__.'/../carpeta_de_tu_proyecto_laravel/bootstrap/app.php';
    
      

    Remember that they are relative routes if you have another file system modified according to your needs.

    With this you must leave your laravel project with the url

      

    Remember that you have to modify your .env file, which is now called .env.example because you cloned your repository, so you can put all the configuration data of your databases of data and others.

    Modification 2017-10-11

    This modification is for to update the public directory , because when we upload an image or some file, and save it in the public directory ( public folder) it saves it in the public directory where the project was placed, this does not indicate that for when we want to access these resources it will not be where the index.php is that we modify to relate it to the project. This update consists of changing the public path just after loading laravel.

  • We are positioned after loading the bootstrap / app.php (line ~ 38 of the index.php)
  • we place the following line doing the same redirection process with relative routes
  • $app->bind('path.public', function() { return __DIR__.'/[ruta_relativa_hacia_el_directorio_publico]'; });

    This way when you put _public_path () _ you will indicate that you want to access the public directory that is in view of all.

        
    answered by 01.07.2017 в 04:23
    0

    Here on this page it is very well explained how you can install laravel inside a shared server, it is valid for most of the cases. Explain how to install How to install Laravel on a shared server I hope it serves you

        
    answered by 08.12.2016 в 16:42