127

I have installed Laravel many times on Windows OS but never had this problem.

However, on Ubuntu 14.04 I am getting a 500 Internal Server Error, and messages like this in my logs:

[Wed Jul 22 10:20:19.569063 2015] [:error] [pid 1376] [client 127.0.0.1:52636] PHP Fatal error: require(): Failed opening required '/var/www/html/laravel_blog/../bootstrap/autoload.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/html/laravel_blog/index.php on line 22

Previously I've had problems when mod_rewrite was not installed or set up properly, but I have installed it and it is not working. Changed .htaccess as well from original to this.

    +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

I've given access to all my folders and files inside i.e.

/var/www/html/laravel_project

I have all the necessary extensions needed for Laravel 5+ as well. Is there something left that I didn't do?

IMSoP
  • 89,526
  • 13
  • 117
  • 169
DpEN
  • 4,216
  • 3
  • 17
  • 26
  • 2
    Why does it just have `+FollowSymLinks` at the top? Should be `Options +FollowSymLinks`. – Mike Rockétt Jul 21 '15 at 15:39
  • 1
    "I have installed rewrite_mod but ..." - and allowed appropriate access for .htaccess with `AllowOverride` in your server config? – MrWhite Jul 21 '15 at 18:21
  • @MikeRockett i recently removed the "Options" when keeping it the browser goes blank white and when not keeping it the browser returns a 500 request error but in both cases the browser is returning 500 error. ! – DpEN Jul 22 '15 at 04:39
  • 1
    @MarcB my error log shows following :- [Wed Jul 22 10:20:19.569063 2015] [:error] [pid 1376] [client 127.0.0.1:52636] PHP Fatal error: require(): Failed opening required '/var/www/html/laravel_blog/../bootstrap/autoload.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/html/laravel_blog/index.php on line 22 – DpEN Jul 22 '15 at 04:40
  • Well, the `Options` must be there - otherwise the file is invalidated. The error says that `www/html/bootstrap/autoload.php` does not exist... So where is the `bootstrap` directory? – Mike Rockétt Jul 22 '15 at 04:58
  • @MikeRockett The directories are all default ... i have not changed any of it. Its inside "laravel_blog/bootstrap/.." – DpEN Jul 22 '15 at 05:23
  • The `public` and `bootstrap` directories should be under `laravel_blog`, and you should be accessing the app from `laravel_blog/public` - this is the assumption based on the info you've provided thus far. You must have changed something if it is looking for `autoload.php` inside `html/bootstrap/`. Are you using a VirtualHost? If so, is its `DocumentRoot` set to `public`? – Mike Rockétt Jul 22 '15 at 06:18
  • @MikeRockett I've moved my index.php file outside the public and my .htaccess file ..On windows I always did this and accessed my files just doing the localhost/my_site_foler and nevr any errors occured ... But i've been using ubuntu for a week now and here seems to be problem... I think my problem is in .htaccess file but i do not know where it went wrong... – DpEN Jul 22 '15 at 10:36
  • 1
    @MikeRockett .. I've removed the "/../" from the index.php file and tried and showed different errors of file permissions and then chmod and set read/ write permissions and it worked !!! Thanx for the help bro !! – DpEN Jul 22 '15 at 11:05

34 Answers34

245

Finally Overcame the problem

  • It was not the .htaccess file that was the problem nor the index.php. The problem was on accessing the files and requiring permissions.

For solving the problem i ran the following commands through terminal.

sudo chmod -R 755 laravel_blog

and then type below to allow laravel to write file to storage folder

chmod -R o+w laravel_blog/storage

This two commands solved the problem.

C.Liddell
  • 1,084
  • 10
  • 19
