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.
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.