[DevOps] How to create a Dockerfile and Docker Compose for PHP8 Service

0
43

✋✋✋Hello everyone, welcome back to Learn Tech Tips Blogspot. I am Zidane (大家好, 我是雞蛋🥚🥚)

Nice to meet you back. Today I will show you How to create a Dockerfile and Docker Compose for PHP8 Service, so you can start server no need download any MAMP, WAMP, nginx …

Wow, That sound good, I no need to download any heavy things just want to run a small php 8 (include server inside). Ok let discovery now.

As you know when you working with Docker, you should know what is Docker? 

If you are new in docker  you can check below information. 

👇

“Docker is a set of platform as a service products that use OS-level virtualization to deliver software in packages called containers. The service has both free and premium tiers. The software that hosts the containers is called Docker Engine. It was first started in 2013 and is developed by Docker, Inc”

If you already know docker, you can go through this topic right now.  

Before enter the topic, I want to share with you my tiktok account and my fan page.

👉 Tiktok

👉 Facebook:

Ok. Let’s back to topic

How to create a Dockerfile and Docker Compose for PHP8 Service – without setup any MAMP, XAMP, nginx

Docker container is a unit of software that packages up code and all its dependencies to allow the application to tun quickly and reliably from one computing environment to another. For laynching multiple docker containers, a YAML file is used by compose to initialize services for the app. Creating and lauching all of the functions is as simple as issuing a single command when configutation is complete

Ok. Let’s create a Dockerfile first with below command

# Docker Image Name : mcc/web-server
# Command to build Docker Image : docker build –platform=linux/amd64 -t mcc/web-server:php8-amd64 .
FROM php:8.1.10-apache
USER root
RUN apt-get update

# Install GD
RUN apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev
&& docker-php-ext-configure gd –with-freetype –with-jpeg
&& docker-php-ext-install -j$(nproc) gd

RUN apt-get install -y libpq-dev pkg-config libcurl4-openssl-dev libicu-dev libonig-dev libxslt-dev
&& docker-php-ext-install pdo pdo_mysql curl fileinfo intl mbstring exif xsl

# Add php.ini config
COPY php/custom_config.ini /usr/local/etc/php/conf.d/

# Install OpenSSL
# RUN docker-php-ext-install openssl

# Enable RewriteModule
RUN a2enmod rewrite

On above command, we have php/custome_config.ini for easy config later, so we need create a folder structure like this

How to create a Dockerfile and Docker Compose for PHP8 Service

custom_config.ini with below info 

memory_limit = 1024M
max_execution_time = 600
max_input_time = 60
post_max_size = 512M
upload_max_filesize = 512M
max_file_uploads = 30
extension=gd
error_reporting = E_ERROR | E_PARSE

After that, create docker compose with below

version: ‘3.8’
networks:
  default:
    name: learntechtips-network
services:
    app:
       container_name: serverphp8
       image: serverphp8
       ports:
          – 8080:80
      volumes:
          – ./:/var/www/html:delegated

start your docker file then type the command
docker build . -t serverphp8
 
you will see this result 
How to create a Dockerfile and Docker Compose for PHP8 Service

continue the command: (for update the docker image)
docker-compose –compatibility up -d –force-recreate

How to create a Dockerfile and Docker Compose for PHP8 Service
Congratulation, You succeed created Docker Container for PHP8 service (include server)
After docker run smoothly, you can access to localhost:8080 for check result
How to create a Dockerfile and Docker Compose for PHP8 Service

If you still cannot catch up me on this topic, you can access to my github for checkout the docker file and docker compose for php8 service 👉 here

 
Thanks for reading. Any feedback and questions for Create a Dockefile and docker compose for PHP8 service. Leave your comment on below post, we can discuss about it.

✋✋✋✋ Learn Tech Tips – I am Zidane, See you next time