【Docker compose】lamp+Laravle環境を作るpart2

前回はホスト側にComposerをインストールするところまで行いました

今回はComposerを使ってLaravelをインストールしてLaravelプロジェクトをホスト側に作成します

こちらの記事を参考にさせていただきました

ホスト側でcomposerを使ってlaravelをインストール

ここrootで実行しちゃってますが基本的にcomposerコマンドはrootではないほうがよいので注意

[root@dev381 ~]# composer global require “laravel/installer”
Changed current directory to /root/.config/composer
Using version ^1.3 for laravel/installer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 10 installs, 0 updates, 0 removals
– Installing symfony/process (v3.3.2): Downloading (100%)
– Installing psr/log (1.0.2): Downloading (100%)
– Installing symfony/debug (v3.3.2): Downloading (100%)
– Installing symfony/polyfill-mbstring (v1.4.0): Downloading (100%)
– Installing symfony/console (v3.3.2): Downloading (100%)
– Installing guzzlehttp/promises (v1.3.1): Downloading (100%)
– Installing psr/http-message (1.0.1): Downloading (100%)
– Installing guzzlehttp/psr7 (1.4.2): Downloading (100%)
– Installing guzzlehttp/guzzle (6.2.3): Downloading (100%)
– Installing laravel/installer (v1.3.4): Downloading (100%)
symfony/console suggests installing symfony/event-dispatcher ()
symfony/console suggests installing symfony/filesystem ()
Writing lock file
Generating autoload files

ホスト側でLaravelプロジェクトを作成

[sawaryot@dev381 dev1]# composer create-project laravel/laravel MyFirstLaravel
Installing laravel/laravel (v5.4.23)
– Installing laravel/laravel (v5.4.23): Downloading (100%)
Created project in MyFirstLaravel
> php -r “file_exists(‘.env’) || copy(‘.env.example’, ‘.env’);”
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
– phpunit/phpunit 5.7.9 requires ext-dom * -> the requested PHP extension dom is missing from your system.
– phpunit/phpunit 5.7.8 requires ext-dom * -> the requested PHP extension dom is missing from your system.
– phpunit/phpunit 5.7.7 requires ext-dom * -> the requested PHP extension dom is missing from your system.
– phpunit/phpunit 5.7.6 requires ext-dom * -> the requested PHP extension dom is missing from your system.
– phpunit/phpunit 5.7.5 requires ext-dom * -> the requested PHP extension dom is missing from your system.
– phpunit/phpunit 5.7.4 requires ext-dom * -> the requested PHP extension dom is missing from your system.
– phpunit/phpunit 5.7.3 requires ext-dom * -> the requested PHP extension dom is missing from your system.
– phpunit/phpunit 5.7.20 requires ext-dom * -> the requested PHP extension dom is missing from your system.
– phpunit/phpunit 5.7.2 requires ext-dom * -> the requested PHP extension dom is missing from your system.
– phpunit/phpunit 5.7.19 requires ext-dom * -> the requested PHP extension dom is missing from your system.
– phpunit/phpunit 5.7.18 requires ext-dom * -> the requested PHP extension dom is missing from your system.
– phpunit/phpunit 5.7.17 requires ext-dom * -> the requested PHP extension dom is missing from your system.
– phpunit/phpunit 5.7.16 requires ext-dom * -> the requested PHP extension dom is missing from your system.
– phpunit/phpunit 5.7.15 requires ext-dom * -> the requested PHP extension dom is missing from your system.
– phpunit/phpunit 5.7.14 requires ext-dom * -> the requested PHP extension dom is missing from your system.
– phpunit/phpunit 5.7.13 requires ext-dom * -> the requested PHP extension dom is missing from your system.
– phpunit/phpunit 5.7.12 requires ext-dom * -> the requested PHP extension dom is missing from your system.
– phpunit/phpunit 5.7.11 requires ext-dom * -> the requested PHP extension dom is missing from your system.
– phpunit/phpunit 5.7.10 requires ext-dom * -> the requested PHP extension dom is missing from your system.
– phpunit/phpunit 5.7.1 requires ext-dom * -> the requested PHP extension dom is missing from your system.
– phpunit/phpunit 5.7.0 requires ext-dom * -> the requested PHP extension dom is missing from your system.
– Installation request for phpunit/phpunit ~5.7 -> satisfiable by phpunit/phpunit[5.7.0, 5.7.1, 5.7.10, 5.7.11, 5.7.12, 5.7.13, 5.7.14, 5.7.15, 5.7.16, 5.7.17, 5.7.18, 5.7.19, 5.7.2, 5.7.20, 5.7.3, 5.7.4, 5.7.5, 5.7.6, 5.7.7, 5.7.8, 5.7.9].

