program story

Laravel 5+ Ubuntu 14.04에서 500 내부 서버 오류 발생

inputbox 2020. 11. 22. 19:25
반응형

Laravel 5+ Ubuntu 14.04에서 500 내부 서버 오류 발생


Windows OS에 Laravel을 여러 번 설치했지만 이런 유형의 문제는 발생하지 않았습니다. 이 500 내부 서버는 일반적으로 "mod_rewrite"모듈이 켜져 있지 않을 때 발생합니다.

그러나 Ubuntu 14.04에서는이 문제로 인해 두통이 생깁니다. rewrite_mod를 설치했지만 작동하지 않습니다. ie 안의 모든 폴더와 파일에 대한 액세스 권한을 부여했습니다.

/ var / www / html / laravel_project

여전히 작동하지 않습니다. .htaccess도 원본에서 이것으로 변경되었습니다.

    +FollowSymLinks
RewriteEngine On

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

Laravel 5+에 필요한 모든 확장 기능도 있습니다. 내가하지 않은 것이 남아 있습니까?


마침내 문제를 극복

  • 문제가 된 .htaccess 파일도 index.php도 아니 었습니다. 문제는 파일에 액세스하고 권한을 요구하는 것입니다.

문제를 해결하기 위해 터미널을 통해 다음 명령을 실행했습니다.

sudo chmod -R 755 laravel_blog

그런 다음 laravel이 저장 폴더에 파일을 쓸 수 있도록 아래에 입력하십시오.

chmod -R o+w laravel_blog/storage

이 두 명령이 문제를 해결했습니다.


.env 파일을 만들고 다음을 실행합니다.

php artisan key:generate

이것은 git 프로젝트를 가져온 후에 저에게 효과적이었습니다.

.env 파일을 만들고 키를 생성 한 후 아래 코드를 실행합니다.

php artisan cache:clear 
php artisan config:clear

설치 후 아래 명령 실행

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

여기서 "laravel"은 laravel이 설치된 디렉토리의 이름입니다.


이 명령으로 수정했습니다.

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

서버를 다시 시작하는 것보다 XAMPP 또는 다른 서버를 다시 시작하면 작동합니다.


비슷한 오류가 발생했습니다. 로그인을 /var/log/apache2/error.log확인하고 UnexpectedValueException을 발견했습니다.

소유자를 프로젝트 디렉토리 아래의 스토리지 폴더의 아파치 사용자로 변경했습니다.

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

제 경우에는 apache2 프로세스 소유자가 www-data이므로 이것을 귀하의 것으로 변경하면 apache2 구성 파일에서 찾을 수 있습니다. 이것이 당신에게 유용하기를 바랍니다.


.env파일 이 있는지 확인 하십시오.

대부분이 일은 그런 일을 일으킬 수 있습니다. 파일을 만든 다음에서 모든 항목을 복사 .env.example하여 만든 파일에 붙여넣고 이름을 지정합니다 .env. 또는 jsut 단순히 .env.example파일 이름을 바꾸고 .env실행하십시오.php artisan key:generate


이 문제에 대한 또 다른 해결책이 있습니다.

프로젝트의 루트에서 composer 명령을 실행하여 필요한 패키지를 설치합니다.

sudo composer install

최신 정보:

  • 프로덕션 서버에서이 명령을 실행하면 안되지만 composer의 일부 문제는 로컬 환경에서이를 통해 해결할 수 있습니다.

편집하다:


때때로 PHP 버전에 문제가 있습니다. 서버에서 PHP 버전을 변경해야합니다. .htaccess 파일의 문자열 아래에 적어 두십시오 .

AddHandler application/x-httpd-php5 .php

PHP 7.0과 PHP 7.1이 설치되어 있고 명령 줄에서 PHP 7.1을 사용하고 있었고 Apache에서 PHP 7.0이 활성화되어 있었기 때문에 Laravel Framework와 localhost Apache2를 laravel과 함께 사용할 때 문제가 발생할 수 있습니다.

작성기 파일을 먼저 확인하여 PHP 버전을 확인하십시오.

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

명령 줄에서 현재 PHP 버전 확인

php -v

Apache에서 활성화 된 현재 PHP 버전을 확인하십시오. 브라우저를 사용했습니다.

http://localhost

동일하지 않은 경우 현재 버전을 비활성화하고 최신 버전을 활성화하십시오.

sudo a2dismod php7.2

sudo a2enmod php7.1

sudo service apache2 restart

그 후 폴더 권한 변경

sudo chmod 755 -R blog

