65

I am trying to upload my Laravel project onto my web server, but my past two attempts have been unsuccessful. I believe I am not uploading the files to the right location.

This is my web server's structure -> WebServer Structure

Am I correct to say that I need to upload ALL of my laravel files into public_html?

This is my Laravel project's directory :

Laravel Project Directory

EDIT : I have now added all the files onto the root folder, and public into public_html, however none of my routes seem to work. (They work perfectly on localhost). Everything throws a 404

Sainath Krishnan
  • 2,089
  • 7
  • 28
  • 43

7 Answers7

47

No, but you have a couple of options:

The easiest is to upload all the files you have into that directory you're in (i.e. the cPanel user home directory), and put the contents of public into public_html. That way your directory structure will be something like this (slightly messy but it works):

/
    .composer/
    .cpanel/
    ...
    app/                 <- your laravel app directory
    etc/
    bootstrap/           <- your laravel bootstrap directory
    mail/
    public_html/         <- your laravel public directory
    vendor/
    artisan              <- your project's root files

You may also need to edit bootstrap/paths.php to point at the correct public directory.

The other solution, if you don't like having all these files in that 'root' directory would be to put them in their own directory (maybe 'laravel') that's still in the root directory and then edit the paths to work correctly. You'll still need to put the contents of public in public_html, though, and this time edit your public_html/index.php to correctly bootstrap the application. Your folder structure will be a lot tidier this way (though there could be some headaches with paths due to messing with the framework's designed structure more):

/
    .composer/
    .cpanel/
    ...
    etc/
    laravel/      <- a directory containing all your project files except public
        app/
        bootstrap/
        vendor/
        artisan
    mail/
    public_html/  <- your laravel public directory
alexrussell
  • 13,856
  • 5
  • 38
  • 49
  • 2
    i will +1 this for the 1st approach. the system files should be taken out of public access. – itachi Feb 27 '14 at 17:45
  • 1
    I put everything into the folder as you said, and put public into public_html, but now I'm getting this error when I visit my domain - `View [layouts.main] not found. ` – Sainath Krishnan Feb 27 '14 at 19:02
  • @itachi I actually meant for the second approach that the system files would *also* be out of the public folder, will edit the post to clarify. – alexrussell Feb 28 '14 at 08:52
  • @SainathKrishnan all I can say here is that you really need to check that all your paths are set up as correctly as possible. There are a few places where Laravel sets up paths, although the main two are `public/index.php` and `bootstrap/paths.php` but the view stuff is in `app/config/view.php` so maybe check that out too if you're having view issues. I guess also ensure that the `app/storage/` directory (and all directories within it) are somehow writable by the process that runs PHP for that site. – alexrussell Feb 28 '14 at 09:28
  • My issue was due to there being a duplicate .htaccess file, got it fixed now. Thank you for your original solution! Cheers :) – Sainath Krishnan Feb 28 '14 at 12:50
  • I have answered to a similar question for uploading a laravel 5 project to shared hosting with step by step instructions, http://stackoverflow.com/questions/35461322/upload-laravel-5-to-server-subfolder/35474800#35474800 – Donkarnash Feb 19 '16 at 06:56
  • I do not understand why we can take this solution. I think this not helpful at much. Yes it may works but we change some rule there. Why we change ? – Faris Rayhan May 18 '16 at 09:05
  • Laravel (at least at the time of writing this answer) just wouldn't work like this without the extra work required to make it do so. As you can see by how short the answer is though, Laravel was set up to allow these kinds of changes be made. Sometimes you have to put a little work in to go against a default, that's just the way of life. It's worth me pointing out, however, that the solution I ended up sticking with for this kind of thing was to put *all* of the Laravel stuff (un-renamed) in a directory `src/` and then symlink `public_html` to `src/public/`. – alexrussell May 23 '16 at 09:09
  • How did you symlink it? Can you please provide the answer to that here? – HexaCrop May 29 '18 at 10:51
  • @KevinRED sorry for the delay, and I'm almost certainly waaay too late here, but you'd have to symlink it by going to the command line on your shared host and running, from the root of your hosting (where `public_html` would sit) `ln -s src/public public_html` (or, more generically, `ln -s path/to/thing-you-actually-have where-you-want-it-to-pretened-it-is`). You might find that you already have a `public_html` set up by the hosting, you should just be able to delete that directory and add the link in, and then you may need to change the permissions on that new `public_html` using `chmod -h`. – alexrussell Jul 24 '18 at 11:02
  • Thanks for the reply – HexaCrop Jul 24 '18 at 13:21
  • i uploaded my project to public_html and it's not working for now i wanted to know is there a way to solve my issue without changing .htaccess file or the structure of my project ? – Youssef Boudaya Mar 15 '19 at 13:58
13

I believe - your Laravel files/folders should not be placed in root directory.

e.g. If your domain is pointed to public_html directory then all content should placed in that directory. How ? let me tell you

  1. Copy all files and folders ( including public folder ) in public_html

  2. Copy all content of public folder and paste it in document root ( i.e. public_html )

  3. Remove the public folder

  4. Open your bootstrap/paths.php and then changed 'public' => __DIR__.'/../public', into 'public' => __DIR__.'/..',

  5. and finally in index.php,

Change

require __DIR__.'/../bootstrap/autoload.php';

$app = require_once __DIR__.'/../bootstrap/start.php';

into

require __DIR__.'/bootstrap/autoload.php';

$app = require_once __DIR__.'/bootstrap/start.php';

Your Laravel application should work now.

Kamlesh
  • 5,233
  • 39
  • 50
Raj Sf
  • 1,408
  • 1
  • 17
  • 26
5

If you are trying to host your Laravel app on a shared hosting, this may help you.

Hosting Laravel on shared hosting #1

Hosting Laravel on shared hosting #2

If you want PHP 5.4 add this line to your .htaccess file or call your hosting provider.

AddType application/x-httpd-php54 .php

Abhinandan N.M.
  • 362
  • 1
  • 3
  • 15
4

In Laravel 5.x there is no paths.php

so you should edit public/index.php and change this lines in order to to pint to your bootstrap directory:

require __DIR__.’/../bootstrap/autoload.php’;

$app = require_once __DIR__.’/../bootstrap/app.php’;

for more information you can read this article.

M.A. Heshmat Khah
  • 740
  • 12
  • 27
2

Had this problem too and found out that the easiest way is to point your domain to the public folder and leave everything else the way they are.

PLEASE ENSURE TO USE THE RIGHT VERSION OF PHP. Save yourself some stress :)

Overcomer
  • 434
  • 5
  • 11
1

All of your Laravel files should be in one location. Laravel is exposing its public folder to server. That folder represents some kind of front-controller to whole application. Depending on you server configuration, you have to point your server path to that folder. As I can see there is www site on your picture. www is default root directory on Unix/Linux machines. It is best to take a look inside you server configuration and search for root directory location. As you can see, Laravel has already file called .htaccess, with some ready Apache configuration.

Miroslav Trninic
  • 3,327
  • 4
  • 28
  • 51
0

(1) If you are uploading in Cpanel or cloud make sure exact version of laravel, php should be taken care.

(2) Make changes in .env files with refrence to DB credentials user and pass if in localhost

ram sharma
  • 13
  • 3