可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have installed Laravel many times on Windows OS but it never occurred this type of problem. This 500 internal server usually occurs when your "mod_rewrite" module is not turned on.
However, on Ubuntu 14.04 this problem is giving me a headache. I have installed rewrite_mod but it's also not working. I've given access to all my folders and files inside i.e.
/var/www/html/laravel_project
Still it doesn't work. Changed .htaccess as well from original to this.
+FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
I have all the necessary extensions needed for Laravel 5+ as well. Is there something left that I didn't do?
回答1:
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 755 -R 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.
回答2:
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
回答3:
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.
回答4:
I fixed with this Command:
rm -rf app/storage/logs/laravel.logs
chmod -R 777 app/storage,
php artisan cache:clear,
php artisan composer dump-autoload
Than restart a server eather XAMPP ore another one and that should be working.
回答5:
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.
回答6:
A newbie but this is what i did coz i had no key
Created the .env file and also run
php artisan key:generate
This worked for me after pulling a git project
回答7:
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
回答8:
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
回答9:
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
回答10:
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
回答11:
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
回答12:
Besides the reasons listed above, there are other reasons for which laravel can give 500 internal server error. Including missing or old CSRF, syntax error, .htaccess miss configuration etc. There is a whole list covered here https://abbasharoon.me/how-to-fix-laravel-ajax-500-internal-server-error/
回答13:
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.
回答14:
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.
回答15:
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
回答16:
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
回答17:
Make sure storage folder with write previlege (chmod o+w), work for me like a charm.
回答18:
Because of no right to write the log's directory.
chmod 755 storage -R
回答19:
I faced this issue and fixed by upgrade my php version in apache up to 5.6.x
回答20:
Only change the web folder permission through this command:
sudo chmod 755 -R your_folder
回答21:
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