1
0

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.

DockerのPHP公式コンテナを拡張してComposerとlaravelインストーラーをインストールする

Posted at

dockerfile

FROM php:7.4-apache
RUN apt-get update \
  && apt-get install -y --no-install-recommends \
    vim \
    libonig-dev \
    libzip-dev
RUN docker-php-ext-install \
    pdo_mysql \
    mysqli \
    mbstring \
    zip
RUN apt-get install -y curl git unzip

# https://getcomposer.org/download/ に差し替える
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
RUN php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
RUN php composer-setup.php
RUN php -r "unlink('composer-setup.php');"
# https://getcomposer.org/download/ に差し替える ここまで

# mvでなぜかディレクトリが作成されてしまうのでシンボリックリンクを貼る
RUN mv ./composer.phar $(dirname $(which php))
RUN chmod +x $(dirname $(which php))/composer.phar
RUN ln -s $(dirname $(which php))/composer.phar /usr/bin/composer
RUN composer global require laravel/installer
RUN a2enmod rewrite

ENV PATH $PATH:/root/.composer/vendor/bin

実行

$ docker compose build
$ docker compose up -d
$ docker compose exec php sh
# laravel new stock               

 _                               _
| |                             | |
| |     __ _ _ __ __ ___   _____| |
| |    / _` | '__/ _` \ \ / / _ \ |
| |___| (_| | | | (_| |\ V /  __/ |
|______\__,_|_|  \__,_| \_/ \___|_|

参考

1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?