DpEN
  • 4,216
  • 3
  • 17
  • 26
  • 1
    Thanks, I had this problem when installing laravel onto a fresh ubuntu 14.04 distribution on google compute engine, this solved it. – Alex Oct 16 '15 at 19:37
  • 2
    this is a very bad advice, the chmod sets all files to +x. I assume you wanted to do it for directories, in which case you'd use find. – MightyPork Feb 27 '16 at 10:03
  • where should I cd (change directory) on in order to execute that command ? – Anastasie Laurent Apr 04 '16 at 22:53
  • cd to your /var/www/html directory then execute this command... instead of laravel_blog put your project folder.. – DpEN Apr 05 '16 at 03:24
  • For me on mac terminal I had to put -R before the 755 or it thought -R was the file/folder name. So: sudo chmod -R 755 laravel_project. The 2nd command was fine. It did fix my problem, so thanks! – Base Desire Sep 15 '16 at 13:23
  • 1
    You need many cookies. Worked fine on LAMP Ubuntu 16.04 Installation of Digital Ocean. – Abhishek Saini Jan 13 '17 at 09:52
  • Works on CentOS 7 – ii7scw Jun 19 '17 at 15:35
  • for me this work like this `sudo chmod -R 755 laravel_blog` – Elshan May 02 '18 at 04:54
  • these two problems solved my problem partially, but when i run this extra command `sudo chmod -R o+w laravel_blog/bootstrap` it worked for me. – Abdullah Shoaib Aug 31 '18 at 05:38
  • You saved me! Thanks so much. Old 5.2 project, updating is done through dragging files in FTP. I feel like I'm in the 90's again – Miguel Stevens Mar 27 '19 at 20:35
  • i agree this totally fubared my dir tree i literally pulled the ethernet cord out immediately... – Chris Jul 24 '19 at 03:35
  • should be: find /var/www/docroot/* -type f -exec chmod 660 '{}' \;; find /var/www/docroot/* -type d -exec chmod 770 '{}' \;;find /var/www/docroot/* -type f -exec chmod u+s,g+s '{}' \;; that is assuming you have a laravel user, if just apache then it could just be 600 and 700 – Chris Jul 24 '19 at 03:42
119

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
tchap
  • 3,412
  • 3
  • 29
  • 46
Goodlife
  • 3,822
  • 2
  • 24
  • 23
  • 10
    This worked for me. Don't make a noob mistake, after installing laravel project make sure to rename .env.example to .env or php artisan key:generate will crash – Armin Jun 20 '19 at 17:25
  • OK is this a new thing? First time encountering this problem – Robert Nov 22 '19 at 03:57
  • 2
    `php artisan cache:clear php artisan config:clear` is working for my case – Nurkartiko Jun 06 '20 at 00:13
  • can i do these commands with project already in production ? – Youssef Boudaya Apr 20 '21 at 07:00
  • 1
    What Armin did worked for me as well. If you have a 500 Server Error, just rename the ".env.example" to ".env" and run: - php artisan key:generate - php artisan cache:clear - php artisan config:clear In my case, I pulled the project to Github repo to local machine. Just make sure you have an updated Composer. Mine's version 8. – Star-Lord Jul 05 '21 at 02:41
34

Try to check if you have .env file.

Mostly this thing can cause something like that. Try to create a file then copy everything from .env.example, paste it to your created file and name it .env. or jsut simply rename the .env.example file to .env and run php artisan key:generate

Unheilig
  • 16,196
  • 193
  • 68
  • 98
Lesther
  • 511
  • 5
  • 6
30

After installing run below command

sudo chmod 755 -R laravel
chmod -R o+w laravel/storage

here "laravel" is the name of directory where laravel installed

Sujendra Kumar
  • 439
  • 4
  • 5
27

Make sure a .env file, containing an APP_KEY, exists in root.

What should be in the .env hasn't been explicitly stated in other solutions, and thought I'd boil it down to the sentence above.

This fixed my 500 error on a fresh install of Laravel.

Steps:

  1. Create a .env file in root (e.g. touch .env)
  2. Make sure it contains at least one line: APP_KEY=
  3. Generate an app key in terminal: php artisan key:generate

More .env paramaters:

As a reference, here's the official .env with useful baseline parameters. Copy-paste what you need:

https://github.com/laravel/laravel/blob/master/.env.example

Notes:

  • My particular installation didn't include any .env whatsoever (example or otherwise)

  • Simply having a blank .env does not work.

  • A .env containing parameters, but no APP_KEY parameter, does not work.

Bug?: When generating an app key in terminal, it seems to falsely report success, however no key will actually get placed in the .env if the file is missing a line starting with APP_KEY=.

Kalnode
  • 9,386
  • 3
  • 34
  • 62
14

I fixed with this Command:

   rm -rf app/storage/logs/laravel.logs
   chmod -R 777 app/storage,
   php artisan cache:clear,
   php artisan dump-autoload OR composer dump-autoload

Than restart a server eather XAMPP ore another one and that should be working.

Khushal
  • 249
  • 4
  • 19
Atdhe Kurteshi
  • 373
  • 5
  • 14
12

I have faced a similar error. I checked the log in /var/log/apache2/error.log and found an UnexpectedValueException

I changed the owner to my apache user of the storage folder under the project dir.

sudo chown -R www-data:www-data ./storage

In my case apache2 process owner is www-data, so change this to yours, this can be found in apache2 config file. Hope this is useful to you.

Naman
  • 27,789
  • 26
  • 218
  • 353
Snriud
  • 143
  • 2
  • 7
11

May another solution to this problem:

Install the required packages by running the composer command from the the root of the project:

sudo composer install

UPDATE:

  • You should not run this command on a production server, but some issues with composer can be resolved with this on local envs.

EDIT:

Christos Papoulas
  • 2,469
  • 3
  • 27
  • 43
  • 1
    What the heck is this , do you actually know what you are answering ! – Jimmy Obonyo Abor Jan 30 '16 at 23:21
  • 3
    @JimmyObonyoAbor Actually this is working. According to the logs, the 500 was because some files in /vendor were missing. How do you fix that ? By running composer install/update. Thanks and upvote, Christos Papoulas – tomsihap Feb 06 '16 at 23:42
  • 5
    I believe running that command with sudo is a potential security hole – Shay Jul 07 '16 at 08:57
10

run these commands

1. composer install 
2. mv .env.example .env 
3. php artisan cache:clear 
4. composer dump-autoload 
5. php artisan key:generate

I had this problem ...

Saeid
  • 422
  • 4
  • 9
9

Create .env file with the below cmd command:

cp .env-example .env

Then generate a key for your project:

php artisan key:generate

After that clear your caches using the below commands:

//---Delete Configuration Cahce
php artisan config:cache
//---Clear Application Cache
php artisan cache:clear
Hedayatullah Sarwary
  • 2,664
  • 3
  • 24
  • 38
8

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

Reasons for this error:

  • These 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 once you start getting all these commands, I suggest you to make a script which will save your time.

Smit Patel
  • 1,682
  • 18
  • 23
5

I had PHP 7.0 and PHP 7.1 installed and I was using PHP 7.1 on command line and PHP 7.0 was enabled on Apache, that messy can bring problems when you are using Laravel Framework and localhost Apache2 with laravel.

Check your composer file first to see your PHP version.

"php": "^7.1.3",
"laravel/framework": "5.6.*",

Check your currently php version on command line

php -v

Check your currently php version enabled on Apache, I did using browser.

http://localhost

If it's not the same disable the current version and enable the newest one.

sudo a2dismod php7.2

sudo a2enmod php7.1

sudo service apache2 restart

After that change folder permissions

sudo chmod 755 -R blog

for storage folder

chmod -R o+w blog/storage
Saulo Campos
  • 342
  • 4
  • 9
5

A frequent issue when using git:

Laravel's .gitignore ignores the .env file which when missing generates this error

Solved this by manually adding an .env file on the server or uploading it through FTP

Maroun Melhem
  • 3,100
  • 1
  • 20
  • 22
5

First, if there is not .env file in your Laravel repository. Copy the .env.example file using the following cmd command cp .env.example .env and open .env file and apply your configuration if needed.

Run these commands:

//---Generate Key in your project
php artisan key:generate
//---Flush the application cache
php artisan cache:clear
//---Remove the configuration cache file
php artisan config:cache
php artisan config:clear
//---Regenerates the list of all classes that need to be included in the project
composer dump-autoload
//---Restart your Server
php artisan serve
Hedayatullah Sarwary
  • 2,664
  • 3
  • 24
  • 38
4

Sometimes there is problem with php version. We need to change php version from server. Just write down below string in .htaccess file:

AddHandler application/x-httpd-php5 .php
Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
4

First allow all permissions for your project folder (let say it's called laravel), for the storage subfolder and its logs subsubfolder and for the vendor subfolder (laravel/storage, laravel/storage/logs and laravel/vendor).

Then check if your have .env file - if not you can run:

$ mv .env.example .env

to rename your build-in .env.example to the needed .env.

Otherwise turn on the debug mode - open .env and set

APP_DEBUG=true

and open laravel/config/app.php and change

'debug' => env('APP_DEBUG', false), 

to

'debug' => env('APP_DEBUG', true),

so you can find out what is the reason for your error.

tsveti_iko
  • 6,834
  • 3
  • 47
  • 39
  • 4
    There's no reason you should be editing config/app.php like that. The would negate the entire purpose of the .env file. – Nathan Jan 29 '17 at 19:04
  • I was getting Internal Service errors when I ran my laravel app on my test server (in production mode). Setting APP_DEBUG=true allowed me to see the details of the error, so I could then find and fix the problem. – Debbie V Sep 04 '18 at 16:17
3

Run these two commands in the directory where Laravel is installed:

sudo chmod 755 -R DIRECTORY_NAME
chmod -R o+w DIRECTORY_NAME/storage

Then clear the cache and dump the auto load:

php artisan cache:clear
composer dump-autoload
zx485
  • 28,498
  • 28
  • 50
  • 59
Ayman
  • 41
  • 3
3

I have faced this problem many times. Try one of these steps it helped me a lot. Maybe it will also help you.

  1. First of all check your file permissions.
  2. To fix file permissions sudo chmod 755 -R your_project
  3. Then chmod -R o+w your_project/storage to write file to storage folder.
  4. php artisan cache:clear
    composer dump-autoload
  5. php artisan key:generate
  6. Then check server requirements as per the laravel requirement.
  7. Many times you got this error because of the php version. Try changing your php version in cpanel.
  8. Then configure your .htaccess file properly
Anand Mainali
  • 993
  • 1
  • 14
  • 23
3

If you use vagrant, try this:

First remove config.php in current/vendor.

Run these command:

php artisan config:clear
php artisan clear-compiled
php artisan optimize

NOT RUN php artisan config:cache.

Hope this help.

Hanh Nguyen
  • 145
  • 1
  • 13
2

if its on a live server try this

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews -Indexes
</IfModule>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /


# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

then also make sure that the php version in your composer.json is the same as that of your server.

Check your php version in your terminal using php -v

The Billionaire Guy
  • 3,382
  • 28
  • 31
2

Check if your .env file is present or not in file structure. if not, follow the procedures:

  1. run command cp .env.example .env from projects root directory.
  2. run command php artisan key:generate
  3. refresh the browser.

Thanks.

1

Run these two commands on root of laravel

find * -type d -print0 | xargs -0 chmod 0755 # for directories

find . -type f -print0 | xargs -0 chmod 0644 # for files

1

I have a similar issue with a share Host. I was having 500 error. I just fixed by checking the Laravel version and PHP version. The error was because Laravel 5.6 doesn't run on PHP 7.0.x Once I know this I just reconfigure the project to Laravel 5.5 that is compatible with PHP 7.0.x now everything is right. Another reason I have issues sometimes is the FTP I get corrupted Files and have to upload the project more than once. Hope this help in the future I don't found so many information in this topic.

Josean Maya
  • 161
  • 2
1

For those of you who like me still got errors after trying all the other answers :

Check the version of php apache uses, latest laravel only works with php7.1. So you have to :

sudo a2dismod php[yourversion]
sudo a2enmod php7.1
sudo systemctl restart apache2

hope this helps

Ika
  • 21
  • 5
1

Make sure, you've run composer update on your server instance.

Usama Munir
  • 589
  • 9
  • 11
1

I fixed this problem by this commands:

mv .env.example .env
php artisan cache:clear
composer dump-autoload
php artisan key:generate

then

php artisan serve
Dharman
  • 30,962
  • 25
  • 85
  • 135
Adam
  • 309
  • 3
  • 8
1

php artisan require APP_KEY in .env file. So firstly create .env file in root,

sudo nano .env

and add APP_KEY= in first line, save the file and run

sudo php artisan key:generate
Ahsan Khan
  • 157
  • 2
  • 3
0

According to the logs :

[06-Feb-2016 22:38:48 Europe/Berlin] PHP Warning:  require(/Users/tomsihap/Documents/Development/mamp/partie_1_exo/bootstrap/../vendor/autoload.php): failed to open stream: No such file or directory in /Users/tomsihap/Documents/Development/mamp/partie_1_exo/bootstrap/autoload.php on line 17
[06-Feb-2016 22:38:48 Europe/Berlin] PHP Fatal error:  require(): Failed opening required '/Users/tomsihap/Documents/Development/mamp/partie_1_exo/bootstrap/../vendor/autoload.php' (include_path='.:/Applications/MAMP/bin/php/php7.0.0/lib/php') in /Users/tomsihap/Documents/Development/mamp/partie_1_exo/bootstrap/autoload.php on line 17
[06-Feb-2016 22:43:37 Europe/Berlin] PHP Warning:  require(/Users/tomsihap/Documents/Development/mamp/partie_1_exo/bootstrap/../vendor/autoload.php): failed to open stream: No such file or directory in /Users/tomsihap/Documents/Development/mamp/partie_1_exo/bootstrap/autoload.php on line 17
[06-Feb-2016 22:43:37 Europe/Berlin] PHP Fatal error:  require(): Failed opening required '/Users/tomsihap/Documents/Development/mamp/partie_1_exo/bootstrap/../vendor/autoload.php' (include_path='.:/Applications/MAMP/bin/php/php7.0.0/lib/php') in /Users/tomsihap/Documents/Development/mamp/partie_1_exo/bootstrap/autoload.php on line 17

There are some failures opening files into the /vendor folder.

By installing and updating via composer, I was able to finally solve the issue.

sudo composer install
sudo composer update
tomsihap
  • 1,712
  • 18
  • 29
0

Make sure storage folder with write previlege (chmod o+w), work for me like a charm.

user3619249
  • 1
  • 1
  • 1
0

Because of no right to write the log's directory.
chmod 755 storage -R

George Peter
  • 69
  • 1
  • 1
  • 6
0

I faced this issue and fixed by upgrade my php version in apache up to 5.6.x

Mahmoud Niypoo
  • 1,598
  • 5
  • 24
  • 41
0

Only change the web folder permission through this command:

sudo chmod 755 -R your_folder

Parker
  • 7,244
  • 12
  • 70
  • 92
0

I just ran the following command:

php artisan passport:install

I was using passport to run my application completely based on API's and Vue.js. Laravel worked fine but everytime i tried to login via my API i would get the error. After running the command and updating the client_id and client_secret on my Laravel files then pushed the new updates to the live server, the problem was solved. In my user model i have a script as follows:

public function generateToken($request)
{
    $http = new \GuzzleHttp\Client();
    $response = $http->post(URL::to('/').'/oauth/token', [
        'form_params' => [
            'grant_type' => 'password',
            'client_id' => '6',
            'client_secret' => 'x3yhgWVqF8sSaMev4JI3yvsVxfbgkfRJmqzlpiMQ',
            'username' => $this->email,
            'password' => $request->input('password'),
            'scope' => '',
        ],
    ]);
    //  Lets get an array instead of a stdObject so that we can return without errors
    $response = json_decode($response->getBody(), true);

    return oq_api_notify([
                'auth' => $response,                                        //  API ACCESS TOKEN
                'user' => $this->load(['settings'])->toArray(),
            ], 201);
}

I just updated the client_id and client_secret only then saved. Since the passport command gives you two client keys:

1) Personal access client (client_id & client_secret)

2) Password grant client (client_id & client_secret)

I used the Password grant client. Hopes this helps someone out there :)

Julian Tabona
  • 325
  • 3
  • 13
0

If you're facing this issue on the live server then the best way is to add the below-mentioned routes on the web.php file and then run all the routes through URL.

Most of the time this error is because of caches issues and once you clear all the caches - then this error will be solved and you can see to updates codes result.

//Clear Cache facade value:

Route::get('/clear-cache', function() {
    $exitCode = Artisan::call('cache:clear');
    return '<h1>Cache facade value cleared</h1>';
});

//Clear Route cache:

Route::get('/route-clear', function() {
    $exitCode = Artisan::call('route:clear');
    return '<h1>Route cache cleared</h1>';
});

//Clear View cache:

Route::get('/view-clear', function() {
    $exitCode = Artisan::call('view:clear');
    return '<h1>View cache cleared</h1>';
});

//Clear Config cache:

Route::get('/config-clear', function() {
    $exitCode = Artisan::call('config:clear');
    return '<h1>Config cleared</h1>';
});
Akash Sethi
  • 184
  • 1
  • 4
  • 15