1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

(備忘録)実録centoOSでdockerアプリを稼働させようとしたらめちゃくちゃ大変だった話

Last updated at Posted at 2021-07-02

docker で作成されたプロジェクトと用意されたcento OSサーバーがすでにあり、
centOSのサーバー上でgit cloneなどでdockerプロジェクトを持ってきたあとコンテナを立ち上げたいと思っていた。

サーバーに対する知識は皆無でどうやってデプロイすんのかもよくわかっていなかったので調べ調べにやってみました。
やってみたら色々たらい回しにされてめちゃくちゃ大変だったという話。
備忘録を兼ねて書いてるので参考にはなりません。。。
ちなみにcentosにした理由は”名前を聞いたことがあったから”その程度の知識です。

やってみる

さて、どうやってデプロイしようかと考えていたところ
winscpでやるのがおすすめらしいのでインストール後、
winscpで接続したあとwinscpのコンソールを開いてgit cloneをしたが以下のエラーが発生。

Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

git clone 元のリポジトリがprivateなので権限が無いのかと思いssh-keygen -t rsa -b 4096 -C "メールアドレス"でssh鍵を生成してgithubにあげようと思ったが、エラーが起きてkeygenが中断される。

見てみるとwinscpのコンソールには「ユーザ入力やデータ転送が必要なコマンドは実行しないでください」と書かれていて、ユーザー入力が必要なコマンドだとエラーが起きる。

WinSCP.com(紛らわしいが上記とは別のコンソール)のコンソールも試したが不明なコマンド 'ssh-keygen'.とでるのでもうWinSCPはもうだめだ…

そういうわけでWinSCPではうんともすんとも言わないのでteratermをインストールして切り替えることに。
以降コマンドはteratermで実行。

teratermではkeygenが無事できるのでkeygenしてpub-keyをgithubに貼りgit cloneをした。

# cat ~/.ssh/id_rsa.pub

docker compose up -d をしたいので以下の記事を参考にdocker-composeをできるように

そして
docker compose up -d

コンテナが立ち上がった。
つないでみると…

Warning: require(/work/backend/public/../vendor/autoload.php): Failed to open stream: No such file or directory in /work/backend/public/index.php on line 34

謎のエラー
どうやら(/work/backend/public/../vendor/autoload.php)がないのがいけないらしい。
調べてみるとcomposer installでインスコできる来のでコマンドを入力してみる。

command not found: composer

コマンドが見つからない。そういえばまだcomposer自体をインストールしていなかった。

以下の記事を参考にcomposerをインスコしようと試みる

手順通りに
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
とコマンドを入力したら。

-bash: php: command not found

phpコマンドもかーい!!!

phpを先にインストールしなけらばならないという事で以下を参考にインストール

先に行っておくとやらかしました。これでインストールしたphpのバージョンは7.2
後々になって問題になってきます。

再度上記を参考にcomposerをインストール

# php composer-setup.php
Some settings on your machine make Composer unable to work properly.
Make sure that you fix the issues listed below and run this script again:

The json extension is missing.
Install it or recompile php without --disable-json

またなんか言われてら、、、

結局調べてもよくわからないので、他のサイトを探してみる。

なんかよさそう。

取り敢えず手順通りにしてみる。
successがでた。ほとんど手順が一個目のサイトと変わらないのに、どうして???

このままではcomposerコマンドをルートディレクトリでしか使えないのでどこでも使えるようにする。

# mv composer.phar /usr/local/bin/composer

そしてlaravel のディレクトリに移りcomposer install。

# composer install
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Your lock file does not contain a compatible set of packages. Please run composer update.

  Problem 1
    - Root composer.json requires php ^7.3|^8.0 but your php version (7.2.24) does not satisfy that requirement.
  Problem 2
    - doctrine/dbal is locked to version 3.1.1 and an update of this package was not requested.
    - doctrine/dbal 3.1.1 requires php ^7.3 || ^8.0 -> your php version (7.2.24) does not satisfy that requirement.

なんかいろいろ言われているが要するに必要とされているPHPのバージョンが7.3以上なのに対してインスコされているバージョンが7.2なのでエラーが起きている。
これはやってしまいましたね…

PHPのバージョンを上げなければ。

# yum remove php*

でとりあえずphpを全部消す。

そしてPHP7.4を上記を参考にインストール。

できた!!php -vで確認してもちゃんと7.4だ

これでcomposer installもできるはず

# composer install

できた。

取り敢えずサイトを開いてみる。
そしたらlaravelのエラー画面で以下の文言がでてきた。

The stream or file "/work/backend/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied

権限がないらしい。
larvel project下で以下のコマンドで権限を変え読み取れるように。

# chmod -R 777 storage

そしてマイグレーション
php artisan migrate

# php artisan migrate

   Error

  Class 'PDO' not found

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:1409
    1405?      * @return mixed
    1406?      */
    1407?     public static function getResolver($driver)
    1408?     {
  ? 1409?         return static::$resolvers[$driver] ?? null;
    1410?     }
    1411? }
    1412?

      +25 vendor frames
  26  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()

なんかエラー出たが??

上記参考に解決。PHPのバージョンが参考サイトと違うので読み替えて。

could not find driver (SQL: select * from information_schema.tables where table_schema = laravel_local and table_name = migrations and table_type = 'BASE TABLE')

こんどはドライバが見つからないらしい

上記を参考に

$ php -m | grep pdo
pdo_sqlite

初期だとsqliteしか入っていないらしい。mysqlが必要だ

$ sudo yum -y install --enablerepo=remi,remi-php74 php-mysqlnd

上記のコマンドを実行後再度確認。

$ php -m | grep pdo
pdo_mysql
pdo_sqlite
$ sudo service httpd restart

Apacheを再起動
再度php artisan migrate

出来た。

そしてwebサイトを開いてみる。

開いた!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

完走した感想: やること多すぎじゃないですかね。

ちなみにトータル4時間くらいかかりました。

疲れた…

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?