Setting up Laravel 5 on shared hosting server

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.

# Do not change this line. 
RewriteEngine on 

# Change example.com to your domain name
RewriteCond %{HTTP_HOST} ^(www.)?example.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.)?example.com$ 
RewriteRule ^(/)?$ your_app_name/index.php [L]

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:

  1. Your PHP version is lower than 5.5.9. Laravel 5 requires PHP 5.5.9 and above.
  2. 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.
  3. 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.

151 Comments

  • Chace Hwanjoo Kim

    December 9, 2015

    This does not work in my case. I followed everything that you have done in this tutorial. Any suggestions? i get 403 forbidden errors..

    Reply
    • Andrews Ang

      December 9, 2015

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

      Reply
  • Chace Hwanjoo Kim

    December 10, 2015

    Thank 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

    Reply
    • Andrews Ang

      December 10, 2015

      Glad it worked! 🙂

      Reply
      • Jeet Dholakia

        June 25, 2016

        Even after changing my .htaccess file I am still getting 4.3 for subfolder. Please help.

        Reply
        • Andrews Ang

          June 27, 2016

          Hi, 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).

          Reply
          • Jeet Dholakia

            June 27, 2016

            Sorry 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, 2016

            Have 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, 2016

            Have 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, 2016

    I get 500 Internal Server Error. I followed everything to the letter. Any suggestions. Please this is kinda urgent. Thanks in advance

    Reply
    • Andrews Ang

      January 7, 2016

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

      Reply
    • Andrews Ang

      January 7, 2016

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

      Reply
  • Angga

    January 9, 2016

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

    Reply
    • Andrews Ang

      January 9, 2016

      Hey 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 ?

      Reply
  • Umaha

    January 10, 2016

    I got mine working. In cpanel, change php version to 5.5 and set php extensions to default. That should do it.

    Reply
    • Andrews Ang

      January 10, 2016

      Thanks for sharing! 🙂

      Reply
  • Michael Coman

    February 7, 2016

    Hey 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

    Reply
    • Andrews Ang

      February 8, 2016

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

      Reply
  • Michael Coman

    February 8, 2016

    I 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

    Reply
    • Andrews Ang

      February 8, 2016

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

      Reply
  • Michael Coman

    February 8, 2016

    One 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 ?

    Reply
    • Andrews Ang

      February 8, 2016

      Hi 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?

      Reply
    • Andrews Ang

      February 8, 2016

      What does your hosting server folder structure look like? Maybe I can try to map out a similar structure in Laravel.

      Reply
  • Michael Coman

    February 9, 2016

    Heya,

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

    Reply
  • Abiodun Sulaiman

    February 9, 2016

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

    Reply
    • Umaha Tokula

      September 6, 2016

      Hi were you able to make this work. If you did pls share

      Reply
  • Michael Coman

    February 10, 2016

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

    Reply
  • Michael Coman

    February 10, 2016

    Hey 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 ?

    Reply
    • Andrews Ang

      March 15, 2016

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

      Reply
  • Abiodun Sulaiman

    February 10, 2016

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

    Reply
    • Andrews Ang

      February 25, 2016

      Hi 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

      Reply
    • Andrews Ang

      February 25, 2016

      Then you setup that sub domain to point to that sub folder as described in this blog.

      Reply
  • Matthew Smart

    February 10, 2016

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

    Reply
    • Andrews Ang

      February 25, 2016

      Where did you place that subfolder /api/? What’s your folder structure?

      Reply
  • Jeevan

    March 15, 2016

    Hi 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

    Reply
    • Jeevan

      March 15, 2016

      Correction from above comment: I changed Index file to ../../my_app_name/bootstrap/autoload.php.

      Reply
      • Andrews Ang

        March 15, 2016

        Hi 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?

        Reply
        • Jeevan

          March 15, 2016

          Thanks 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

          Reply
          • Andrews Ang

            March 15, 2016

            To 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, 2016

    It looks similar to this

    |–myappname
    |—app
    |—-GoPublic.php
    |—bootstrap
    |—config
    |—database
    |—public
    |—resources
    |—storage
    |—tests
    |—vendor
    |–public_html
    |—myappname
    |—-index.php
    |—-.htaccess

    Reply
    • Andrews Ang

      March 15, 2016

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

      Reply
      • Jeevan

        March 15, 2016

        Still same error 404, may be i should change some thing in index.php ?

        Reply
        • Andrews Ang

          March 15, 2016

          Are you using a subdomain for this application or redirect from a main domain?

          Reply
          • Jeevan

            March 15, 2016

            I 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, 2016

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

          Reply
        • Andrews Ang

          March 15, 2016

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

          Reply
        • Andrews Ang

          March 15, 2016

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

          Reply
  • Jeevan

    March 15, 2016

    Yes it looks exactly to your comment

    Reply
  • Jeet Dholakia

    April 3, 2016

    Hello,

    I followed all the steps but getting this error “Fatal error: Class ‘App\GoPublic’ not found”

    Please help

    Reply
    • Andrews Ang

      April 4, 2016

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

      Reply
      • Jeet Dholakia

        April 4, 2016

        I 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

        Reply
        • Andrews Ang

          April 4, 2016

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

          Reply
          • Jeet Dholakia

            April 4, 2016

            I 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, 2016

            Laravel 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, 2016

    Hello,

    I tried running “composer dump-autoload” on the server but still same error.

    Reply
    • Andrews Ang

      April 4, 2016

      Can u show me the location of ur GoPublic.php file and its content

      Reply
      • Jeet Dholakia

        April 4, 2016

        Here is the location: http://www.awesomescreenshot.com/image/1135853/dddd246c43cf6c95d1b40ceac0146f2e

        And the code is:

        basePath.DIRECTORY_SEPARATOR.’../../public_html/askurprolv’;
        }
        }

        Reply
        • Andrews Ang

          April 5, 2016

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

          Reply
          • Jeet Dholakia

            April 5, 2016

            Its inside App folder only. GoPublic.php file is under app folder.

            Structure is like: root/application/app/GoPublic.php

          • Andrews Ang

            April 5, 2016

            Ah, 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, 2016

    It 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

    Reply
  • Eric V. Woods

    April 11, 2016

    Getting a 403 Forbidden error. I gave /storage full read/write rights as suggested above but still get error. Any other suggestions?

    Reply
    • Andrews Ang

      April 14, 2016

      Start 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

      Reply
  • Azaz

    April 13, 2016

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

    Reply
    • Andrews Ang

      April 14, 2016

      Thanks for the suggestion Azaz. This guide merely shows the possibility. The business decision is still up to individuals.

      Reply
      • Andrews Ang

        April 14, 2016

        Also, from what I understand, managed cloud hosting have similar folder structure where public_html is accessible by public. So this guide applies too.

        Reply
  • Eric V. Woods

    April 14, 2016

    Thanks! I’ll take a look.

    Reply
  • Cooke Moore

    April 22, 2016

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

    Reply
    • Andrews Ang

      April 22, 2016

      I’m glad it worked for you too!

      Reply
  • Hi 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.

    Reply
    • Andrews Ang

      May 1, 2016

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

      Reply
      • Hi 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.

        Reply
        • Andrews Ang

          May 1, 2016

          Glad it worked out for you 🙂

          Reply
  • Haitham

    May 22, 2016

    I 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 ?

    Reply
    • Andrews Ang

      June 15, 2016

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

      Reply
  • Benatry

    June 10, 2016

    please 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

    Reply
    • Andrews Ang

      June 15, 2016

      Hi, I see your JS and images are loading fine now. How did you fix it?

      Reply
  • Jeet Dholakia

    June 27, 2016

    I 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

    Reply
    • Andrews Ang

      July 4, 2016

      Sorry for the late reply, I see your site is working now. How did you resolve it?

      Reply
  • Lenny

    July 7, 2016

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

    Reply
  • Lenny

    July 11, 2016

    Andrew,

    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.

    Reply
  • Ty

    July 19, 2016

    I 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

    Reply
    • Andrews Ang

      July 20, 2016

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

      Reply
      • Ty

        July 21, 2016

        Hi 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

        Reply
        • Andrews Ang

          July 21, 2016

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

          Reply
          • Ty

            July 23, 2016

            Hello 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, 2016

            Hi 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, 2016

    Hi,

    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

    Reply
    • Andrews Ang

      July 20, 2016

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

      Reply
      • leo

        July 20, 2016

        Hi 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 🙂

        Reply
  • leo

    July 20, 2016

    I 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

    Reply
    • Andrews Ang

      July 21, 2016

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

      Reply
  • leo

    July 20, 2016

    Also, my other routes are not working localhost/example is not working localhost/another is not working too

    Reply
  • Thuy Dung

    August 11, 2016

    thanks 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

    Reply
    • Andrews Ang

      August 11, 2016

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

      Reply
  • Gabriel

    August 12, 2016

    Great, 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?

    Reply
    • Andrews Ang

      August 12, 2016

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

      Reply
      • Gabriel

        August 13, 2016

        Andrews 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

        Reply
        • Andrews Ang

          August 13, 2016

          Is there a .htaccess file within ur folder? Check if the hosting server allows htaccess override

          Reply
          • Gabriel

            August 19, 2016

            No there isn’t. With the subdomain must have?

          • Andrews Ang

            August 19, 2016

            Hi 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, 2016

    Hi 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

    Reply
    • Andrews Ang

      August 12, 2016

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

      Reply
      • Ethan

        August 13, 2016

        I 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?

        Reply
  • Umaha Tokula

    September 6, 2016

    Hi Andrew, will this tutorial work for a Laravel 5.3 application?

    Reply
    • apluslabs

      September 30, 2016

      its work bro,
      i was try in my server.

      Reply
      • Andrews Ang

        October 6, 2016

        Thanks for clarifying! I’ve yet to try 5.3. 🙂

        Reply
  • Reid

    October 6, 2016

    Hi 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?

    Reply
    • Andrews Ang

      October 6, 2016

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

      Reply
  • niki2k1

    October 9, 2016

    Can 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?

    Reply
    • niki2k1

      October 9, 2016

      Thats on line 50: $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

      Reply
      • Andrews Ang

        October 10, 2016

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

        Reply
  • Edwin

    October 30, 2016

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

    Reply
    • Andrews Ang

      November 5, 2016

      Hi Edwin, if you’re using Apache, to redirect http:// to https:// you should use .htaccess instead.

      Reply
  • Tom Harrison

    November 4, 2016

    Hi, 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)

    Reply
    • Andrews Ang

      November 5, 2016

      Hi 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

      Reply
    • Andrews Ang

      November 5, 2016

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

      Reply
  • Umaha Tokula

    November 7, 2016

    Hi, 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

    Reply
    • Andrews Ang

      November 8, 2016

      Hi, are you using the helper url()? Can you echo it and see what it shows?

      Reply
  • Stephen Paul Samynathan

    November 14, 2016

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

    Reply
    • Andrews Ang

      November 14, 2016

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

      Reply
  • Bjorn

    November 14, 2016

    Hello 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?

    Reply
    • Andrews Ang

      November 14, 2016

      Hi, 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

      Reply
      • Bjorn

        November 15, 2016

        Hey 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

        Reply
        • Andrews Ang

          November 24, 2016

          Hi, 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?

          Reply
          • Bjorn

            January 10, 2017

            Hello 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, 2017

            Forget about my previous post, it works!

            Great many thanks!

  • Francesco Parisi

    November 22, 2016

    I 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?

    Reply
    • Andrews Ang

      November 24, 2016

      Hi, 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

      Reply
      • Francesco Parisi

        November 24, 2016

        hi,

        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}]

        Reply
        • Andrews Ang

          November 24, 2016

          Thx for sharing!

          Reply
  • violetann

    November 24, 2016

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

    Reply
    • Andrews Ang

      November 24, 2016

      I’m glad it helped! 🙂

      Reply
  • Navas

    December 23, 2016

    Thanks buddy, do it L5.2 to godaddy shared hosting.

    Reply
  • khactung

    December 28, 2016

    Hi you,
    If I create login session for base then can sub project get that session ?

    Reply
  • Alex

    December 30, 2016

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

    Reply
  • Luítame De Oliveira

    January 5, 2017

    This not work for me. I’m using Laravel 5.3. When try to access an URI the server launch an error 404.

    Reply
    • Andrews Ang

      January 12, 2017

      Could 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?

      Reply
  • vivekpadhye

    January 9, 2017

    Why 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?

    Reply
    • Andrews Ang

      January 12, 2017

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

      Reply

Leave a Reply