Laravel – PHPStorm & Docker

Docker-compose

version: "3.9"  # optional since v1.27.0
services:

    mariadb:
        image: mariadb
        environment:
            MARIADB_ROOT_PASSWORD: root
            MARIADB_DATABASE: laravel
        volumes:
            - ./.docker/mariadb/data:/var/lib/mysql
        restart: unless-stopped

    redis:
        image: redis
        volumes:
            - ./.docker/redis/data:/data
        restart: unless-stopped

    mongodb:
        image: mongo
        volumes:
        - ./.docker/mongodb/data:/data/db
        - ./.docker/mongodb/configdb:/data/configdb
        restart: unless-stopped

    php:
        build:
            context: .
            dockerfile: ./.docker/php/Dockerfile
        #image: php:8.1
        tty: true
        volumes:
            - ./:/var/www/html
        restart: unless-stopped

    nginx:
        image: nginx
        ports:
            - 8080:80
        volumes:
            - ./:/var/www/html
            - ./.docker/nginx/conf.d:/etc/nginx/conf.d/
        restart: unless-stopped

PHP Dockerfile

FROM php:8.1-fpm

# https://github.com/mlocati/docker-php-extension-installer

RUN apt-get update && apt-get upgrade -y

ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/

RUN chmod +x /usr/local/bin/install-php-extensions

RUN install-php-extensions mongodb-stable
RUN install-php-extensions redis-stable
RUN install-php-extensions opcache-stable
RUN install-php-extensions apcu-stable

RUN install-php-extensions mysqli pdo_mysql sqlite3
RUN install-php-extensions opcache memcache memcached
RUN install-php-extensions imagick gd
RUN install-php-extensions mbstring curl intl mcrypt xml xmlrpc xsl yaml zip ldap pcntl

RUN install-php-extensions @composer

# Set working directory
WORKDIR /var/www/html

EXPOSE 9000

CMD ["php-fpm"]

Nginx conf

server {
    listen 80;
    index index.php index.html;

    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;

    root /var/www/html/public;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
    location / {
        try_files $uri $uri/ /index.php?$query_string;
        gzip_static on;
    }
}

Setup PHP Test Framework

Check current Network mode

➜  mqtt-client git:(develop) ✗ docker network ls
NETWORK ID     NAME                  DRIVER    SCOPE
3527ee01a5b2   bridge                bridge    local
6a39d1caf0d9   host                  host      local
39cd55bac1ea   mqtt-client_default   bridge    local
939479be3201   none                  null      local

Than change Network mode to correct one

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Up ↑

%d bloggers like this: