Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kodemania's avatar

Laravel giving 500 internal error.

Hello guys

I have an laravel app working fine on my local machine. I have just transferred it to my server ( Shared hosting ) and put everything on public folder in public_html and everything else in one step above public_html. The problem is now it shows 500 internal error on every route. I have changed .htaccess code to given code on documentation, folder rights to storage and bootstrap is set to 777. Nothing in error logs and also nothing in laravel log files. when I installed fresh laravel installation it worked on server as well. Tried updated code with my project but still 500 internal error.

Its .htaccess code

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    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]
</IfModule>

Code in my composer.json file

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.1.*",
        "illuminate/html": "^5.0",
        "laravel/socialite": "^2.0"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~4.0",
        "phpspec/phpspec": "~2.1"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-install-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "pre-update-cmd": [
            "php artisan clear-compiled"
        ],
        "post-update-cmd": [
            "php artisan optimize"
        ],
        "post-root-package-install": [
            "php -r \"copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ]
    },
    "config": {
        "preferred-install": "dist"
    }
}

Searching from 3 days found no solution yet.

0 likes
24 replies
MikeHopley's avatar

Laravel expects to find your public files in the /public folder. Every request gets routed through /public/index.php. Laravel cannot find this file, hence the error.

You have a few options, depending on your hosting:

  1. Rename the /public_html folder to /public. But then you will need to configure your server to use this directory.
  2. ...or create a symlink that points /public to /public_html.
  3. ...or configure Laravel to look in /public_html instead.

This last option should work regardless of your hosting setup (I think). Follow these instructions: https://laracasts.com/discuss/channels/general-discussion/where-do-you-set-public-directory-laravel-5

kodemania's avatar

I can use 3rd option only which I used and still 500 internal error.

I have installed fresh copy of laravel 5.1 on this same server which worked. But when I deploy my laravel app code it shows 500 internal error.

My laravel app code is working fine on xampp also.

bashy's avatar

And you've turned on logging and seen the error behind the 500 status code?

shiny's avatar

@bashy - how do you get errors echoed back to the screen rather than a log file?

kocoten1992's avatar

@shiny , you set APP_DEBUG in .env to true

If the request is ajax, using chrome and press f12, go to Network tab -> click on error -> preview tab, if it just say error with a blank screen, then maybe you should chmod 775 and try again

5 likes
shiny's avatar

@kocoten1992 - I have that already, but my controller is returning status 500 and no message from php as to what happened. SOLVED - lumen did not have permission to write to the /storage/logs folder. So to me that is an application bug that prevents errors from echoing back if the log file can not be written too. Bad lumen, bad! No doughnut!

1 like
kocoten1992's avatar

yes, if it a blank screen, 100% of that is permission stuff, else the error would have print to the screen, cheer

3 likes
climbican's avatar

For me it was the permissions on the storage app_folder/storage.... needed to be changed to daemon read / write access for creating temporary files and sessions

Ncls's avatar

@kocoten1992 I am having the same issue. blank screen and error 500. Yet I think I have the correct permissions set...

total 1256  
drwxr-xr-x  13 nicolas  admin     442 Mar  6 10:34 app
-rw-r--r--      1 nicolas  admin    8519 Mar  6 10:34 app.php
-rw-r--r--      1 nicolas  admin    1646 Mar  6 10:34 artisan
drwxr-xr-x   5 nicolas  admin     170 Mar  6 10:34 bootstrap
-rw-r--r--      1 nicolas  admin    1433 Mar  6 10:34 composer.json
-rw-r--r--      1 nicolas  admin  121719 Mar  6 10:34 composer.lock
drwxr-xr-x  16 nicolas  admin     544 Mar  6 10:34 config
drwxr-xr-x   6 nicolas  admin     204 Mar  6 10:34 database
-rw-r--r--      1 nicolas  admin     530 Mar  6 10:34 gulpfile.js
-rw-r--r--      1 nicolas  admin     212 Mar  6 10:34 package.json
-rw-r--r--      1 nicolas  admin    1026 Mar  6 10:34 phpunit.xml
drwxr-xr-x   11 nicolas  admin     374 Mar  6 10:34 public
-rw-r--r--      1 nicolas  admin    1918 Mar  6 10:34 readme.md
drwxr-xr-x   6 nicolas  admin     204 Mar  6 10:36 resources
-rw-r--r--      1 nicolas  admin     567 Mar  6 10:34 server.php
drwxr-xr-x   5 nicolas  admin     170 Mar  6 10:34 storage
drwxr-xr-x   4 nicolas  admin     136 Mar  6 10:34 tests
fideloper's avatar

