I tried to build a laravel operating environment while remembering Docker

Introduction

I remembered the contents of docker that I was working on a while ago and tried to build the operating environment of laravel. In the past, I have built the environment based on the reference site that I googled with docker laravel environment construction etc. Starting from the alpine official image (clean installation state?), We built the PHP operating environment + introduced nginx + installed laravel and linked with nginx. Since I succeeded in building the environment safely, I created a review article with the meaning of this summary.

The completed contents are published in the following repository

Posted by Spec

Stumble / worried points

Part 1: I can't find it when I try to install PHP7 via the package manager (apk)

This time I used alpine 3.12 which was the latest as of November 2020, but when I used the latest alpine version, I could not find PHP itself and PHP related packages ... Finally, by adding the repository referenced by apk, I was able to install PHP itself and PHP related packages with apk add package name.

Part 2: Successful installation of php-fpm → php-fpm not found

apk add php -fpm If I think I was able to install it, php-fpm not found is displayed even if I run php-fpm -v ... As a result, it was installed under the/usr/sbin/directory under the name php-fpm7. In my case, it will be one more character, but I thought that php-fpm7 would be fine, so I continued to execute commands with php-fpm7, but If you really want to run it with php-fpm, you can create a symbolic link with php-fpm naming for php-fpm7.

Where is the apk installation directory through this case? I searched a lot, but During my research, I found out that the bin directory sbin directory has a role. I casually touched the bin directory on my Mac, but I didn't know it had a role (´ ・ ω:;.: ... The following materials were referred to during the survey

--Linux/bin,/usr/bin, $ HOME/bin roles

Part 3: Laravel and nginx don't work together

Introducing nginx → The welcome screen was displayed successfully, and the process of creating a laravel project via composer went smoothly. However, when I tried to link nginx and laravel, nginx did not return the page output of laravel. The reason why it didn't work was that I edited the nginx config file and the php-fpm config file and it responded well. I didn't know the settings of nginx or php-fpm at all, so this took the longest time to resolve.

--nginx configuration file (/etc/nginx/conf.d/default.conf)

server {
    listen 80;
    server_name  localhost;

    access_log  /var/log/nginx/laravelProject/access.log  main;
    error_log   /var/log/nginx/laravelProject/error.log  warn;
    #Set to refer to public of laravel project below
    root /www/laravelProject/public;

    location / {
        index index.php index.html;
        try_files $uri $uri/ /index.php$is_args$args;
    }
    
    #FastCGI connection settings when running php file
    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
[www]

user = nginx
group = nginx

listen =/var/run/php-fpm/php-fpm.sock
listen.owner = nginx
listen.group = nginx

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

Part 4: Host and container directory synchronization results in an empty directory

In the dockerfile, I first confirmed that the laravel project was created and worked in the container with composer create-project laravel/laravel = 5.5 project name. Since I was able to build a laravel operating environment to some extent, I mounted the host and container in the synchronous directory → When I executed the laravel project installation in the synchronous directory destination, it became an empty directory.

Finally, after the container was built once, I was able to successfully deploy it in the sync directory by executing the create laravel project command via docker exec. To be honest, I don't think this method is the correct answer, so I'm still investigating the cause.

Summary

Until now, I had never built an environment from a clean installation of a Linux OS, so I had a lot of trouble. However, what I learned from achieving my initial goal was also fresh. It is important that you do not break or give up on the way. Honestly, there is an official / unofficial image that can build a PHP operating environment container based on __alpine, so if you use that as the base image, you don't have to do this. The mysterious self-satisfaction that I was able to build an environment by introducing the minimum necessary middleware was satisfied. Above all, when learning a Linux-based OS, I was able to try various things from a clean-installed state and experiment, so that was more rewarding. : thumbsup: After all, I was able to reconfirm that Docker is convenient because it can be immediately destroyed → rebuilt if it fails by touching it.

that's all!!

Recommended Posts

I tried to build a laravel operating environment while remembering Docker
I tried to build a Firebase application development environment with Docker in 2020
I tried to build an environment using Docker (beginner)
I tried to build the environment little by little using docker
I tried to build the environment of WSL2 + Docker + VSCode
I tried to create a padrino development environment with Docker
I tried to build the environment of PlantUML Server with Docker
Build a Laravel / Docker environment with VSCode devcontainer
I tried to create a portfolio with AWS, Docker, CircleCI, Laravel [with reference link]
Try to build a Java development environment using Docker
I tried to create a java8 development environment with Chocolatey
I tried to create React.js × TypeScript × Material-UI on docker environment
Build a Node-RED environment with Docker to move and understand
Build docker + laravel environment with laradock
[Rails 6.0, Docker] I tried to summarize the Docker environment construction and commands necessary to create a portfolio
I tried to build an http2 development environment with Eclipse + Tomcat
I tried to create a Spring MVC development environment on Mac
I tried to build a simple application using Dockder + Rails Scaffold
Build a PureScript development environment with Docker
Build a WAS execution environment from Docker
Build a Wordpress development environment with Docker
What is Docker? I tried to summarize
I tried to build Ruby 3.0.0 from source
How to build Rails 6 environment with Docker
Build a simple Docker + Django development environment
01. I tried to build an environment with SpringBoot + IntelliJ + MySQL (MyBatis) (Windows10)
[Copy and paste] Build a Laravel development environment with Docker Compose Part 2
I tried migrating the portfolio created on Vagrant to the Docker development environment
I tried to make a machine learning application with Dash (+ Docker) part1 ~ Environment construction and operation check ~
When I tried to build an environment of PHP7.4 + Apache + MySQL with Docker, I got stuck [Windows & Mac]
Build a development environment for Docker + Rails6 + Postgresql
I tried to verify AdoptOpenJDK 11 (11.0.2) with Docker image
java I tried to break a simple block
Build a WordPress development environment quickly with Docker
I tried to develop a man-hour management tool
I tried to develop a DUO3.0 study website.
I tried to create a LINE clone app
Build a simple Docker Compose + Django development environment
Build a Laravel environment on an AWS instance
Build a container for Docker x Laravel phpMyAdmin
I tried running Ansible on a Docker container
I tried to build Micra mackerel in 1 hour!
Build a development environment for Docker, java, vscode
I tried to develop a website to record expenses.
How to build a Pytorch environment on Ubuntu
I tried to implement a server using Netty
I tried to break a block with java (1)
I tried to make a machine learning application with Dash (+ Docker) part3 ~ Practice ~
I installed WSL2 without using Microsoft Store and tried to build an environment where Docker can be used
Memo to build a Servlet environment on AWS EC2
[Road _node.js_1-1] Road to build Node.js Express MySQL environment using Docker
I tried to develop a ramen shop sharing website.
How to build docker environment with Gradle for intelliJ
I tried to summarize the state transition of docker
[Rails] [Docker] Copy and paste is OK! How to build a Rails development environment with Docker
I tried to decorate the simple calendar a little
Easily build a Vue.js environment with Docker + Vue CLI
Build Docker + Laravel PHP + Vue.js development environment in 5 minutes
I tried to create a Clova skill in Java
I tried to make a login function in Java
[Note] Build a Python3 environment with Docker in EC2