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
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
.
http://dl-cdn.alpinelinux.org/alpine/edge/community
to the/etc/apk/repositories
file, the repository was added and the installation was successful.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
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
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.
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