To enable extensions, verify that they are enabled in your .ini files:
– /etc/php.ini
– /etc/php.d/20-bz2.ini
– /etc/php.d/20-calendar.ini
– /etc/php.d/20-ctype.ini
– /etc/php.d/20-curl.ini
– /etc/php.d/20-exif.ini
– /etc/php.d/20-fileinfo.ini
– /etc/php.d/20-ftp.ini
– /etc/php.d/20-gd.ini
– /etc/php.d/20-gettext.ini
– /etc/php.d/20-iconv.ini
– /etc/php.d/20-json.ini
– /etc/php.d/20-mbstring.ini
– /etc/php.d/20-pdo.ini
– /etc/php.d/20-phar.ini
– /etc/php.d/20-sockets.ini
– /etc/php.d/20-sqlite3.ini
– /etc/php.d/20-tokenizer.ini
– /etc/php.d/30-pdo_sqlite.ini
You can also run `php –ini` inside terminal to see which files are used by PHP in CLI mode.

以下のようなエラー

・phpunit/phpunit 5.7.0~5.7.9には ext-dom が必要
・きみのシステムにPHP extension domをリクエストしたけどなかった

こちらの記事を参考にしてDOM Extensionをインストールしてみる

[root@dev381 dev1]# yum install php-xml
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: ftp.riken.jp
* epel: mirror01.idc.hinet.net
* extras: ftp.riken.jp
* remi-safe: mirrors.thzhost.com
* updates: ftp.riken.jp
Resolving Dependencies
–> Running transaction check
—> Package php-xml.x86_64 0:5.4.16-42.el7 will be installed
–> Processing Dependency: php-common(x86-64) = 5.4.16-42.el7 for package: php-xml-5.4.16-42.el7.x86_64
–> Processing Dependency: libxslt.so.1(LIBXML2_1.0.24)(64bit) for package: php-xml-5.4.16-42.el7.x86_64
–> Processing Dependency: libxslt.so.1(LIBXML2_1.0.22)(64bit) for package: php-xml-5.4.16-42.el7.x86_64
–> Processing Dependency: libxslt.so.1(LIBXML2_1.0.18)(64bit) for package: php-xml-5.4.16-42.el7.x86_64
–> Processing Dependency: libxslt.so.1(LIBXML2_1.0.13)(64bit) for package: php-xml-5.4.16-42.el7.x86_64
–> Processing Dependency: libxslt.so.1(LIBXML2_1.0.11)(64bit) for package: php-xml-5.4.16-42.el7.x86_64
–> Processing Dependency: libxslt.so.1()(64bit) for package: php-xml-5.4.16-42.el7.x86_64
–> Processing Dependency: libexslt.so.0()(64bit) for package: php-xml-5.4.16-42.el7.x86_64
–> Running transaction check
—> Package libxslt.x86_64 0:1.1.28-5.el7 will be installed
—> Package php-xml.x86_64 0:5.4.16-42.el7 will be installed
–> Processing Dependency: php-common(x86-64) = 5.4.16-42.el7 for package: php-xml-5.4.16-42.el7.x86_64
–> Finished Dependency Resolution
Error: Package: php-xml-5.4.16-42.el7.x86_64 (base)
Requires: php-common(x86-64) = 5.4.16-42.el7
Installed: php-common-7.0.20-1.el7.remi.x86_64 (@remi-php70)
php-common(x86-64) = 7.0.20-1.el7.remi
Available: php-common-5.4.16-42.el7.x86_64 (base)
php-common(x86-64) = 5.4.16-42.el7
You could try using –skip-broken to work around the problem
You could try running: rpm -Va –nofiles –nodigest

再度Laravelプロジェクトを作ってみるが変わらない・・・

こちらの記事を見るとphp7系のじゃないとだめっぽいのかな

ということで7系のやつで再度php-xmlをインストール

sudo yum -y install --enablerepo=remi-php71 php-xml

もっかいLaravelプロジェクトを作ってみるとできた

作り終わるまでに10分ちょいくらいかかった

最後に以下のメッセージが出ればおk

Application key [base64:(ランダムな英数列)] set successfully.

プロジェクトの設定

DB情報やホスト情報を以下のファイルに書き込む

[sawaryot@dev381 ~]$ vi MyFirstLaravel/.env

以下のような情報で保存

DB_HOST=l72.XX.X.XXX
DB_DATABASE=testdb
DB_USERNAME=root
DB_PASSWORD=pass

DB_HOSTはDocker上で動いているmysqlコンテナのホストを指定します。
DB_DATABASEにはデータベース名を指定します。
あらかじめmysqlに作成しておきましょう。
ユーザー名とパスワードも設定に合わせて指定します。

次回はlampのDockerコンテナと組み合わせます

シェアする

  • このエントリーをはてなブックマークに追加

フォローする