UPDATE (7 Jan 2016): Added a final step for pointing domain to subfolder.
UPDATE (4 Apr 2016): I’ve received a number of enquiries with this setup. Please test it on your local environment first. Use homestead to create a domain with the same folder structure. If it’s working on homestead, it’ll most likely work on your shared server.
UPDATE (15 Jun 2016): Added some common problems found from the lovely comments. Scroll to the bottom to see
In this tutorial, I’ll show you some guide to deploy your Laravel 5 application onto a shared hosting server.
By default, the Laravel folder structure assumed that the public folder is within the application itself. This is the high level folder structure:
your_app_name |--app |--bootstrap |--config |--database |--public |--assets |--index.php <--we need to point here |--resources |--storage |--tests |--vendor
In an ideal scenario, you can simply point the web domain to the public folder so that the URL loads public\index.php.
However, in a shared hosting server, you are limited to putting your web serving files in a folder probably named public_html or www which is publicly accessible via web domain. You may be tempted to do this (NOT recommended):
shared_hosting_root_NOT_recommended |--other_folders (not accessible via web domain) |--public_html |--your_app_name |--app |--bootstrap |--config |--database |--public |--assets |--index.php <--we need to point here |--resources |--storage |--tests |--vendor
You can then point your web domain to the public folder.
The problem with this is that your application is now publicly accessible and that may expose vulnerability. You cannot be sure if someone somewhere is able to access your config folder and look at all your sensitive information such as database credentials.
Instead, put your application root into a folder outside of public_html, and place only the public folder within public_html.
This is the recommended folder structure:
shared_hosting_root_recommended |--other_folders (not accessible via web domain) |--applications (not accessible via web domain) |--your_app_name |--app |--GoPublic.php <--we'll create this |--bootstrap |--config |--database |--public <--copy content to public_html |--assets |--index.php |--resources |--storage |--tests |--vendor |--deploy.sh <--we'll create this |--public_html |--your_app_name |--assets |--index.php <-- we need to point here
In Laravel 4, you can easily tell your application that the public folder is now in another location by simply changing the file bootstrap/path.php. See point 9 of my Laravel 4 tutorial.
However, in Laravel 5, this file no longer exists. I’ll show you how.
1. Create a class to point to new location
Create a new file shared_hosting_root\applications\your_app_root\app\GoPublic.php
<?php namespace App; class GoPublic extends \Illuminate\Foundation\Application { /** * Get the path to the public / web directory. * * @return string */ public function publicPath() { return $this->basePath.DIRECTORY_SEPARATOR.'../../public_html/your_app_name'; } }
We’re using relative path here so you don’t have to know the absolute path. But it is extremely crucial to follow the same recommended folder structure I’ve mentioned earlier.
Updated:
You may need to run the following command in your root folder to autoload the new class. Otherwise you will get an error saying the class cannot be found.
composer dump-autoload
2. Edit bootstrap\app.php
Now we need to tell our application the location of the new public folder. Open and edit your_app_name\bootstrap\app.php:
<?php /* -- remove/comment this original code $app = new Illuminate\Foundation\Application( realpath(__DIR__.'/../') ); -- until here */ /* -- add this new code -- */ $app = new App\GoPublic( realpath(__DIR__.'/../') );
As you can see above, we’re using the new class that we’ve created in step 1.
3. Edit public\index.php
You need to edit these 2 lines.
From line 21:
require __DIR__.'/../bootstrap/autoload.php';
to
require __DIR__.'/../../applications/your_app_name/bootstrap/autoload.php';
And from line 35:
$app = require_once __DIR__.'/../bootstrap/app.php';
to
$app = require_once __DIR__.'/../../applications/your_app_name/bootstrap/app.php';
4. Copy public to public_html
Now, copy the content inside applications\your_app_name\public into public_html\your_app_name.
To simplify the process, I would create a bash file to automatically copy the files to the new location.
Create a new file shared_hosting_root\applications\your_app_name\deploy.sh
#!/bin/bash echo "Copy public folder to public_html/your_app_name" rsync -rv ./public/ ../../public_html/your_app_name
Using rsync ensures that if you ever run this deploy.sh several times, only those that are newer will be copied to the new location.
When you’re ready to run it, in the terminal run:
?> cd applications\your_app_name ?> sh deploy.sh
Caution: You have to run deploy.sh within applications\your_app_name, otherwise it will fail.
5. Accessing your app
There are 2 ways of accessing your application from the hosting server. You need to follow either one of the following step depending on your setup.
5a) Using subdomain
The easier way of accessing your application is to set up a subdomain (e.g. your_app_name.example.com) and point it to your application folder (i.e. public_html/your_app_name). This should automagically work without much hassle.
5b) Using primary domain
The other (slightly more complex) way is to point your primary domain (e.g. example.com) to your application folder (i.e. public_html/your_app_name).
By default, the primary domain points to the folder public_html in most of the shared hosting environment.
To do that, you need to create (or edit if it’s already there) a .htaccess file inside the public_html folder.
WARNING: If .htaccess already exists, DO NOT remove the defaults. Simply append these beneath the existing lines. If you’ve copied laravel’s .htaccess to this folder, DO NOT remove the defaults. Append these beneath the existing lines.
6. Em…
And that’s it.
I would also recommend using the same folder structure during your development so that you can experience the whole process of deployment before you upload to your hosting server.
Hope this helps!
7. Common Problems
There were a few cases of the following that may cause your Laravel 5 to not work on your live server:
- Your PHP version is lower than 5.5.9. Laravel 5 requires PHP 5.5.9 and above.
- Your folder structure is different. Make sure your local test environment is exactly the same as your live server. Starting from your server’s root folder.
- Re-read the whole tutorial. I find that some of my codes were truncated, so make sure you copy and paste correctly. Try scrolling left and right to see the full code line. Sorry about that.
Chace Hwanjoo Kim
December 9, 2015This does not work in my case. I followed everything that you have done in this tutorial. Any suggestions? i get 403 forbidden errors..
Andrews Ang
December 9, 2015Hi there. 403 error may be due to folder access permission. Have you tested the folder structure in your local environment? Also check that your “storage” folder is given full write permission.
Chace Hwanjoo Kim
December 10, 2015Thank you for your reply I got it working. In my case I had to configure my .htaccess to point to the subfolde. Great tutorial by the way keep up the good work! cheers
Andrews Ang
December 10, 2015Glad it worked! 🙂
Jeet Dholakia
June 25, 2016Even after changing my .htaccess file I am still getting 4.3 for subfolder. Please help.
Andrews Ang
June 27, 2016Hi, what’s 4.3? Do you mean 403?
If it’s 403, you need to check if your app’s “storage” folder has write access. Also that the subfolder you’re pointing to must be within the public folder, e.g. “www” or “public_html” (depending on your hosting provider).
Jeet Dholakia
June 27, 2016Sorry that was typing mistake. It was 403 and I solved that error. I placed the .htaccess file in public_html folder but now the thing is the site is not showing me anything. You can check the site: http://www.askurpro.in
Andrews Ang
June 27, 2016Have you tried echoing from your index.php and see if it produces anything? What’s your .htaccess look like? Did you try out your settings on a local environment with the same folder structure first?
Andrews Ang
June 27, 2016Have you tried echoing from your index.php and see if it produces anything? What’s your .htaccess look like? Did you try out your settings on a local environment with the same folder structure first?
Umaha
January 6, 2016I get 500 Internal Server Error. I followed everything to the letter. Any suggestions. Please this is kinda urgent. Thanks in advance
Andrews Ang
January 7, 2016500 internal server error is a general error, did u managed to get a new Laravel installation working? Try to create a local environment (with folder structure) that is similar to your shared hosting server, then test that the Laravel installation is working, before porting over to the production site.
Andrews Ang
January 7, 2016Also, as mentioned by previous commenter, you need to have a .htaccess in public_html folder to point to the subfolder public_html/your_app_name. That could be the problem.
Angga
January 9, 2016Just recently having this problem as well when deploying my laravel app to my shared hosting. here’s what i did to solve the issue:
open .htaccess in your public/ directory and write:
RewriteBase /
you should not get the 500 internal server error anymore.
Andrews Ang
January 9, 2016Hey Angga, thx for that! I’ve read that somewhere but couldn’t get it to work myself. Will u be able to show us your full .htaccess ?
Umaha
January 10, 2016I got mine working. In cpanel, change php version to 5.5 and set php extensions to default. That should do it.
Andrews Ang
January 10, 2016Thanks for sharing! 🙂
Michael Coman
February 7, 2016Hey there, i’ve tried installing laravel on my share webhosting the only downside is that it doesn’t recognize my Models. To be more specific when i try to access the index page it says FatalErrorException in BaseController.php line 92:
Class ‘App\Model’ not found. Any thoughts would be much appreciated. Cheers
Mentioning that i’ve done this tutorial step by step, with one minor detail ( i put the public/ files directly in the public_html/ directory and modified htaccess and other files accordingly). Mentioning as well i don’t have access to any php artisan commands, any ssh command for any of that matter. Cheers
Andrews Ang
February 8, 2016Hi Michael,
Did you create a development environment to test your folder structure? If not, try using Homestead and create the exact folder structure and make sure it’s working first. It’s easier to debug in local environment.
Also, if you don’t have SSH or Artisan commands access, did you run composer install in your local environment before uploading to your shared hosting server? There could some file missing during the upload.
To clarify, did you create a new class “Model” in “BaseController”? Or is it the default Laravel’s Eloquent Model class? If it’s the default class, then probably the composer install didn’t run probably.
Just to be on the safe side, I would always test the folder structure with a brand new Laravel install so that I know the shared hosting server supports it.
Michael Coman
February 8, 2016I have tested it locally and it works, Model was a generic model name i used to paste the error. The model name is SiteCategories and i’ve used it to generate my category tree insite. So i am kinda stuck. Cheers
Andrews Ang
February 8, 2016I see. Have you checked the casing of your file and folder names?
I’ve got problem with my local environment (Mac OS) which was set to be case-insensitive.
But since most shared hosting are using Linux, all file names are case sensitive.
Try looking at the file path against the namespace and class. See if that’s the issue.
Clue: If your full namespace is “App\Model\Subfolder\SiteCategories“, then the full path must match the casing like this
“app\Model\Subfolder\SiteCategories.php“.
Take note that the folder “app” need not be in upper case because Laravel has been configured to read from that folder by default.
Michael Coman
February 8, 2016One of mg hunches would be that i can’t run the composer dump-autoload command so it would update its paths. They don’t quite match with the hostings paths. Having said that, if i don’t have ssh commands available won’t the config cache and any other caches “disable” the project ?
Andrews Ang
February 8, 2016Hi Michael,
Try to set up a local environment that has the same path as the hosting server. Once you’ve run composer update, the autoloading file will be updated in your local environment. That path is relative. So when you upload to your hosting server, it should work. The crucial step is to have the exact path replicated on your local machine. Are you using Laravel Homestead for development?
Andrews Ang
February 8, 2016What does your hosting server folder structure look like? Maybe I can try to map out a similar structure in Laravel.
Michael Coman
February 9, 2016Heya,
Thank you for the quick replies. Sadly i’m not going home tonight so i can’t paste you the details. Will get back to you asap. But the structure is something along the lines of \home\public_html\.
Abiodun Sulaiman
February 9, 2016Good day all,
Thanks for this great post.
I followed this post every step of the way.
I could access something like example.com/my_app_name
example.com/my_app_name/sub_folder gives a 404 not found error
e.g. a login redirect from example.com/my_app_name to example.com/my_app_name/auth/login returns 404 not found error.
I believe I’m quite close to achieving this.
Please, help.
Thank you.
Umaha Tokula
September 6, 2016Hi were you able to make this work. If you did pls share
Gunel
September 3, 2017Hi i have the same problem now and coul not find solution if you have solved can you share with me pls?
Michael Coman
February 10, 2016Somehow i finally managed to make it work, although now my resources aren’t load ( E.x: css/global.css ) and so on. Any thoughts ? Guessing the .htaccess file isn’t how it should be.
Michael Coman
February 10, 2016Hey there,
Managed to make it work somehow but nevertheless the resources aren’t loading at all, no images, no js, nothing …. Although public_path() returns the proper path … Again stuck … Any thoughts ?
Andrews Ang
March 15, 2016Hi Michael, where is your file located? And what does the public_path() says? Have you tried using shortcode url()? For example url(‘assets/css/style.css’) gives your http://example.com/assets/css/style.css.
And make sure your files don’t have any space, if you do, then you need to replace spaces with ‘%20’, for example url(str_replace(‘ ‘, ‘%20’, your_image_path)).
Abiodun Sulaiman
February 10, 2016Good day again,
Please, I need assistance with this:
I could access my laravel site on example.com/my_app_name
But I could not access example.com/my_app_name/sub_folder, it gives me a 404 not found error
e.g. a login redirect from example.com/my_app_name to example.com/my_app_name/auth/login returns 404 not found error.
What am I doing wrong, someone please?.
Please, help.
Thank you.
Andrews Ang
February 25, 2016Hi there,
It’s very tricky to try to access a subfolder URL. This tutorial only works if you’re running from a subfolder but accessing it via a root domain. So I would suggest creating a sub domain for your case.
Example:
my_app_name.example.com
Andrews Ang
February 25, 2016Then you setup that sub domain to point to that sub folder as described in this blog.
Matthew Smart
February 10, 2016Hello i followed you steps and went to 5b way. I am getting the error –
The requested URL /api/index.php was not found on this server.
Andrews Ang
February 25, 2016Where did you place that subfolder /api/? What’s your folder structure?
Jeevan
March 15, 2016Hi guys, I followed every step you recommended except my folder structure starts from app_name but I keep getting 404 error even though I changed Index file to /../../my_app_name/bootstrap/autoload.php.
I kept .htaccess unchanged
Please help me that, if it helps I am using cloud hosting
Jeevan
March 15, 2016Correction from above comment: I changed Index file to ../../my_app_name/bootstrap/autoload.php.
Andrews Ang
March 15, 2016Hi Jeevan,
It could be an error with your .htaccess and index.html.
Can you show me your full folder structure and what you have in index.html and .htaccess?
Jeevan
March 15, 2016Thanks Andrews for quick help.
My folder structure:
Root(FTP Host)
-Application Name
-public_html
.htaccess is same as it is from above code except I replaced app_name and site_address
I think its some thing wrong with my index.php
these are the two modifications I made:
require __DIR__.’/../../myappname/bootstrap/autoload.php’
$app = require_once __DIR__.’/../../myappname/bootstrap/app.php
Andrews Ang
March 15, 2016To be very sure, is this the full structure of your server?
|--myappname
----|--app
--------|--GoPublic.php
----|--bootstrap
----|--config
----|--database
----|--public
--------|--assets
--------|--index.php
----|--resources
----|--storage
----|--tests
----|--vendor
----|--deploy.sh
|--public_html
----|--myappname
--------|--assets
--------|--index.php
Jeevan
March 15, 2016It looks similar to this
|–myappname
|—app
|—-GoPublic.php
|—bootstrap
|—config
|—database
|—public
|—resources
|—storage
|—tests
|—vendor
|–public_html
|—myappname
|—-index.php
|—-.htaccess
Andrews Ang
March 15, 2016I see.
In your GoPublic.php file, is this your path?
public function publicPath()
{
return $this->basePath.DIRECTORY_SEPARATOR.’../public_html/your_app_name’;
}
Replace ‘../../ with just ‘../’ because your folder is 1 level higher than this tutorial.
Jeevan
March 15, 2016Still same error 404, may be i should change some thing in index.php ?
Andrews Ang
March 15, 2016Are you using a subdomain for this application or redirect from a main domain?
Jeevan
March 15, 2016I am just using main domain,
my .htaccess should be working fine because when i try to edit index.php, it was showing me an error in file it means index.php is accessible but the path from there causing the issue
Andrews Ang
March 15, 2016I see. Try these 4 steps.
Step 1:
Edit your public_html/myappname/index.php with the following at the top of the page just after the php opening tag:
echo “OK”;
return;
Refresh the URL and check that you can see “OK” text.
If you don’t see, then your index.php is not pointed correctly.
Andrews Ang
March 15, 2016Step 2:
Below the echo “OK” (before return), add the following lines:
require __DIR__.'/../../myappname/bootstrap/autoload.php';
echo "Done";
Refresh the URL and check that you can see “OK” and “Done” text.
If you don’t see, then your autoload.php path is incorrect.
Andrews Ang
March 15, 2016Step 3:
Below the echo “Done” (before return), add the following lines:
$app = require_once __DIR__.'/../../myappname/bootstrap/app.php';
echo "Finish";
Refresh the URL and check that you can see “OK”, “Done” and “Finish” text.
If you don’t see, then your app.php path is incorrect.
Step 4:
Undo all steps 1 to 3, but this time make sure you have the correct paths for autoload.php and app.php.
Refresh the URL and check that you can see the Laravel home page.
If you don’t see, then your application is not installed correctly. Try running ‘composer update’ again.
Jeevan
March 15, 2016Yes it looks exactly to your comment
Jeet Dholakia
April 3, 2016Hello,
I followed all the steps but getting this error “Fatal error: Class ‘App\GoPublic’ not found”
Please help
Andrews Ang
April 4, 2016Did you run “composer dump-autoload” once so that the class gets registered? If you’ve tried it, check that you have the cases correct and the path be “app/GoPublic.php”. Show me a screenshot of your folder structure and the code in GoPublic.php.
Jeet Dholakia
April 4, 2016I am on Hostgator shared hosting, so can you tell me where to and how to run “composer dump-autoload” ? Folder structure is like: http://www.awesomescreenshot.com/image/1135527/0af5fa619d4cefca16e8bd87bdf93550
Thank you
Andrews Ang
April 4, 2016You need to connect via SSH to run it. If you don’t have SSH access, then you’ll need to run it on your local environment then upload the updated autoload files located inside vendor/composer. Have you tested your folder structure in your local environment first? It’s recommended to test it in homestead first.
Jeet Dholakia
April 4, 2016I have installed composer on my server using SSH but the thing is PHP version is 5.4.45 and its giving me error that php version should be of 5.5. I will test it on local environment. Can you tell me how to test this code on local environment using XAMPP?
Thank you.
Andrews Ang
April 4, 2016Laravel version 5.1 onwards require PHP 5.5.9 or above. You need to contact your hosting provider to see if they support it. As for local environment, try https://laravel.com/docs/5.2/homestead, it’s the best environment because it’s a virtual linux machine.
Jeet Dholakia
April 4, 2016Hello,
I tried running “composer dump-autoload” on the server but still same error.
Andrews Ang
April 4, 2016Can u show me the location of ur GoPublic.php file and its content
Jeet Dholakia
April 4, 2016Here is the location: http://www.awesomescreenshot.com/image/1135853/dddd246c43cf6c95d1b40ceac0146f2e
And the code is:
basePath.DIRECTORY_SEPARATOR.’../../public_html/askurprolv’;
}
}
Andrews Ang
April 5, 2016Hi there, ur Laravel installation isn’t complete. Those files and folders are suppose to be inside a folder “app”. Ur “askurprolv” folder should contain the full Laravel source code.
Jeet Dholakia
April 5, 2016Its inside App folder only. GoPublic.php file is under app folder.
Structure is like: root/application/app/GoPublic.php
Andrews Ang
April 5, 2016Ah, I see. Then should be fine. Can you go to folder “vendor/composer” and look for filename “autoload_classmap.php” and check if ‘App\\GoPublic’ is there? If not, try add this to the array
‘App\\GoPublic’ => $baseDir . ‘/app/GoPublic.php’,
Jeet Dholakia
April 5, 2016It wasnt there in the file, So I added ‘App\\GoPublic’ => $baseDir . ‘/app/GoPublic.php’, at the end. After this do I have to run any commands? because by just refreshing the page its not coming. You can check askurprolv.digitalbrackets.in
Andrews Ang
April 5, 2016That could mean your autoloading is not working. Are you using Laravel 5.2? In that same file, are you able to find “GoPublic” without the namespace? Take a screenshot of your GoPublic.php and public_html/askurprolv/index.php and show me.
Jeet Dholakia
April 5, 2016Yes, I am on Laravel 5.2 only.
GoPublic.php: http://www.awesomescreenshot.com/image/1138937/4dfb7da7492039877b9afc6ee62cc541
Index.php: http://www.awesomescreenshot.com/image/1138944/c8ef023bec8da453330d84800816ebd2
Andrews Ang
April 5, 2016For your index.php line 22, are you missing a “require” in front?
Line 22 should read:
require __DIR__.’/../../applications/askurprolv/bootstrap/autoload.php’;
Jeet Dholakia
April 5, 2016Thank you so much! That solved my error.
Thank you once again for the quick responses.
Andrews Ang
April 5, 2016Glad it worked! 🙂
Eric V. Woods
April 11, 2016Getting a 403 Forbidden error. I gave /storage full read/write rights as suggested above but still get error. Any other suggestions?
Andrews Ang
April 14, 2016Start investigating your public/index.php by going through line by line to see if your shared hosting has given you permission to access any folder outside public_html
Azaz
April 13, 2016Andrews I appreciate that you took time out of your schedule to write this guide, but I would not recommend hosting website on shared server. There is a huge risk to security. Also, the performance will not be really and there might be some limitations as well. There are better alternatives to it, like a managed cloud hosting. Some managed hosting, like Cloudways, offer dedicated hosting with one click installation feature that makes it a lot easier to install and configure application.
Andrews Ang
April 14, 2016Thanks for the suggestion Azaz. This guide merely shows the possibility. The business decision is still up to individuals.
Andrews Ang
April 14, 2016Also, from what I understand, managed cloud hosting have similar folder structure where public_html is accessible by public. So this guide applies too.
Eric V. Woods
April 14, 2016Thanks! I’ll take a look.
Cooke Moore
April 22, 2016Wow. I’d given up on getting Laravel 5.2 running on a CPanel VPS account. While waiting for some big iron services to provision, I found this post and decided to try again. This method is so smart, and still so easy to understand that I was even easily able to adjust the directory structure to my own needs. Thank you for sharing…
Andrews Ang
April 22, 2016I’m glad it worked for you too!
Eduardo Amparo Santana Severino
April 30, 2016Hi every one, my name is Eduardo Santana from Dominican Republic.
I am new to Laravel.
The first moment I saw it, I loved. It was love at first sign.
At the moment I doing very well with Laravel locally, I am Using Wamp Server 3.0. It has PHP 5.6 and PHP 7. And Apache 2.4.
I followed all the steps in this tutorial locally and it is working seamless, like a charm, but on my shared hosting I upload the files, and still can’t make it work.
I have been checking it all again and again but still not working.
Thanks to Andrews Ang for taking time to write this.
I am using Laravel 5.2, on a shared hosting from Justhost.com. I get 500 Internal Server Error.
Any suggestions, Any Advice?
Thanks agains.
Andrews Ang
May 1, 2016Hi, 500 Internal server error is usually due to misconfiguration. Try renaming the htaccess in public folder to something else, then test index.php line by line. Check if there’s any permission error on your app/storage folder.
Eduardo Amparo Santana Severino
May 1, 2016Hi Andrews Ang.
thanks for the quick replay.
it was only after i send this message i started to read all of the comments from the post.
so i realize my problem. which was that my shared hosting had the php 5.4.
so once i chat with the support and they did the change to php 5.6 it worked like a charm.
thank you again.
and
god bless you.
Andrews Ang
May 1, 2016Glad it worked out for you 🙂
Haitham
May 22, 2016I followed everything that you have done in this tutorial but i am getting error “404 not found” on live server only the home page route is working.
Please, Could you help me with that ?
Andrews Ang
June 15, 2016Did it work on your local testing environment? If so, then probably your PHP version may be wrong. You must have at least PHP 5.5.9 for Laravel 5 to work.
Benatry
June 10, 2016please i need an urgent help, i loaded my laravel 5.0 on a shared host. it loaded fine but my js and images are not working correctly. can any one help me. this is how i linked my js .
and below is how i linked my image.
please u can check the files at http://continentalbasiccollege.com.ng/
Thanks in anticipation
Andrews Ang
June 15, 2016Hi, I see your JS and images are loading fine now. How did you fix it?
Jeet Dholakia
June 27, 2016I tried it on my local environment and its working fine. I tried echo “Hi” on my index file and its getting on the page. Here is what my htaccess look like: http://prntscr.com/blmuvu
Andrews Ang
July 4, 2016Sorry for the late reply, I see your site is working now. How did you resolve it?
Lenny
July 7, 2016Andrew, Thanks for writing this guide. I’m new to Laravel and struggling a bit.
In my GoPublic.php, I want to perform an environment check and specify path based on that (I want to develop using my local public directory, and then when I’m ready to deploy just change APP_ENV).
if (App::environment(‘local’)) {
return $this->basePath.DIRECTORY_SEPARATOR.’../public’;
}
This code should check APP_ENV to see if it’s set to local, if it is, use public instead of public_html.
I’m getting an error “Class ‘App’ not found in GoPublic.php”.
I know that App is a Facade so I tried to include it using use App;
It’s still not working. What can I do?
Thanks.
Lenny
July 7, 2016Nevermind, I should have stackoverflow’d.
if (env(‘APP_ENV’) == ‘local’) {
return $this->basePath.DIRECTORY_SEPARATOR.’public’;
}
Source: http://stackoverflow.com/questions/36582298/appenvironment-is-returning-a-blank-page-on-laravel/36583427
Andrews Ang
July 7, 2016Haha, glad you found a solution! 🙂
Lenny
July 11, 2016Andrew,
I was able to get my website working properly using this setup, but my restful API routes are returning 404.
This is an example route in my routes.php
Route::group([‘prefix’ => ‘api’], function()
{
Route::get(‘tester/testMethod’, ‘TesterController@testMethod’);
}
When I try to hit this route, I get a 404.
My site is using a subdomain, for example: test.testwebsite.com/api/tester/testMethod
This route is returning a 404, page not found.
I know that routes.php is being hit, because if I remove this code block:
/*
Route::get(‘/’, function () {
return view(‘index’);
});
*/
Page break occurs.
What can I do to resolve this issue? Thanks a ton for your help.
Lenny
July 11, 2016Just figured out that if I do: test.testwebsite.com/index.php/api/tester/testMethod, it works.
I’ve seen some solutions that use .htaccess to resolve this, but I have no idea how that file works. Researching now…
Lenny
July 11, 2016The solution can be found here:
http://stackoverflow.com/questions/24146969/index-php-still-needed-even-after-htaccess/24147201#24147201
Andrews Ang
July 11, 2016Hi Lenny, if this works, it must be done by your hosting provider. That means they don’t allow htaccess overwrite by default.
Ty
July 19, 2016I follow all your instruction but it still not working.
it show like this when I type by my website
Index of /
cgi-bin/
css/
error_log
favicon.ico
fonts/
index123.html
index1234.php
robots.txt
vendor/
your_app_name/
Apache Server at gmllhatdistribution.com Port 80
Andrews Ang
July 20, 2016Hi, your folder structure is not the same as in my tutorial. Your folder ‘your_app_name’ should be outside the “public_html” folder. And you need to copy the content within “your_app_name/public” into your “public_html” folder. You may want to quickly rename index123.html back to index.html. Otherwise everyone can see your existing folder structure now. Not safe.
Ty
July 21, 2016Hi Andrew,
My web application folder structure is like this
Laravel source location: /application/your_app_name/
index.php location :/public_html/
require __DIR__.’/../../applications/your_app_name/bootstrap/autoload.php’;
$app = require_once __DIR__.’/../../applications/your_app_name/bootstrap/app.php’;
$kernel = $app->make(‘Illuminate\Contracts\Http\Kernel’);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
.htaccess file location in /public_html also
Options -MultiViews
# Do not change this line.
RewriteEngine on
# Change example.com to your domain name
RewriteCond %{HTTP_HOST} ^(www.)?gmllhatdistribution.com/$
# Change your_app_name to the subfolder name
RewriteCond %{REQUEST_URI} !^/your_app_name/
# Don’t change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change your_app_name to the subfolder name
# Change example.com to your domain name
RewriteRule ^(.*)$ /your_app_name/$1
RewriteCond %{HTTP_HOST} ^(www.)?gmllhatdistribution.com$
RewriteRule ^(/)?$ index.php [L]
but I still got the HTTP ERROR 500
Andrews Ang
July 21, 2016Hi TY,
Your index.php path may be wrong. Since your index.php is directly inside “public_html”, your path should be:
require __DIR__.’/../applications/your_app_name/bootstrap/autoload.php’;
$app = require_once __DIR__.’/../applications/your_app_name/bootstrap/app.php’;
Note: Because my folder structure is one step deeper “public_html/my_app”, so yours is “/../applications” instead of “/../../applications”.
HTTP ERROR 500 is a general error, usually tells us that the file is not found.
Ty
July 23, 2016Hello Andrews,
How about my file .htaccess need to change also because I still got error file not found.
Could you help to check it?
Andrews Ang
July 23, 2016Hi Ty, your htaccess has a problem too. You don’t have a subfolder, so u don’t need to follow this. Just replace the htaccess with the one from Laravel public folder.
Leo
July 20, 2016Hi,
I cannot access to the page of my site if I don’t add index.php.
Here is my htacess in my public_html folder :
# Do not change this line.
RewriteEngine on
# Change yourdomain.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?mtlgigs.com$
# Change ‘subfolder’ to be the folder you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/mtlgigs/
# Dont change this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change ‘subfolder’ to be the folder you will use for your main domain.
RewriteRule ^(.*)$ /mtlgigs/$1
# Change yourdomain.com to be your main domain again.
# Change ‘subfolder’ to be the folder you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?mtlgigs.com$
RewriteRule ^(/)?$ mtlgigs/index.php [L]
RewriteCond %{HTTP_HOST} ^mtlgigs\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mtlgigs\.com$
RewriteRule ^/?$ “mtlgigs” [R=301,L]
My former public folder is now in public_html/mtlgigs.
My project is not in a applications folder but directly in mtlgigs.
If I type : mtlgigs.com/login is does not work
If I type mtlgigs.com/index/php/login it works and it redirects me to : mtlgigs.com/mtlgigs/index/php/login
If I try with a test file : mtlgigs.com/test.php it works
What can I do to access to my site without typing index.php
Andrews Ang
July 20, 2016Hi Leo, that means your .htaccess is not set up correctly. I’m sorry I can’t help you if you’re not following my folder structure, it’s very difficult to see what you’re trying to do from my end.
leo
July 20, 2016Hi Andrews, I’ve changed the structure so it follow yours still the same problem Here is my config> I’m using Mamp Pro, my Document Root is pointing to htdocs/public_html to mimic what it is done with shared hosting.
My app is located inside htdocs/applications/mtlgigs
The content of my former public folder is located htdocs/public_html/mtlgigs
Inside public_html I have a .htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?localhost$
RewriteCond %{REQUEST_URI} !^/mtlgigs/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mtlgigs/$1
RewriteCond %{HTTP_HOST} ^(www.)?localhost
RewriteRule ^(/)?$ mtlgigs/index.php [L]
Inside htdocs/applications/mtlgigs I have a .htaccess
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
I also created the GoPublic.php in htdocs/applications/mtlgigs/app. (Didn’t type composer dump-autoload and didn’t have a error)
basePath.DIRECTORY_SEPARATOR.’../../public_html/mtlgigs’;
}
}
The file app.php contains
* — add this new code — */
$app = new App\GoPublic(
realpath(__DIR__.’/../’)
);
The index.php in applications/mtlgigs is
/**
* Laravel – A PHP Framework For Web Artisans
*
* @package Laravel
* @author Taylor Otwell
*/
$uri = urldecode(
parse_url($_SERVER[‘REQUEST_URI’], PHP_URL_PATH)
);
// This file allows us to emulate Apache’s “mod_rewrite” functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a “real” web server software here.
if ($uri !== ‘/’ && file_exists(__DIR__.’/public’.$uri)) {
return false;
}
require_once __DIR__.’/public/index.php’;
The index.php in public_html/mtlgigs is
require __DIR__.’/../../applications/mtlgigs/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__.’/../../applications/mtlgigs/bootstrap/app.php’;
If I type http://localhost/login I have
Not Found
The requested URL /mtlgigs/login was not found on this server.
If I type http://localhost/index.php/login it is working and the URL CHANGE to http://localhost/mtlgigs/index.php/login
Thanks for your help 🙂
leo
July 20, 2016I forgot to highlight the fact that if I go type : localhost/test.txt it displays my file which is located in public_html/mtlgigs/test.txt
But when I want to reach laravel it does not work without index.php
Andrews Ang
July 21, 2016Hi Leo,
I think the problem lies in the .htaccess file that is not pointing to your index.php file correctly. Can you try 1 level up with this folder structure?
htdocs
— applications
. |– mtlgigs
— public_html
. |– index.php (and all other files copied from applications/mtlgigs/public)
Note that you need to change the path for app/GoPublic.php, and htdocs/public_html/index.php
Replace the .htaccess inside public_html with the one that comes with Laravel inside public folder.
See if you can get the site to work in MAMP Pro first at that level first.
leo
July 20, 2016Also, my other routes are not working localhost/example is not working localhost/another is not working too
Thuy Dung
August 11, 2016thanks very much, but i have a error with GoPublic.php,
Fatal error: Class ‘App\Illuminate\Foundation\Application’ not found =>> that my error.
i did run “composer dump-autoload” but not work, please help me, thanks
Andrews Ang
August 11, 2016Hi Thuy, I think you’re missing a slash in front.
Instead of “Illuminate\Foundation\Application”, type “\Illuminate\Foundation\Application”.
If you leave out the slash in front, Laravel will try to look for the class within the current folder.
Gabriel
August 12, 2016Great, it worked perfectly. Just a question, only works if I put in the url ‘index.php’, there is any way that works without the index.php?
Andrews Ang
August 12, 2016Hi Gabriel, it’s under point 5, you need to either using a subdomain or change your public_html’s htaccess to direct to the subfolder. Currently I’m still figuring out how to make it work as a subfolder of a domain, but so far no outcome yet.
Gabriel
August 13, 2016Andrews thanks for answer. I also created the subdomain but doesn’t work. If I put ‘http://mysubdomain.mydomain.org/index.php/api/v1.0/productos’ works, but if I put ‘http://mysubdomain.mydomain.org/api/v1.0/productos’ without index.php doesn’t work
Andrews Ang
August 13, 2016Is there a .htaccess file within ur folder? Check if the hosting server allows htaccess override
Gabriel
August 19, 2016No there isn’t. With the subdomain must have?
Andrews Ang
August 19, 2016Hi Gabriel, yes, Laravel’s public folder comes with a htaccess file, that’s for resolving the /index.php/ problem you’re having. Copy that into your public_html/myapp/ folder and it should work.
Ethan
August 12, 2016Hi Andrew thanks for your detailed explanation, but my application is not working, instead I get a blank page when I type the sub-domain which points to the application folder in public_html.
I have tried to test the index.php with an echo message, but I still get a blank screen, then I replaced the index.php codes line by line and I got the echo message, but whenever I add the final code shown below, all echo responses from the index.php disappears.
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
Please what could be the problem?
P.S:
I’m using Laravel 5.0
Andrews Ang
August 12, 2016Hi Ethan, it seems like a correct (blank) result. The final codes are the laravel code, it should be working correctly if your path above is correct. Did you try echoing from bootstrap\autoload.php and bootstrap\app.php as well? See if the files are being called correctly. Are you testing locally or directly on the hosting server? Best to test locally with Homestead first.
Ethan
August 13, 2016I have tried echoing from the autoload.php but it shows a blank page also, I’m testing directly on the hosting server, and I’m using wamp server locally. Also my PHP version is 5.4. could it be the cause?
Umaha Tokula
September 6, 2016Hi Andrew, will this tutorial work for a Laravel 5.3 application?
apluslabs
September 30, 2016its work bro,
i was try in my server.
Andrews Ang
October 6, 2016Thanks for clarifying! I’ve yet to try 5.3. 🙂
Reid
October 6, 2016Hi Andrews! Great tutorial. This may have a simple answer, but would my app work if I just upload my public folder from laravel to my “public_html” folder? I.E. is the public folder a stand-alone “unit” that just works as as-is PHP files?
Andrews Ang
October 6, 2016Hi Reid, yes it should work. The file “index.php” is the main file that will be called automatically by the server if you place the content within the “public_html” folder (provided you don’t have other index.php file). But do note that my examples are not the same, so you need to change certain paths to make it work.
niki2k1
October 9, 2016Can you help me?, I get always a
Parse error: syntax error, unexpected ‘class’ (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or ‘{‘ or ‘$’ in /home/www/doc/7847/dcp78470003/project.niki2k1.de/www/project/index.php on line 50
Also with other Tutorials the same thing?
niki2k1
October 9, 2016Thats on line 50: $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
Andrews Ang
October 10, 2016Hi, your PHP version is probably wrong. That error message sounds like it could be because of PHP 5.5’s class name resolution. Have you checked your PHP version? From Laravel 5.1 and 5.2, you need at least PHP 5.5.9. For Laravel 5.3, you need at least 5.6.4.
Edwin
October 30, 2016Hi. Thank you so much for this guide. It worked for me but I have an extra issue. What if I want to do all of this AND redirect all http:// to https://
Any help will be much appreciated. Sorry for my bad english.
Andrews Ang
November 5, 2016Hi Edwin, if you’re using Apache, to redirect http:// to https:// you should use .htaccess instead.
Tom Harrison
November 4, 2016Hi, this works great but I have a problem with the url, It now reads like this http://domain.com/app_name/app/ (displays the index page here)
my folder structure is app_name > 2 folders app(contains public folder)/laravel (contains rest of files)
Andrews Ang
November 5, 2016Hi Tom, my method would only work if the public folder is directly accessed via a domain (e.g. domain.com) or subdomain (e.g. app.domain.com). To make it work for sub folders, you may need to work around the .htaccess configuration at the root domain folder domain.com. I’ve accidentally managed to do it on my own site when I was configuring my wildcard SSL certificate, but I’m not exactly sure which lines worked. Something along these lines:
# Custom subdomain .htaccess SSL + WordPress
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain.maindomain.com$
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteRule ^(.*)$ /subfolder/$1
RewriteCond %{HTTP_HOST} ^subdomain.maindomain.com$
RewriteRule ^(/)?$ subfolder/index.php [L]
# End custom subdomain .htaccess
Andrews Ang
November 5, 2016Your folder structure may expose your core codes to the public, because anyone can access domain.com/app_name/laravel to see your contents. You may want to move the laravel codes to somewhere not accessible by the public.
Umaha Tokula
November 7, 2016Hi, Everything works fine but images on other pages other than homepage don’t show. My app involves uploading images and when i do, they are uploaded to applications/my_app/public but the pages try to load from public_html/my_app which of course it cannot find.
Any help is appreciated
Andrews Ang
November 8, 2016Hi, are you using the helper url()? Can you echo it and see what it shows?
Stephen Paul Samynathan
November 14, 2016Hi. I tried your method. However when I go to the url, I can only see folder list of that public_html. Any thing that I can do to solve this?
Andrews Ang
November 14, 2016Did you copy the files inside Laravel public folder into your site’s public_html? Inside public_html you should have an .htaccess file and the index.php file. If you see folder list that means there’s no default file (i.e. index.php is missing.
Bjorn
November 14, 2016Hello Andrews
I tried your method, but i get an http 500 error.
When I try the same setting in xampp, offline, it won’t work either. When I go to the public_html folder, the htaccess file is not loaded. I see the structure (so all the maps and folders) but it only contains my_app_name folder. Should the htaccess file also load when I try it on localhost?
Any ideas why it won’t work?
Andrews Ang
November 14, 2016Hi, yes, your htaccess should be loaded on localhost as well. It could be XAMPP issue. Have you checked that Apache is set to allow override? See this solution http://stackoverflow.com/questions/17162214/htaccess-not-working-on-localhost-with-xampp
Bjorn
November 15, 2016Hey Andrews. I followed the instructions in your link. The htaccess file still won’t work. I get this error.
Access forbidden!
You don’t have permission to access the requested object. It is either read-protected or not readable by the server.
If you think this is a server error, please contact the webmaster.
Error 403
Andrews Ang
November 24, 2016Hi, was this error on your localhost XAMPP? For Apache environment the public accessible folder must be within the /var/www or /var/public_html folder. Were you trying to access a folder outside that path?
Bjorn
January 10, 2017Hello Andrew,
I still don’t got the Laravel 5 running. I switched to AllowOverRide all as you told me in the previous answer.
I get the following error:
Warning: require(C:\xampp\htdocs\blog1\public_html\Laravel5/../../applications/Laravel5/bootstrap/autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\blog1\public_html\Laravel5\index.php on line 22
Fatal error: require(): Failed opening required ‘C:\xampp\htdocs\blog1\public_html\Laravel5/../../applications/Laravel5/bootstrap/autoload.php’ (include_path=’C:\xampp\php\PEAR’) in C:\xampp\htdocs\blog1\public_html\Laravel5\index.php on line 22
PHP is running version 5.6.24, which i tested with the following video: https://www.youtube.com/watch?v=NJZNiCf_dyE
Any ideas?
Bjorn
January 11, 2017Forget about my previous post, it works!
Great many thanks!
Francesco Parisi
November 22, 2016I tried a slightly different configuration, my filesystem is organized like so:
-project
–app
–bootstrap
–config
–database
–resources
–storage
–tests
–vendor
–.env
–server.php
-public_html
–index.php
–.htaccess
in short, I don’t need to have a my_app folder in public_html, because I’ve only one app. under /project/app I’ve GoPublic.php
basePath.DIRECTORY_SEPARATOR.’../../public_html’;
}
}
under /project/bootstrap I’ve app.php, with the code correctly edited:
/*
$app = new Illuminate\Foundation\Application(
realpath(__DIR__.’/../’)
);
*/
/* — add this new code — */
$app = new App\GoPublic(
realpath(__DIR__.’/../’)
);
under /project/config I’ve app.php with my domain in url:
‘url’ => env(‘APP_URL’, ‘http://www.my_domain.com’),
under /project I’ve server.php
<?php
/**
* Laravel – A PHP Framework For Web Artisans
*
* @package Laravel
* @author Taylor Otwell
*/
$uri = urldecode(
parse_url($_SERVER[‘REQUEST_URI’], PHP_URL_PATH)
);
// This file allows us to emulate Apache’s “mod_rewrite” functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a “real” web server software here.
if ($uri !== ‘/’ && file_exists(__DIR__.’/’.$uri)) {
return false;
}
require_once __DIR__.’/index.php’;
and .env with my domain in App_URL
APP_URL=http://www.my_domain.com
in /public_html I’ve index.php withe two lines relative to bootstrap wrote like so:
require __DIR__.’/../project/bootstrap/autoload.php’;
$app = require_once __DIR__.’/../project/bootstrap/app.php’;
I also have .htaccess,
# Do not change this line.
RewriteEngine on
# Change my_domain.com to your domain name
RewriteCond %{HTTP_HOST} ^(www.)?my_domain.com$
# Change your_app_name to the subfolder name
RewriteCond %{REQUEST_URI} !^/
# Don’t change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change your_app_name to the subfolder name
# Change my_domain.com to your domain name
RewriteRule ^(.*)$ /$1
RewriteCond %{HTTP_HOST} ^(www.)?my_domain.com.com$
RewriteRule ^(/)?$ /index.php [L]
unfortunately when I try to visit http://www.mydomain.com I receive a connection reset message from Firefox.
I think that the problem is related to the htaccess, where I’m doing wrong?
Andrews Ang
November 24, 2016Hi, in your GoPublic.php, can you try this path instead?
basePath.DIRECTORY_SEPARATOR.’../public_html’;
The ‘../’ should only be 1 since your structure is 1 level shallower than mine.
Also, since you are only hosting 1 application within public_html (and it’s directly there), you don’t have to set domain name.
Simply replace htaccess with the default one from Laravel and it should work automagically.
Cheers,
Andrews
Francesco Parisi
November 24, 2016hi,
I found that a Laravel app is incompatible with Zend Optimizer, I resolved the problem in .htaccess in this way 🙂
php_flag opcache.enable Off
Options -MultiViews
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder…
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller…
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* – [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
Andrews Ang
November 24, 2016Thx for sharing!
violetann
November 24, 2016Just wanted to say thank you, This helped me SO MUCH! I have just got into Laravel 5.3 and I wanted to host my projects on my shared host in a subdomain and this helped me to get it working.
Andrews Ang
November 24, 2016I’m glad it helped! 🙂
Navas
December 23, 2016Thanks buddy, do it L5.2 to godaddy shared hosting.
khactung
December 28, 2016Hi you,
If I create login session for base then can sub project get that session ?
Andrews Ang
January 12, 2017I think it depends on the domain. If it’s a different sub-domain then the session may not work. You may want to look at this link instead: http://stackoverflow.com/questions/26463467/laravel-maintain-a-session-in-subdomain-of-different-server
Alex
December 30, 2016Thanks Andrew! I’m happy to say that it took far fewer steps than I expected:
1) Changed laravel directory structure to work with my shared hosting addon domain.
2) Edited the public index.php with new relative path (“Step 3”)
3) Works!
What tripped me up for a while: need to run
artisan config:cache
artisan cache:clear
before copying files over from local development.
Luítame De Oliveira
January 5, 2017This not work for me. I’m using Laravel 5.3. When try to access an URI the server launch an error 404.
Andrews Ang
January 12, 2017Could be some path issue. Will you share a screenshot of what you have done to all the files and your folder structure? What environment are you using to test it? Homestead?
vivekpadhye
January 9, 2017Why put it outside public_html directory. I tried it inside. Example.
Public_html
|
— subdomain folder
— laravel folder + all contents from public folder outside this folder
then make changes inside index.php & htaccess
and it works.
what are security risks?
Andrews Ang
January 12, 2017Everything within the public_html folder is accessible by the public (any users), if they know the path. If you are hosting the Laravel application in a subdomain (sharing the same public_html folder but in a subfolder), then someone could easily guess the path and try to access it from the main domain (bypassing the Laravel routing). It will still work with .htaccess set up properly, this step is just an additional security layer.
Naranz
February 14, 2017HI Andrews Ang,
It’s a great post. I have followed your instruction to host my application. Everything working fine except favicon.
Khudadad
February 17, 2017I’m getting this error:
This site can’t be reached
arya.appfocus.co’s server DNS address could not be found.
Andrews Ang
July 10, 2017Hi there, DNS issue should be due to propagation delay, not an indication of an error in your code. Did you just set up the subdomain of appfocus.co? You need to wait up to 48 hours for the propagation to complete.
WebWalcien
March 31, 2017Hi. Great article! I’m relatively new to Laravel. I tried to deploy my app as a subdomain and I think I got the setup correctly based on your instructions. Now when trying to access the URL it gives me this error: NotFoundHttpException in RouteCollection.php line 161
I’m hoping you could guide me with this. Do I have to change something in my routes file?
Thanks in advance.
Andrews Ang
July 10, 2017Did your main page (subdomain.example.com) work? If it does then your route may have issue.
Glenn
April 12, 2017I managed to setup this structure. but my routes are not working, sample I have to login with POST (/login)
the server cannot find the route, any solution for this?
thanks.
Andrews Ang
July 10, 2017Did the GET (/login) work? Or just the POST?
Joaquin
May 19, 2017Hi all.
Andrews, congratulations, this is a great input, especially for the security thems.
I only want add, that if you only put all contect of public folder inside public_html, you can dispense with of step 5, avoiding topics of redirection and additional tasks from .htaccess file.
Note: My suggest implies changes on routes of index.php and GoPublic.php file.
Again, thanks for your valuable input.
amberhina
May 24, 2017I need help in robot.txt file. cz .htaccess file is not blocking content .
Andrews Ang
July 10, 2017You may need to contact your hosting provider about the use of .htaccess. Not all hosting provider supports that on sub directories.
Suraj
June 9, 2017Hello Andrews Thank you for such great tut but I facing issue while directing tha app to domain
please check it out for me
Issuing site:
http://buva.in/police/
Error in error log
[09-Jun-2017 06:55:21 UTC] PHP Fatal error: Class ‘App\GoPublic’ not found in /home/buvain/rtn/police/bootstrap/app.php on line 27
Folder structure
http://buva.in/police/err.png
Andrews Ang
July 10, 2017Unfortunately, as of now I’ve not figured out how to use sub-route “/police/” for Laravel. I would use http://police.buva.in in this case. You need to install the Laravel into either the root domain (buva.in) or a sub-domain (police.buva.in). Sub-route (buva.in/police) will not work.
Suraj
July 10, 2017Hello Andrews Are you available for freelance if yes ping me back on my email please
Andrews Ang
November 28, 2017Hi Suraj, I run a development studio. You can contact me via our contact found at https://www.redooor.com/contact. Cheers.
Priska
August 26, 2017Hi Andrew, thank you for your awesome tutorial. I am trying it out now on HostGator.
Well, have you written any tutorial on how to do database migration using php artisan migrate –seed command on a shared hosting ?
I have tried, but it didn’t work. I always get the access denied error despite having given the correct credentials and other things on the .env file.
Andrews Ang
November 28, 2017Hi Priska, sorry for the late reply. If you can’t make the seeding work, maybe try doing it locally and then import the database into your shared hosting database?
reza
September 19, 2017Hello bro
My problem is like other guys. I can access home page but not other routes.
reza
September 19, 2017I found my solution ! My problem was about showing home page and 404 for other routes. Guys be careful that don’t remove default value of laravel public folder .htaccess . It’s the solution 🙂
reza
November 12, 2017Hello
I found the solution of common problem : cant access routes after this tutorial !
Dear author plz add this note that dont remove default .htaccess values in this tutorial.
Andrews Ang
November 28, 2017Hi Reza, ok! Will add that note in. 🙂
aamir khan
December 19, 2017i am getting error access denied for user @ localhost at live server although i granted all permissom to user created db correctly and include user name pwd and db name coorectly in .env still iam geeting error i have all thing php artisan cache:clear route:clear config cache:cache but still getting error
Andrews Ang
December 20, 2017Hi, I think your problem is the file permission for app/storage and cache folder (folder may be different depending on your Laravel version). See the solution from this link https://laracasts.com/discuss/channels/general-discussion/laravel-framework-file-permission-security
Mohammad
March 9, 2018Many thanks Andrews for saving my time.