How to setup laravel 7 on shared hosting? - laravel

I recently transposed an existing web site from symfony to laravel for which I am a newbie.
At the moment my site is running with Laravel locally using the embedded server.
I created a repo on github and pushed my site on it.
Then I connected to my site via ssh and cloned the github repo on the remote server (shared hosting).
I created a .env file from the .env-example remotly.
I created a subdomain that points to the public folder of the cloned site.
I modified a line in public/index.php to
$app = require_once __DIR__.'/bootstrap/app.php';
I launched a composer update command and then run
php artisan key:generate it returned success but I couldn't find any key in the .env file thus I used the same key I use locally.
When I visit the subdomain I get a page like this one:
Index of / Name Last modified Size Description cgi-bin/
2020-09-13 15:23 -
I very probably missed something

Related

This page isn’t working, Currently unable to handle this request. HTTP ERROR 500 on Laravel

Before Laravel, I have been using the MVC Web Framework and success to host in cPanel server.
Now, I decide to upgrade my Framework. So I find Laravel because it also included MVC patterns and easy to learn for me. Seeing some tutorials, I decided to host a simple project of Laravel on a subdomain of my main domain sites.
What I did:
On server:
I create a subdomain and set the document root to /public_html/subdomain.maindomain.com/public.
Inside the public_html folder, I created a folder and renamed as just like to subdomain name.
On My Computer
composer global require laravel/installer
laravel new website
php artisan serve
Now, I get the Laravel homepage on browser link http://127.0.0.1:8000.
Then, I added bootstrap.
composer require laravel/ui
php artisan ui bootstrap --auth
npm install && npm run dev
Then, I see the login and register link on the Laravel homepage.
Now, seeing https://laravel.com/docs/8.x/deployment documentation of Laravel:
composer install --optimize-autoloader --no-dev
php artisan config:cache
php artisan route:cache
php artisan view:cache
Now, I uploaded the zip file (all files inside the website folder) and extracted it to server document root /public_html/subdomain_name/. In the subdomain_name folder, I have all the files that were in my website folder on my computer.
I don't change anything on the index.php file of the public folder, remain on default condition.
require __DIR__.'/../vendor/autoload.php;
$app = require_once __DIR__.'/../bootstrap/app.php';
Then, I check my URL but I faced This page isn’t working, subdomain.domain.com is currently unable to handle this request. HTTP ERROR 500
First of all upload the laravel to your domain root folder and not public_html and extract, then move the content of the public folder of your laravel to /public_html/subdomain.maindomain.com/public then edit the content of the index.php require __DIR__.'/../vendor/autoload.php'; equire_once __DIR__.'/../bootstrap/app.php'; to this require __DIR__.'/../../../laravelpackagename/vendor/autoload.php' and $app = require_once __DIR__.'/../../../laravelpackagename/bootstrap/app.php';
Not tested but I believe this should work
How did I solve this error:
I re-create the Laravel new project just like the above command and put that file to my server path to /public_html/laravel/. Therefore, I didn't change anything on the index.php file on the public folder, remain to the default condition. By doing this still error remains same (HTTP ERROR 500).
Then, I look at the error_log file at /public_html/laravel/public/, and see an error Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) in public_html\laravel\vendor\ramsey\uuid\src\functions.php line on 34.
In cPanel MultiPHP Managers, I select my sites and set the PHP Version to the same version it has before [PHP 7.3 (ea-php73)]. Then, BOOM!! It worked. I see the homepage of my laravel project in the URL.
In brief, selecting the same PHP Version in cPanel MultiPHP Managers, help me to solve this error.

how to Deploy VueJS, laravel App on live server

i want to deploy the App of laravel with inbuilt vuejs
on my local i just run the "PHP ARTISAN SERVE"
and boom its works for me
but what about the live ?
its not working on live server
my .htaccess and index.php is in public folder
for Laravel we just move the index.php and .htaccess out of public folder and edit some code lines and it will work.
but how it will work with vuejs templates ?
Follow these steps:
Please create a zip folder of your project except the vendor folder.
Deploy the folder on live and extract.
Change your DB and other configuration in env file.
In the terminal on live server, run this command : composer update
After the installation, look for your front page.
Hope it should work fine.

Creating symlink setting up Laravel 5.6 on a remote server

I'm setting up a Laravel 5.6 site in a remote shared hosting server.
I'm failing at creating the storage symlink. I'm executing a file with the following line (as Laravel documentation and other tutorials instruct):
symlink('/home/nataliag/laravel/storage/app/public', '/home/nataliag/public_html/storage');
this creates a symlink, but instead of getting my images with mydomain.com/img/..., i have to go mydomain.com/storage/img/....
what link the php artisan storage:link creates? because that works in local, and all my links are created following that structure

How to deploy Laravel 5.5 on shared hosting without composer

I am trying to deploy a Laravel project on shared hosting. I copied the Laravel folder in user's root directory (/home/shrpr) and copied the content of public directory in /home/shrpr/www folder. I modified the index.php in public folder to include "../Laravel" as explained in site. Since, composer is not allowed on this shared hosting, I also copied my local vendor and storage folder along with laravel folder. But I still keep on getting error 500. So, I added a test.php file in the laravel folder and included it in index.php file to test if path and all is correct as under:
require __DIR__.'/../laravel/test.php'; die;
This works fine as the content of test.php is getting displayed properly. So, it looks like some dependencies of vendor folder is missing. Is there a way of identifying and uploading complete dependencies of laravel and uploading it, that is without use of composer?
Try composer update before upload to shared hosting.
Change permissons of your index.php to 644.
Check your enviroment, maybe isn't works.
Wich version of php is running in your shared hosting? and wich is yor Laravel version, change php version to 7.0
Make sure you have PHP 5.5+ installed on the server. Move the index.php file from public to www and change the paths accordingly.
Another way to deploy laravel on shared hosting is to set up your domain as addon domain and then set root folder of the addon domain to the /public folder of the laravel project. eg. home/mili/laravelproject/public
I tried this with godaddy and it worked.

Lumen not working out of the box

Just installed Lumen framework.
hit the link http://localhost/lumen/public/ in my browser and got this following error, anyone got any idea about it?
Traced it back to the app.php file in bootstrap folder.
if You want to access lumen project without "php artisan serve"
$app->run(); replace with
$request = Illuminate\Http\Request::capture();
$app->run($request);
from this path yourlumenproject/public/index.php
Open your terminal in the root folder run the following command php artisan serve.
Lumen development server started on http://localhost:8000/
if you want to serve your app in local development you can do this :
php -S localhost:8000 -t public/
and it will serve in localhost in port 8000. hope this help.
Note : I'm using Laravel Framework version Lumen (5.2.4) (Laravel Components 5.2.*)
At the moment Lumen only runs in the domain root.
(I've submitted a PR that fixes this but it has yet to be merged)
You have to create a Virtual Host on your local webserver and point the document root of that to the public directory. After that you can access your app with something like: http://lumen.dev.
Guide for Virtual Hosts with nginx
Guide for Virtual Hosts with Apache
A simple alternative to setting this up manually is Laravel Homestead. It is an official Vagrant box made for Laravel, that allows you to easily get your development environment up and running.

Resources