Uploading Laravel from my localhost to godaddy server - php

My set up in localhost works well. I want to upload my Laravel app to my GoDaddy server. I created an FTP to transfer my Laravel app to my GoDaddy server. As what I've noticed upon creating my FTP account the files is inside /webroot so I created a /webroot/testapp inside testapp is my Laravel app. Inside Laravel app, there is a public folder. As what I've research in google other says only inside the public folder must be inside /public_html and Laravel app will be outside. in my case, it is /webroot. Now upon transferring my Laravel app to my server, I did not separate my public folder. I put it also in testapp folder because when I put the public folder outside my testapp folder and edit the index.php file my main site is in WordPress and it will cause an error. So I added the public folder into my testapp folder. When I tried to run in the browser it says 404 (Page Not Found) Error` so I tried to edit my index.php file below
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* #package Laravel
* #author Taylor Otwell <taylor#laravel.com>
*/
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/
require __DIR__.'/../testapp/public/bootstrap/autoload.php';
/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/
$app = require_once __DIR__.'/../testapp/public/bootstrap/app.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
Now can someone help me to work this thing out? I've seen it other tutorials is working well mine is not. Any help is muchly appreciated. TIA

You should upload the whole project from localhost to godaddy and then ask from the support team to edit your hosts pointing to public folder.
This is a shared hosting service , so you can't do it alone. Ask it.

Crete .htaccess in root directory and add this below code:-
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
Hope it helps!

Follow this tutorial it works for any shared hosting plan.

Related

Cannot resolve public path when trying to read barryvh/dompdf in laravel

I deployed a laravel app to shared hosting. Then I separated the folders into two DOMAIN containing the all the other folders and public_html containing the files in the public directory. I then modified index.php file in public like this
require __DIR__.'/../domain/vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request using
| the application's HTTP kernel. Then, we will send the response back
| to this client's browser, allowing them to enjoy our application.
|
*/
$app = require_once __DIR__.'/../domain/bootstrap/app.php';
The app seems to work well, except for some features like the barrydompdf that gives me the error
Cannot resolve public path
Please any idea on how I can fix this. Thank you all in advance.
This is the most stupid error by DOMPDF.
To resolve this error, all you need to do is to create a public folder in project directory, Although it is of no use.
This issue is submitted to DOMPDF Git already and people have found workaround of it.
Go to this path
vendor/barryvdh/laravel-dompdf/src
Edit
ServiceProvider.php
Search for
base_path('public')
and replace it with
public_path()
OR YOU CAN JUST CREATE A PUBLIC FOLDER IN YOUR CODEBASE DIRECTORY
EDIT:
This happens when your code base has no public folder and you have separated your public folder to public_html.
Never edit the content under the vendor folder
Just add this property in your config/app.php
'public_path' => public_path(),
remplace
'public_path' => null
for
'public_path' => base_path()
to file path
/config/dompdf.php
you can see the same topic here
https://laracasts.com/discuss/channels/general-discussion/cannot-resolve-public-path-dompdf

Deploying Laravel PHP site on shared host using GitHub

I've built a Laravel site locally, and everything works wonderfully—but when I've tried deploying it to my shared host (Hostinger), I cannot get everything replicated or set up correctly. The obvious problem is that Hostinger puts the public-facing code in a public_html folder, which my Laravel setup does not have (it has public instead).
Also, I'm using GitHub for version control and (hopefully) deployment. I'm able to connect my GitHub repo directly in Hostinger, but the problem is, it pulls my code into public_html instead of the root.
I'm really sorry if this question/problem is dumb; I'm more of a web designer than developer these days, and I just need a damn portfolio site up and running. :)
Local directory structure:
root
--app
--bootstrap
--config
--database
--node_modules
--public
--resources
--routes
--storage
--tests
--vendor
I've read various articles and posts about either copying contents of public into public_html after uploading the code, and then changing __DIR__ suffixes in index.php; or ways to change public to public_html locally up front...but the former didn't work and the latter scares me since so much of my Laravel workflow using npm run and whatnot utilizes the public dir.
I also don't really want to have my remote and local out of sync. My desired workflow:
code locally <---
| |
npm run dev/watch --
|
npm run prod
|
push to GitHub
|
deploy to host
|
enjoy fresh website without any changes to remote files on host :)
You don't want to move the contents of public to the root and serve your app from the root because you will expose important config files such as .env.
Create another .htaccess in your root with the following contents:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Which will rewrite all of your urls to the public directory. This should work in the local and production environment.
Have you tried to change public path in Laravel :
See answer here maybe this is a solution.

laravel 5.6 host to cpanel on shared hosting

How can a host a Laravel 5.6 app to cpanel on a shared hosting.
Can someone give me an idea
require __DIR__.'/../vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/
$app = require_once __DIR__.'/../bootstrap/app.php';
/*
\#########my index.php file
You have two methods available, one requiring ssh access. Under no circumstances do you put your entire Laravel directory into the public_html directory.
SSH Access
If you have SSH access you'll want to do the following;
Log into your account and go to your home directory cd ~
Delete the public_html directory
Now you want to upload your Laravel app to ~/laravel
Now you need to recreate public_html as a symlink cd ~ && ln -s laravel/public public_html
No SSH Access
If you don't have SSH access you'll want to do the following;
Upload your laravel installation to somewhere like ~/laravel (above the public_html)
Copy the contents of the ~/laravel/public directory to public_html
Change the path to match your new destination
Your new ~/public_html/index.php should look like the following;
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* #package Laravel
* #author Taylor Otwell <taylor#laravel.com>
*/
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/
require __DIR__.'/../laravel/vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/
$app = require_once __DIR__.'/../laravel/bootstrap/app.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
after googling around i found that you have to take content of public folder which has index.php file and put it in public_html. now we have to change the content of index.php file i.e just provide the right link of app.php and autoload.php which would be require __DIR__.'/<project_folder_name>/vendor/autoload.php' and $app = require_once __DIR__.'/<project_folder_name>/bootstrap/app.php'; also update your .env file and check it should work if it doesnt you have to clear cache and routes using php artisan cache:clear and php artisan route:clear you can do this using ssh or define the function in web.php and then hitting the link
An easy way if your shared hosting team is very supportive for you,
Upload your files to public_html folder, and then incase if you donot have ssh access to server, contact your hosting team and ask them to point your domain name to public_html/public folder as root folder.
And then ask them to execute following command via ssh
composer install
If you want to boost the peformance, please provide them the four commands listed in the following article.
https://www.techalyst.com/links/read/112/boosting-laravel-performance-in-production-server
Laravel 5.6 requires PHP 7.
First check your shared hosting support PHP 7 in Cpanel (PHP Selector), if yes but you have other projects which PHP 5 and you don't want to change default php version, then use this in .htaccess file
For example: public_html/abc/.htaccess
RewriteEngine on
AddHandler application/x-httpd-php71 .php
Then PHP 7 Work and you can work with Laravel 5.6 on shared hosting
laravel -> all laravel file
public_html -> move all folder & file on *public* file laravel to *public_html*
change your index.php on public html
require __DIR__.'/../laravel/vendor/autoload.php';
$app = require_once __DIR__.'/../laravel/bootstrap/app.php';
don't forget to change your php version to 7.2
The simplest way to host on shared hosting
Create a subdomain on hosting and map it to a folder e.g: "abc"
In folder "abc" upload laravel project zip (with vendor folder) then extract it
Map subdomain to the public folder of laravel i.e. "abc/public".
Create a database & user and assign that user to the database with all privileges
Import the DB dump in the database created above.
Add DB user/password in laravel .env file.
Note: If you face any due to cache remove file config.php in directory bootstrap/cache.
Umm. Shared hosting does NOT support php 7, which larave 5.6 depends on. Have you guys found a workaround. I have been stuck for months with laravel 4.x on bluehost.

Laravel project deployment gives the HTTP ERROR 500

Before you assume, I did read ALL other posts on this problem and I was unable to find a solution to my problem.
So the thing is, however and wherever i upload my files and folders on my web host i get the same result giving me the "currently unable to handle this request. HTTP ERROR 500". I'm using the 000webhostapp.
So I uploaded the project in my root directory "/", content of the public to the public_html project, and it gave me the text above. Then I tried moving my whole project into the public_html(public was its own directory inside public_html) and it gave me the same result. I've tried some solutions with .htaccess file but whatever I tried won't make it work. In my localhost project is installed somewhat like this "htdocs/kola/..", but on the web hosting it is just in the root, no other dir(that's something I think might help but I'm unable to use). So after 30 hours of trying and reuploading the project 5 times, still can't make it work and I'd be rather grateful if someone could even try to help me with this.
Thanks in advance
The right way is to get to the root of your folder ... ie /home/ and create a folder for your project. Then move the all the contents of your project into this folder except the public folder. Now go to the public_html folder and add all the contents of the public folder there.
Update your index.php as below:
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* #package Laravel
* #author Taylor Otwell <taylor#laravel.com>
*/
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/
require __DIR__.'/../(name of your root folder)/bootstrap/autoload.php';
/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/
$app = require_once __DIR__.'/../(name of your root folder)/bootstrap/app.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
Configure the .env file and have the right database configuration.
Need not to create new dir. Just delete the content of index.php file and paste the above code and replace your (name of your root folder) with public_html.

Install laravel in shared hosting website's subfolder

im trying to install Laravel in my shared hosting website's(which is not laravel) subfolder.
for example in: example.com/dev
Structure:
->laravel
->app
->bootstrap
->public_html
...example.com folders & files
->dev
->css
->js
->.htacess
->index.php
... other Laravel public files
My example.com/dev/index.php looks like this:
... laravel codes
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/
require __DIR__.'/../../laravel/bootstrap/autoload.php';
/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/
$app = require_once __DIR__.'/../../laravel/bootstrap/app.php';
... laravel codes
Problem:
When i try to enter http://example.com/dev/ browser throws error:
This page isn’t working
mysite.com didn’t send any data.
ERR_EMPTY_RESPONSE
THERE ARE NO ANY INFORMATION/SOLUTION FOR THIS PROBLEM IN THE INTERNET.
ANY SOLUTION?
Your entire project should be inside your public_html folder. Then move all the contents of your public folder to public_html as well. Then edit your index.php to match the proper directory for autoload.php and app.php
From your text I assume you want call Laravel via http://example.com/dev/ If you hoster allows symlinks, you can try this.
-> laravel
-> app
-> ...
-> public // symlinked to public_html/example.com/dev
-> ...
-> public_html
-> example.com folders & files
-> dev // This is a symlink to laravel/public
A better approach in my opinion would be to create a subdomain and call Laravel like http://dev.example.com. It depends on your hoster how you can do this.

Categories