php 在 Laravel 5+ Ubuntu 14.04 上出现 500 内部服务器错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31543175/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting a 500 Internal Server Error on Laravel 5+ Ubuntu 14.04
提问by DpEN
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.
我在 Windows 操作系统上安装了 Laravel 很多次,但从未出现过此类问题。这 500 个内部服务器通常发生在您的“mod_rewrite”模块未打开时。
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.
但是,在 Ubuntu 14.04 上,这个问题让我很头疼。我已经安装了 rewrite_mod 但它也不起作用。我已经授予访问我所有文件夹和文件的权限,即
/var/www/html/laravel_project
/var/www/html/laravel_project
Still it doesn't work. Changed .htaccess as well from original to this.
还是不行。将 .htaccess 也从原来的改为这个。
+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?
我也有 Laravel 5+ 所需的所有必要扩展。有没有我没有做的事情?
回答by DpEN
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.
- 问题不是 .htaccess 文件,也不是 index.php。问题在于访问文件并需要权限。
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
然后在下面输入以允许 Laravel 将文件写入存储文件夹
chmod -R o+w laravel_blog/storage
This two commands solved the problem.
这两个命令解决了问题。
回答by Goodlife
Create the .env file and also run :
创建 .env 文件并运行:
php artisan key:generate
This worked for me after pulling a git project.
在拉出一个 git 项目后,这对我有用。
After creating .env file and generating the key, run the code below:
创建 .env 文件并生成密钥后,运行以下代码:
php artisan cache:clear
php artisan config:clear
回答by Sujendra Kumar
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
这里“laravel”是laravel安装目录的名称
回答by Lesther
Try to check if you have .env
file.
尝试检查您是否有.env
文件。
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
大多数情况下,这件事会导致类似的事情。尝试创建一个文件,然后从 复制所有内容.env.example
,将其粘贴到您创建的文件中并为其命名.env
。或 jsut 只需将.env.example
文件重命名为.env
并运行php artisan key:generate
回答by Atdhe Kurteshi
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.
比重新启动服务器以 XAMPP 或另一个服务器,这应该可以正常工作。
回答by Snriud
I have faced a similar error. I checked the log in /var/log/apache2/error.log
and found an UnexpectedValueException
我遇到过类似的错误。我检查了登录/var/log/apache2/error.log
并发现了一个UnexpectedValueException
I changed the owner to my apache user of the storage folder under the project dir.
我将项目目录下存储文件夹的所有者更改为我的 apache 用户。
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.
在我的情况下,apache2 进程所有者是www-data
,因此将其更改为您的,这可以在 apache2 配置文件中找到。希望这对你有用。
回答by Christos Papoulas
May another solution to this problem:
可能是这个问题的另一种解决方案:
Install the required packages by running the composer command from the the root of the project:
通过从项目的根目录运行 composer 命令来安装所需的包:
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.
- 您不应该在生产服务器上运行此命令,但可以在本地环境中解决与 composer 相关的一些问题。
EDIT:
编辑:
- take a look at https://getcomposer.org/doc/faqs/how-to-install-untrusted-packages-safely.mdto see why running composer installas root is not a good idea
- If you need to run it as root, provide the following flags, to block third-party code from executing durin the install --no-plugins --no-scripts
- 看看https://getcomposer.org/doc/faqs/how-to-install-untrusted-packages-safely.md看看为什么以 root 身份运行composer install不是一个好主意
- 如果您需要以 root 身份运行它,请提供以下标志,以阻止第三方代码在安装期间执行--no-plugins --no-scripts
回答by Maroun Melhem
A frequent issue when using git:
使用 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
通过在服务器上手动添加 .env 文件或通过 FTP 上传来解决此问题
回答by MarsAndBack
Make sure a .env file, containing an APP_KEY, exists in root.
确保根目录中存在包含 APP_KEY的 .env 文件。
What should be in the .env hasn't been explicitly stated in other solutions, and thought I'd boil it down to one sentence.
.env 中应该包含的内容在其他解决方案中没有明确说明,我认为我会将其归结为一句话。
This fixed my 500 error on a fresh install of Laravel.
这修复了我在全新安装 Laravel 时出现的 500 错误。
Steps:
脚步:
- Create a .env file in root (e.g.
touch .env
) - Make sure it contains at least one line:
APP_KEY=
- Generate an app key in terminal:
php artisan key:generate
- 在 root 中创建一个 .env 文件(例如
touch .env
) - 确保它至少包含一行:
APP_KEY=
- 在终端生成应用密钥:
php artisan key:generate
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.When generating an app key in terminal, it may report as successful, however no key will actually get placed in the .envif the file has no pre-existing
APP_KEY=
line. This seems like a bug to me?
我的特定安装不包含任何 .env 任何内容(示例或其他)
仅仅拥有一个空白的 .env 是行不通的。
包含参数但没有
APP_KEY
参数的.env不起作用。在终端中生成应用程序密钥时,它可能报告为成功,但是如果文件没有预先存在的
APP_KEY=
行,则实际上不会将密钥放入 .env 中。这对我来说似乎是一个错误?
As a reference, here's the official .env with useful baseline parameters. Copy-paste what you need:
作为参考,这里是带有有用基线参数的官方 .env。复制粘贴你需要的:
回答by Saulo Campos
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.
我安装了 PHP 7.0 和 PHP 7.1 并且我在命令行上使用 PHP 7.1 并且在 Apache 上启用了 PHP 7.0,当您使用 Laravel Framework 和 localhost Apache2 与 Laravel 时,这种混乱会带来问题。
Check your composer file first to see your PHP version.
首先检查您的作曲家文件以查看您的 PHP 版本。
"php": "^7.1.3",
"laravel/framework": "5.6.*",
Check your currently php version on command line
在命令行上检查您当前的 php 版本
php -v
Check your currently php version enabled on Apache, I did using browser.
检查您当前在 Apache 上启用的 php 版本,我使用浏览器。
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