Background
Break News
How to add local font to Tailwind Css and NextJS? - Tutorial Design Pattern? - Blockchain Technology, How to create own Bitcoin virtual currency - Zustand mordern management state - Design Pattern - Flyweight Pattern? - Docker Full training Topic

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

Tuesday 27 September 2022
|
Read: Completed in minutes

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

✋✋✋Hello everyone, welcome back to Webzone Tech Tips . 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.  

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.
✋✋✋✋ Webzone Tech Tips - I am Zidane, See you next time


🙇🏼 We Appreciate Your Comments and Suggestions - Webzone - all things Tech Tips web development 🙇🏼
Popular Webzone Tech Tips topic maybe you will be like it - by Webzone Tech Tips - Zidane
As a student, I found Blogspot very useful when I joined in 2014. I have been a developer for years . To give back and share what I learned, I started Webzone, a blog with tech tips. You can also search for tech tips zidane on Google and find my helpful posts. Love you all,

I am glad you visited my blog. I hope you find it useful for learning tech tips and webzone tricks. If you have any technical issues, feel free to browse my posts and see if they can help you solve them. You can also leave a comment or contact me if you need more assistance. Here is my blog address: https://learn-tech-tips.blogspot.com.

My blog where I share my passion for web development, webzone design, and tech tips. You will find tutorials on how to build websites from scratch, using hot trends frameworks like nestjs, nextjs, cakephp, devops, docker, and more. You will also learn how to fix common bugs on development, like a mini stackoverflow. Plus, you will discover how to easily learn programming languages such as PHP (CAKEPHP, LARAVEL), C#, C++, Web(HTML, CSS, javascript), and other useful things like Office (Excel, Photoshop). I hope you enjoy my blog and find it helpful for your projects. :)

Thanks and Best Regards!
Follow me on Tiktok @learntechtips and send me a direct message. I will be happy to chat with you.
Webzone - Zidane (huuvi168@gmail.com)
I'm developer, I like code, I like to learn new technology and want to be friend with people for learn each other
I'm a developer who loves coding, learning new technologies, and making friends with people who share the same passion. I have been a full stack developer since 2015, with more than years of experience in web development.
Copyright @2022(November) Version 1.0.0 - By Webzone, all things Tech Tips for Web Development Zidane
https://learn-tech-tips.blogspot.com