Deploy laravel using docker on EC2 on AWS ④ (git clone ~ deploy, migration)

Overview##

-I will write the process of deploying laravel / docker on AWS for those who are stuck at the same point as the point where they are stuck.

Clone Git inside an EC2 instance

Clone any laravel project in Git's remote repository into an EC2 instance.

root@ip:/home/ubuntu# git clone [Any repository URL]

Launching Docker container

Move to your cloned folder (where docker-compose.yml is) and launch the container.

root@ip:/home/ubuntu/awstest# docker-compose up -d
root@ip:/home/ubuntu/awstest# docker-compose ps
    Name                   Command               State           Ports        
------------------------------------------------------------------------------
awstest_app_1   docker-php-entrypoint php-fpm    Up      9000/tcp             
awstest_db_1    docker-entrypoint.sh mysqld      Up      3306/tcp, 33060/tcp  
awstest_web_1   /docker-entrypoint.sh ngin ...   Up      0.0.0.0:10080->80/tcp

It's OK if you stand up like this.

** Where I struggled ** I got a version error of docker-compose.yml and according to the error content

root@ip-172-31-35-36:/home/ubuntu/awstest# vi docker-compose.yml
version: "3.3" ←3.8 to 3.Change to 3
  

And version changed. Furthermore, because the push to git was wrong, there was no docker related file and it did not start. I don't think there is anyone other than myself who makes such mistakes, but if there is the same person, please check the file.

Laravel Preferences

We will set the environment so that Laravel can be used. Enter the app container.

root@ip:/home/ubuntu/awstest# docker-compose exec app bash

The .env file that sets the environment in the Laravel project is specified in .gitignore, so it will not be pushed to the Git repository. So I will create it again.

root@:/work# cp .env.example .env

After creating the .env, issue composer install, and also issue APP_KEY.

root@:/work# composer install

root@:/work# php artisan key:generate

Change permissions in the project

Change permissions on files in your project.

Normally, it seems OK if you change the permissions of storage / logs and vendor.

Again, an error occurred and I struggled a little.

View won't open with file_put_contents error

root@:/work# chmod 777 storage/logs vendor
root@:/work# chmod 777 storage/framework/views
root@:/work# chmod 777 storage/framework/sessions

The TOP page has finally opened.

Access http: // [Set Elastic IP Address]: 10080 from a browser.

スクリーンショット 2020-10-11 13.54.08.png

If it is displayed like this, it is OK.

Perform migration

root@:/work# php artisan migrate
root@:/work# php aritsan db:seed

If you do so far, I think that the locally created application will work.

This is the end of "Deploying laravel using docker on EC2 on AWS". Thank you very much.

** Previous article ** Deploy laravel using docker on EC2 on AWS ③

** Please point out any mistakes **

Recommended Posts

Deploy laravel using docker on EC2 on AWS ④ (git clone ~ deploy, migration)
Deploy laravel using docker on EC2 on AWS ① (Create EC2 instance)
Deploy laravel using docker on EC2 on AWS ② (Elastic IP acquisition-linking)
Deploy laravel using docker on EC2 on AWS ③ (SSH connection ~ Docke-compose installation)
Deploy with EC2 / Docker / Laravel
Install docker on AWS EC2
Deployed using Docker + Rails + AWS (EC2 + RDS)
Deploy RAILS on EC2
[Docker] Build an Apache container on EC2 using dockerfile
Creating a docker host on AWS using Docker Machine (personal memorandum)
Install Docker on AWS Ubunt 20.04 LTS
How to deploy Laravel on CentOS 7
Try using Redmine on Mac docker
To beginners launching Docker on AWS
Run the AWS CLI on Docker
Deploy Flask's Docker image on Heroku
Deploy Rails on Docker to heroku
Deploy SpringBoot application to AWS EC2
Using Docker on Windows10 Home WSL2
[For beginners] Laravel Docker AWS (EC2) How to easily deploy a web application (PHP) from 0 (free) ①-Overview-
[AWS ELB] Using ELB and Docker, EC2 has two domains for WEB servers.
EFS mount on AWS Ubuntu EC2 (amazon-efs-utils)
Launch docker container on EC2 (personal memorandum)
Using Java with AWS Lambda-Implementation-Stop / Launch EC2
Send an email using JavaMail on AWS
Deploy your application with VPC + EC2 + Docker.
Build an environment with Docker on AWS
Try the Docker environment on AWS ECS