0
votes

My laravel project work good in localhost by artisan serve commend. Now i'm trying to host it on web host. I upload my project under public_html and copy all files from public folder i also edit app.php 'debug' => env('APP_DEBUG', true), for showing the error.

i edit index.php

require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';

but it still give a 500 Internal server error back.

I also try an another way, Upload my project into root directory except public folder and upload public folder into public_html directory . and i edit index.php as

require __DIR__.'/laravel/bootstrap/autoload.php';
$app = require_once __DIR__.'/laravel/bootstrap/app.php';

i can't find what wrong with my code. how can i deploy my laravel 5.2 project into a web hosting.?

1
What do your server logs say? PHP, Apache, Laravel.Don't Panic

1 Answers

0
votes

No No no.. You need to achieve the second option with some improvements. Let me explain it to you. A laravel application looks like:

app/
config/
public/
public/index.php
.env
composer.json
artisan

Right? good, now a web host's structure looks like:

/home/user/
/home/user/public_html/

But the structure above does not fit our needs because is public/ folder that should be accessed instead of public_html/. So.. the first step is to upload your project, lets say, like these:

/home/user/home/project/app/
/home/user/project/config/
/home/user/project/.env
/home/user/project/composer.json
/home/user/project/public/index.php

The next step is decide if you want your project as a main domain, or as subdomain.

  1. If your laravel's project will serve as a main domain just edit apache's config file httpd.conf and set the following rules:

    DocumentRoot "/home/user/project/public" ...

  2. If you want you project as a subdomain, just edit the apache's config file httpd.conf and add a virtual server like this:

    Listen 80
    <VirtualHost *:80>
        DocumentRoot "/home/user//project/public"
        ServerName my-project.example.com
    
        # Other directives here
    </VirtualHost> 
    

    With this directive you are telling to apache Hey! when people visits my-project.example.com show them the content of my site under /home/user/site/public.

    IF you are using cpanel, just create a subdomain and point it to /home/user/site/public

That is all, you do not need to hack any project's files like index.php, that is a bad practice.