✋✋✋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.
👉 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
custom_config.ini with below info
After that, create docker compose with below
networks:
default:
name: learntechtips-network
services:
app:
container_name: serverphp8
image: serverphp8
ports:
- 8080:80
volumes:
- ./:/var/www/html:delegated