Laradock을 이용하여 Laravel 개발 환경 만들기
9792 단어 Laravel
이 글에서 저는 Laradock을 사용하여 Laravel 개발 환경을 구축하는 절차를 쓰고 싶습니다.
평소 개발 환경은 Laradock을 사용하지 않았지만, 최근부터 Laravel을 접한 사람들로부터 Laradock의 개발 환경 구축에 걸림돌(migrate 실패)이라는 문의를 받았을 때 해결 방법을 제대로 제시하지 못했기 때문에나도 한번 만져봤어 (PHP 프레임워크 라라벨 웹 어플리케이션 개발을 참고했다고 해서 본 기사에서도 같은 순서로 써 봤어
라라독이 뭐예요?
Laradock is a full PHP development environment based on Docker.
요컨대 Docker를 바탕으로 Laravel의 개발 환경을 제공했다.(자세한 내용은 참조공식 홈페이지, 이해하기 쉬울 수 있음
환경 생성 단계
전제 조건
Laradock 다운로드
# 作業ディレクトリ作成
$ mkdir laravel_docker
# 移動
$ cd laravel_docker
# laradockをclone
$ git clone https://github.com/LaraDock/laradock.git
컨테이너 초기화
# laradockディレクトリに移動
$ cd laradock
# envファイルをコピー
$ cp env-example .env
# コンテナの起動 (若干時間かかる)
$ docker-compose up -d nginx mysql workspace phpmyadmin
# コンテナがちゃんと起動してるか確認
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
42218ff4fdeb laradock_phpmyadmin "/docker-entrypoint.…" 10 seconds ago Up 8 seconds 0.0.0.0:8080->80/tcp laradock_phpmyadmin_1
ce8875359faa laradock_nginx "/bin/bash /opt/star…" 47 seconds ago Up 9 seconds 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp laradock_nginx_1
229e9c9b0fb9 laradock_php-fpm "docker-php-entrypoi…" 49 seconds ago Up 47 seconds 9000/tcp laradock_php-fpm_1
3f398da51a14 laradock_workspace "/sbin/my_init" 50 seconds ago Up 48 seconds 0.0.0.0:2222->22/tcp laradock_workspace_1
761b70cc0bd2 laradock_mysql "docker-entrypoint.s…" 51 seconds ago Up 10 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp laradock_mysql_1
8f28241ced91 docker:dind "dockerd-entrypoint.…" 51 seconds ago Up 49 seconds 2375-2376/tcp laradock_docker-in-docker_1
Laravel 프로젝트 만들기
# workspaceコンテナに接続
$ docker-compose exec --user=laradock workspace bash
# Laravelプロジェクト作成
$ composer create-project laravel/laravel sampleapp --prefer-dist "6.*.*"
# コンテナから出る
$ exit
.env
파일 설정 변경# Point to the path of your applications code on your host
APP_CODE_PATH_HOST=../
# Point to the path of your applications code on your host
APP_CODE_PATH_HOST=../sampleapp
# サービスの停止
$ docker-compose stop
# サービスの起動
$ docker-compose up -d nginx mysql
http://localhost
, Laravel의 Welcom 화면에서 표시를 확인할 수 있는 경우phpartisanmigrate 실행 가능 여부 확인
laradock@fd5cdbe63d4b:/var/www$ php artisan migrate
Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')
at /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:665
661| // If an exception occurs when attempting to run a query, we'll format the error
662| // message to include the bindings with SQL, which will make this exception a
663| // lot more helpful to the developer instead of just the database's errors.
664| catch (Exception $e) {
> 665| throw new QueryException(
666| $query, $this->prepareBindings($bindings), $e
667| );
668| }
669|
Exception trace:
1 PDOException::("SQLSTATE[HY000] [2002] Connection refused")
/var/www/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
2 PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=laravel", "root", "", [])
/var/www/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
Please use the argument -v to see more details.
.env
을 설정하지 않았기 때문에 Laradock의 기본 설정에 따라 수정된 것 같습니다 DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=default
DB_USERNAME=default
DB_PASSWORD=secret
php artisan migrate
다음과 같은 오류가 발생laradock@fd5cdbe63d4b:/var/www$ php artisan migrate
Illuminate\Database\QueryException : SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from information_schema.tables where table_schema = default and table_name = migrations and table_type = 'BASE TABLE')
at /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:665
661| // If an exception occurs when attempting to run a query, we'll format the error
662| // message to include the bindings with SQL, which will make this exception a
663| // lot more helpful to the developer instead of just the database's errors.
664| catch (Exception $e) {
> 665| throw new QueryException(
666| $query, $this->prepareBindings($bindings), $e
667| );
668| }
669|
Exception trace:
1 PDOException::("PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password]")
/var/www/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
2 PDO::__construct("mysql:host=mysql;port=3306;dbname=default", "default", "secret", [])
/var/www/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
Please use the argument -v to see more details.
$ docker exec -it laradock_mysql_1 sh
# mysql -uroot -proot -A
mysql> alter user 'default'@'%' identified with mysql_native_password by 'secret';
mysql/my.cnf
(추가default_authentication_plugin=mysql_native_password
# The MySQL Client configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
[mysql]
[mysqld]
sql-mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
character-set-server=utf8
default_authentication_plugin=mysql_native_password // ⬅️追加
php artisan migrate
.잘 되고 있으니까 괜찮아요 laradock@fd5cdbe63d4b:/var/www$ php artisan migrate
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_000000_create_users_table (0.07 seconds)
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated: 2014_10_12_100000_create_password_resets_table (0.04 seconds)
Migrating: 2019_08_19_000000_create_failed_jobs_table
Migrated: 2019_08_19_000000_create_failed_jobs_table (0.02 seconds)
총결산
참고 자료
Reference
이 문제에 관하여(Laradock을 이용하여 Laravel 개발 환경 만들기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/20092014/items/f695baf430c823597bfd텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)