저장 폴더 용

chmod -R o+w blog/storage

Laravel이 설치된 디렉토리에서 다음 두 명령을 실행하십시오.

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

그런 다음 캐시를 지우고 자동로드를 덤프합니다.

php artisan cache:clear
composer dump-autoload

git을 사용할 때 자주 발생하는 문제 :

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

서버에 .env 파일을 수동으로 추가하거나 FTP를 통해 업로드하여이 문제를 해결했습니다.


나는이 문제에 여러 번 직면했다. 이 단계 중 하나를 시도해보세요. 아마도 그것은 당신을 도울 것입니다.

  1. 먼저 파일 권한을 확인하십시오.
  2. 파일 권한을 수정하려면 sudo chmod 755 -R your_project
  3. 그런 다음 chmod -R o + w your_project / storage 파일을 저장 폴더에 씁니다.
  4. php artisan cache : clear
    composer dump-autoload
  5. PHP 장인 키 : 생성
  6. 그런 다음 laravel 요구 사항에 따라 서버 요구 사항확인하십시오 .
  7. php 버전 때문에이 오류 여러 번 발생했습니다 . cpanel에서 PHP 버전변경해보십시오 .
  8. 그런 다음 .htaccess 파일을 올바르게 구성하십시오.

laravel의 루트에서이 두 명령을 실행하십시오.

찾기 * -type d -print0 | xargs -0 chmod 0755 # 디렉토리 용

찾기 . 유형 f -print0 | xargs -0 chmod 0644 # 파일 용


먼저 프로젝트 폴더 (laravel이라고 함), 저장소 하위 폴더 및 로그 하위 폴더 및 공급 업체 하위 폴더 (laravel / storage, laravel / storage / logs 및 laravel / vendor)에 대한 모든 권한을 허용합니다.

그런 다음 .env 파일이 있는지 확인하십시오. 그렇지 않은 경우 실행할 수 있습니다.

$ mv .env.example .env

내장 .env.example의 이름을 필요한 .env로 바꿉니다.

그렇지 않으면 디버그 모드를 켜십시오-.env를 열고 설정하십시오.

APP_DEBUG=true

laravel / config / app.php를 열고 변경하십시오.

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

...에

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

오류의 원인을 찾을 수 있습니다.


공유 호스트와 비슷한 문제가 있습니다. 500 오류가 발생했습니다. 방금 Laravel 버전과 PHP 버전을 확인하여 수정했습니다. 오류는 Laravel 5.6이 PHP 7.0.x에서 실행되지 않기 때문입니다. 일단 이것을 알고 나면 프로젝트를 PHP 7.0.x와 호환되는 Laravel 5.5로 재구성하면 이제 모든 것이 올바르게됩니다. 가끔 문제가있는 또 다른 이유는 FTP에서 파일이 손상되어 프로젝트를 두 번 이상 업로드해야하기 때문입니다. 앞으로이 주제에서 많은 정보를 찾지 못했기를 바랍니다.


나를 좋아하는 사람들은 다른 모든 답변을 시도한 후에도 여전히 오류가 있습니다.

php apache가 사용하는 버전을 확인하십시오. 최신 laravel은 php7.1에서만 작동합니다. 따라서 다음을 수행해야합니다.

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

도움이 되었기를 바랍니다


로그에 따르면 :

[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

/ vendor 폴더로 파일을 여는 데 몇 가지 오류가 있습니다.

Composer를 통해 설치하고 업데이트함으로써 마침내 문제를 해결할 수있었습니다.

sudo composer install
sudo composer update

쓰기 권한이있는 저장소 폴더 (chmod o + w)를 확인하고 나를 위해 매력적으로 작동합니다.


로그 디렉토리를 쓸 권한이 없기 때문입니다.
chmod 755 스토리지 -R


이 문제에 직면하고 Apache에서 PHP 버전을 5.6.x로 업그레이드하여 해결했습니다.


다음 명령을 통해서만 웹 폴더 권한을 변경하십시오.

sudo chmod 755 -R your_folder


라이브 서버에서 이것을 시도하면

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

그런 다음 composer.json의 php 버전이 서버의 버전과 동일한 지 확인하십시오.

터미널에서 PHP 버전을 확인하십시오. php -v


나는 모든 의견과 제안을 읽었습니다. 500-HTTP ERROR CODE는 내부 서버 오류를 나타냅니다.

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.


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 :)

참고URL : https://stackoverflow.com/questions/31543175/getting-a-500-internal-server-error-on-laravel-5-ubuntu-14-04

반응형