Permissions is not everything - if your php.ini is not set to display_errors, then you can still get the blank white screen.

Related to permissions: Showing the permissions of the storage directory doesn't give us enough information to see if it's just a permissions issue because:

  1. The storage/logs, and other subdirectories, may have other permissions set
  2. We don't know what user PHP is being run as, which determines if it can write to the storage directory (and its subdirectories). If user www-data is trying to write to directories owned by user nicolas, and user nicolas is the only user that can write to the directories (as permissions drwxr-xr-x is set), then the app won't be able to write to that location
kocoten1992's avatar

@Ncls , I was bad for assuming that.

Try clear error log of php (google that - the log directory depend on your OS and how you install php), then run it again, error will display on php error directory, let see if it help.

gabrielbuzzi's avatar

Check if rewrite module is enable. Few days ago i got stuck in this, it was the mod rewrite that i forgot to enable.

Tohby's avatar

You should check the cPanel, make sure the PHP version in the cPanel meets your application's minimum requirement. For instance, Laravel 5.7 requires PHP 7.1.3 or higher, whereas most hosting services enable 5.6 or something.

smitpatelx's avatar

I read all the comments and suggestions. 500 - HTTP ERROR CODE represents internal server error.

Reasons for this error:

  • There mainly cause due to permission issues
  • Environment variables not found or .env file not found on your root directory
  • PHP extensions problem
  • Database problem

Fix:

  • Set the correct permissions:
  • Run these commands (Ubuntu/Debian)
find /path/to/your/root/dir/ -type f -exec chmod 644 {} \;
find /path/to/your/root/dir/ -type d -exec chmod 755 {} \;

chown -R www-data:www-data /path/to/your/root/dir/

chgrp -R www-data storage bootstrap/cache
chmod -R ug+rwx storage bootstrap/cache
  • If .env file doesn't exist, create one by touch .env and paste your environment variables and then run
   php artisan key:generate
   php artisan cache:clear
   php artisan config:clear
   composer dump-autoload
  • Check your php.ini file and uncomment the extensions you need (In some case you have to install the extension by running this command apt-get install php7.2-[extension-name]
  • Check your database credentials and values in .env file. And grant permissions to the database user for that database.

These are some common problem you likely going to face when deploying your laravel app and one you start getting all these commands, I suggest you to make a script which will save your time.

5 likes
raviteja155's avatar

Thank you very much. That worked. I have been dealing with strange 500 errors and applying the permission commands has fixed them.

opanegro's avatar

thanks it work after command php artisan key:generate

youssefboudaya's avatar

i have a 5.7 laravel application and when i run the info.php script on my server i get 7.0.33 and the laravel needs as shown in composer.json "php": "^7.1.3" .can this cause the error " This page isnt working HTTP ERROR 500 " because i tried clearing all cache changing permissions, .htaccess file ..

BadHabbit's avatar

This isn't a proper solution but, this was my case. I had a prepared folder for the new Laravel application, but accidentally i installed into a sub folder within the main one. So i moved all the code one level above.

I had error 500 and couldn't load the page.

I deleted the whole folder and installed again (composer/laravel) correctly into the main folder, this helped me.

Hopefully this will help to someone.

dpicciolini's avatar

Create the .env file and also run :

    php artisan key:generate

This worked for me after pulling a git project.

After creating .env file and generating the key, run the code below:

 php artisan cache:clear 

 php artisan config:clear
1 like
Jaswinder's avatar

composer dump-autoload Make sure You are in the correct directory, It will show executing in other directory too but will not work. Go to root directory than execute. Thanks

Marvelxy's avatar

There are so many reasons the 500 error may occur. For me, it was a missing .env file. I cloned my own repo and set up everything, but I forgot to create the .env file.

If you have 500, check to make sure you have .env file.

Please or to participate in this conversation.