Build a Laravel environment on an AWS instance

Create an instance

・ Perform with EC2 (details omitted) image.png

-Open the HTTP port with inbound rules image.png

Install the required packages

Docker

$ sudo yum update -y
$ sudo yum install docker
$ sudo service docker start
$ sudo usermod -a -G docker ec2-user

Docker-compose

$ sudo curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose

Docker image (Laradock)

・ Select Laradock that includes all the packages required to build the Laravel environment.

$ git clone https://github.com/Laradock/laradock.git
$ cd laradock
$ cp env-example .env
#Execute the service required for execution
$ docker-compose up -d nginx mysql phpmyadmin redis workspace
#Check if it is working
$ docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                                                                                                            NAMES
ccb046bd18d9        laradock_nginx        "/docker-entrypoint.…"   6 minutes ago       Up 6 minutes        0.0.0.0:80-81->80-81/tcp, 0.0.0.0:443->443/tcp                                                                                   laradock_nginx_1
ebdc1a33503a        laradock_php-fpm      "docker-php-entrypoi…"   6 minutes ago       Up 6 minutes        9000/tcp                                                                                                                         laradock_php-fpm_1
0c3e361c4626        laradock_phpmyadmin   "/docker-entrypoint.…"   6 minutes ago       Up 6 minutes        0.0.0.0:8081->80/tcp                                                                                                             laradock_phpmyadmin_1
361e0a4fa898        laradock_workspace    "/sbin/my_init"          6 minutes ago       Up 6 minutes        0.0.0.0:3000-3001->3000-3001/tcp, 0.0.0.0:4200->4200/tcp, 0.0.0.0:8080->8080/tcp, 0.0.0.0:2222->22/tcp, 0.0.0.0:8001->8000/tcp   laradock_workspace_1
1a5246349a6d        laradock_mysql        "docker-entrypoint.s…"   6 minutes ago       Up 6 minutes        0.0.0.0:3306->3306/tcp, 33060/tcp                                                                                                laradock_mysql_1
09477490bbec        laradock_redis        "docker-entrypoint.s…"   6 minutes ago       Up 6 minutes        0.0.0.0:6379->6379/tcp                                                                                                           laradock_redis_1
53ded2d4fab3        docker:19.03-dind     "dockerd-entrypoint.…"   6 minutes ago       Up 6 minutes        2375-2376/tcp                                                                                                                    laradock_docker-in-docker_1

・ Store personal projects in the workspace

#Coulomb
$ git clone https://github.com/lineapple0601/laravel_vue_practice.git
$ exit

-Reset the root path of the app in the .env file

.env


APP_CODE_PATH_HOST=../laravel_vue_practice

-Restart docker so that it can be started in a personal project

$ docker-compose stop
$ docker-compose up -d nginx mysql phpmyadmin redis workspace

-Update composer and other settings (it is best to put it in docker-compose.yml, but do it manually)

$ docker exec -it 46a935162a22 /bin/bash
$ composer update
$ php artisan key:generate

-Permission setting in log cache system

$ chmod 644 -R storage
$ chmod 644 -R bootstrap/cache
$ chown laradock:laradock -R storage
$ chown laradock:laradock -R bootstrap/cache

・ Try to access from the public IP on the AWS side image.png Successful access! </ b>

DB server construction

Since Mysql is included in Laradock, it has already been built by starting docker-compose Confirm mysql container startup

$ docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                                                                                                            NAMES
63222479c01a        laradock_nginx        "/docker-entrypoint.…"   20 minutes ago      Up 20 minutes       0.0.0.0:80-81->80-81/tcp, 0.0.0.0:443->443/tcp                                                                                   laradock_nginx_1
a300f914e763        laradock_php-fpm      "docker-php-entrypoi…"   20 minutes ago      Up 20 minutes       9000/tcp                                                                                                                         laradock_php-fpm_1
46a935162a22        laradock_workspace    "/sbin/my_init"          20 minutes ago      Up 20 minutes       0.0.0.0:3000-3001->3000-3001/tcp, 0.0.0.0:4200->4200/tcp, 0.0.0.0:8080->8080/tcp, 0.0.0.0:2222->22/tcp, 0.0.0.0:8001->8000/tcp   laradock_workspace_1
b4f6d0dbb16c        docker:19.03-dind     "dockerd-entrypoint.…"   20 minutes ago      Up 20 minutes       2375-2376/tcp                                                                                                                    laradock_docker-in-docker_1
0c3e361c4626        laradock_phpmyadmin   "/docker-entrypoint.…"   2 hours ago         Up 20 minutes       0.0.0.0:8081->80/tcp                                                                                                             laradock_phpmyadmin_1
1a5246349a6d        laradock_mysql        "docker-entrypoint.s…"   2 hours ago         Up 20 minutes       0.0.0.0:3306->3306/tcp, 33060/tcp                                                                                                laradock_mysql_1
09477490bbec        laradock_redis        "docker-entrypoint.s…"   2 hours ago         Up 20 minutes       0.0.0.0:6379->6379/tcp                                                                                                           laradock_redis_1

Try to access from an external DB tool with the following information

docker-compose.yml


### MYSQL #################################################
MYSQL_VERSION=latest
MYSQL_DATABASE=default
MYSQL_USER=default
MYSQL_PASSWORD=secret
MYSQL_PORT=3306
MYSQL_ROOT_PASSWORD=root
MYSQL_ENTRYPOINT_INITDB=./mysql/docker-entrypoint-initdb.d

image.png image.png

Successful access!

Recommended Posts