Browse Source

add Docker setup with PHP, Nginx, and MySQL for SMS gateway application

master
Amirul Anwar 1 month ago
parent
commit
a448cd4cec
6 changed files with 125 additions and 0 deletions
  1. 3
    0
      .bash_history
  2. 1
    0
      .composer/.htaccess
  3. 1
    0
      .composer/cache/.htaccess
  4. 49
    0
      Dockerfile
  5. 48
    0
      docker-compose.yml
  6. 23
    0
      nginx.conf

+ 3
- 0
.bash_history View File

1
+ls
2
+composer install
3
+exit

+ 1
- 0
.composer/.htaccess View File

1
+Deny from all

+ 1
- 0
.composer/cache/.htaccess View File

1
+Deny from all

+ 49
- 0
Dockerfile View File

1
+FROM php:8.1-fpm
2
+
3
+# Set working directory
4
+WORKDIR /var/www
5
+
6
+# Install dependencies
7
+RUN apt-get update && apt-get install -y \
8
+    build-essential \
9
+    libpng-dev \
10
+    libjpeg62-turbo-dev \
11
+    libfreetype6-dev \
12
+    locales \
13
+    zip \
14
+    jpegoptim optipng pngquant gifsicle \
15
+    vim \
16
+    unzip \
17
+    git \
18
+    curl \
19
+    libonig-dev \
20
+    libzip-dev \
21
+    libxml2-dev
22
+
23
+# Clear cache
24
+RUN apt-get clean && rm -rf /var/lib/apt/lists/*
25
+
26
+# Install PHP extensions
27
+RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
28
+    && docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
29
+
30
+# Install Composer
31
+COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
32
+
33
+# Copy existing application directory contents
34
+COPY . /var/www
35
+
36
+# Create storage and bootstrap/cache directories and set permissions
37
+RUN mkdir -p /var/www/storage /var/www/bootstrap/cache \
38
+    && chown -R www-data:www-data /var/www/storage /var/www/bootstrap/cache \
39
+    && chmod -R 775 /var/www/storage /var/www/bootstrap/cache
40
+
41
+# Copy existing application directory permissions
42
+COPY --chown=www-data:www-data . /var/www
43
+
44
+# Change current user to www
45
+USER www-data
46
+
47
+# Expose port 9000 and start php-fpm server
48
+EXPOSE 9000
49
+CMD ["php-fpm"]

+ 48
- 0
docker-compose.yml View File

1
+services:
2
+  app:
3
+    build:
4
+      context: .
5
+      dockerfile: Dockerfile
6
+    image: sms-gateway-app
7
+    container_name: sms-gateway-app
8
+    restart: unless-stopped
9
+    working_dir: /var/www
10
+    volumes:
11
+      - .:/var/www
12
+    networks:
13
+      - sms-gateway-network
14
+    ports:
15
+      - "9000:9000"
16
+
17
+  webserver:
18
+    image: nginx:alpine
19
+    container_name: sms-gateway-webserver
20
+    restart: unless-stopped
21
+    ports:
22
+      - "80:80"
23
+    volumes:
24
+      - .:/var/www
25
+      - ./nginx.conf:/etc/nginx/conf.d/default.conf
26
+    networks:
27
+      - sms-gateway-network
28
+
29
+  db:
30
+    image: mysql:8.0
31
+    container_name: sms-gateway-db
32
+    restart: unless-stopped
33
+    environment:
34
+      MYSQL_DATABASE: sms-gateway
35
+      MYSQL_ROOT_PASSWORD: root
36
+    volumes:
37
+      - db_data:/var/lib/mysql
38
+    networks:
39
+      - sms-gateway-network
40
+    ports:
41
+      - "3306:3306"
42
+
43
+networks:
44
+  sms-gateway-network:
45
+    driver: bridge
46
+
47
+volumes:
48
+  db_data:

+ 23
- 0
nginx.conf View File

1
+server {
2
+    listen 80;
3
+    index index.php index.html;
4
+    server_name localhost;
5
+
6
+    root /var/www/public;
7
+
8
+    location / {
9
+        try_files $uri $uri/ /index.php?$query_string;
10
+    }
11
+
12
+    location ~ \.php$ {
13
+        include fastcgi_params;
14
+        fastcgi_pass app:9000;
15
+        fastcgi_index index.php;
16
+        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
17
+        fastcgi_param PATH_INFO $fastcgi_path_info;
18
+    }
19
+
20
+    location ~ /\.ht {
21
+        deny all;
22
+    }
23
+}

Loading…
Cancel
Save