<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: mickalannz</title>
    <description>The latest articles on DEV Community by mickalannz (@mickalannz).</description>
    <link>https://dev.to/mickalannz</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F928374%2F60a5cb82-9574-4a46-8c8e-4a01cfca44dc.png</url>
      <title>DEV Community: mickalannz</title>
      <link>https://dev.to/mickalannz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mickalannz"/>
    <language>en</language>
    <item>
      <title>RUN PHP 8, NGINX and PHP-fpm in single Docker container</title>
      <dc:creator>mickalannz</dc:creator>
      <pubDate>Sun, 18 Sep 2022 16:28:29 +0000</pubDate>
      <link>https://dev.to/mickalannz/run-php-8-nginx-and-php-fpm-in-single-docker-container-4pbd</link>
      <guid>https://dev.to/mickalannz/run-php-8-nginx-and-php-fpm-in-single-docker-container-4pbd</guid>
      <description>&lt;p&gt;If you are looking to run PHP 8, NGINX and PHP-fpm in a single Docker container, then this article is for you. I will show you how to configure a Dockerfile and docker-compose file to build and run a PHP 8, NGINX and PHP-fpm in single container.&lt;/p&gt;

&lt;p&gt;You can find nginx config and sample project here: &lt;a href="https://github.com/mickalannz/backend"&gt;Github&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Full guide Article: &lt;a href="https://www.reviewcurious.com/how-to-setup-php-8-nginx-php-fpm-and-alpine-with-docker/"&gt;How to setup PHP 8, NGINX, PHP-FPM and Alpine with Docker&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dockerfile&lt;/p&gt;

&lt;p&gt;The first thing we need is a Dockerfile. A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. We will use the following Dockerfile to build our image.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# First, We need an Operating System for our docker. We choose alpine.
FROM alpine:3.16.2

# Next, Update Alpine OS
RUN apk update &amp;amp;&amp;amp; apk upgrade

# Next, we need to install utilities inside alpine, we can achieve this by type RUN then, the alpine command.
# Install apline utilities and php depedencies
RUN apk add --no-cache \
    bash \
    php8 \ 
    php8-fpm \ 
    php8-opcache \
    php8-gd \
    php8-zlib \
    php8-curl \
    php8-bcmath \
    php8-ctype \
    php8-iconv \
    php8-intl \
    php8-json \
    php8-mbstring \
    php8-mysqlnd \
    php8-openssl \
    php8-pdo \
    php8-pdo_mysql \
    php8-pdo_pgsql \
    php8-pdo_sqlite \
    php8-phar \
    php8-posix \
    php8-session \
    php8-soap \
    php8-xml \
    php8-zip \
    libmcrypt-dev \
    libltdl 

# Next, Install nginx on alpine official guide in nginx official site. I just copied and paste what's on the site guide for installing nginx on alpine.
# https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/
RUN apk add openssl curl ca-certificates

# To set up the apk repository for stable nginx packages, run the command:
RUN printf "%s%s%s\n" \
"http://nginx.org/packages/alpine/v" \
`egrep -o '^[0-9]+\.[0-9]+' /etc/alpine-release` \
"/main" \
| tee -a /etc/apk/repositories

# Import an official nginx signing key so apk could verify the packages authenticity. Fetch the key:
RUN curl -o /tmp/nginx_signing.rsa.pub https://nginx.org/keys/nginx_signing.rsa.pub

# Verify that the downloaded file contains the proper key:
RUN openssl rsa -pubin -in /tmp/nginx_signing.rsa.pub -text -noout

# Move the key to apk trusted keys storage
RUN mv /tmp/nginx_signing.rsa.pub /etc/apk/keys/

# Now, install nginx
RUN apk add nginx

# Install PHP Composer, If you use composer, you can uncomment this one.
# RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# copy project file to nginx inside docker.
COPY ./src /usr/share/nginx/html/project

# Copy default config and paste it into nginx config path inside docker.
COPY ./nginx-configs/default.conf /etc/nginx/conf.d/default.conf

# Expose port to be visible outside the container.
EXPOSE 80
EXPOSE 443

STOPSIGNAL SIGTERM

# Execute startup command.
# Start php-fpm8 and nginx through bash terminal.
CMD ["/bin/bash", "-c", "php-fpm8 &amp;amp;&amp;amp; chmod 755 /usr/share/nginx/html/* &amp;amp;&amp;amp; nginx -g 'daemon off;'"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we need docker-compose. &lt;/p&gt;

&lt;p&gt;Docker compose is a tool used to define and run multi-container applications. With compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: "1.0"

services:
  backend:
    # Specify Image name
    image: backend

    # Specify Container name
    container_name: backend

    # specify context and dockerfile to build
    build: 

      #Docker context is path where dockerfile is located.
      context: ./

      #specify Dockerfile to build.
      dockerfile: Dockerfile

    #expose ports
    ports:
      - "8082:80"
      - "443:43"

    #persistent volume
    volumes: 
      - ./src:/usr/share/nginx/html/project
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the script in your project terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker-compose up -d
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Site Source: &lt;a href="https://www.reviewcurious.com/"&gt;Review Curious&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
