0

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. Commented Mar 23, 2016 at 14:26

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

5 Comments

I am creating subdomain for it by using cpanel but it is not pointing to anything else then public_html/ , please guide me on this
@NeerajRathod, while you are creating the subdomain there is a text field where you can set the path for point it
yes there is a text field with "public_html/" written in it, I had removed "public_html/" and write the desired pointing address, but after creating subdomain, I see pointing address is started only with "public_html/" continue with what I had written in the text field
Could you see the httpd.conf file an see if the virtual host was created?
I resolve it by referring this link stackoverflow.com/questions/41242227/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.