Skip to content

Commit 0012cf1

Browse files
committed
feat(docker): add Docker setup with Nginx and PHP-FPM configuration
Signed-off-by: Sam Poyigi <[email protected]>
1 parent adf138e commit 0012cf1

File tree

7 files changed

+134
-0
lines changed

7 files changed

+134
-0
lines changed

Diff for: .dockerignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.DS_Store
2+
node_modules
3+
vendor
4+
storage/*.key
5+
.env
6+
docker/Dockerfile
7+
tests
8+
docker-compose*
9+
.git

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ composer.lock
1212
node_modules
1313

1414
/public/vendor
15+
/public/storage

Diff for: docker-compose.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
services:
2+
app:
3+
build:
4+
context: .
5+
dockerfile: docker/Dockerfile
6+
container_name: tastyigniter-app
7+
env_file:
8+
- ./.env
9+
ports:
10+
- "8080:80"
11+
volumes:
12+
- ./:/var/www

Diff for: docker/Dockerfile

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
FROM php:8.3-fpm
2+
3+
WORKDIR /var/www
4+
5+
# Install system dependencies
6+
RUN apt-get update && apt-get install -y \
7+
nginx \
8+
supervisor \
9+
git curl zip unzip libzip-dev \
10+
libpng-dev libjpeg-dev libfreetype6-dev \
11+
libonig-dev libxml2-dev libssl-dev \
12+
libicu-dev \
13+
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
14+
&& docker-php-ext-install \
15+
gd \
16+
opcache \
17+
pdo_mysql \
18+
mbstring \
19+
zip \
20+
exif \
21+
pcntl \
22+
bcmath \
23+
intl \
24+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
25+
26+
# Ensure supervisord and nginx can write to the log directory
27+
RUN mkdir -p /var/log/supervisord /var/run/supervisord
28+
29+
# Install Composer
30+
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
31+
32+
# Copy Laravel source code
33+
COPY . /var/www
34+
35+
# Copy configs from the docker/ folder (relative to build context)
36+
COPY docker/nginx.conf /etc/nginx/sites-available/default
37+
COPY docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
38+
COPY docker/entrypoint.sh /entrypoint.sh
39+
40+
# Permissions
41+
RUN chown -R www-data:www-data /var/www \
42+
&& chmod -R 755 /var/www/storage \
43+
&& chmod -R 755 /var/www/bootstrap/cache \
44+
&& chmod +x /entrypoint.sh
45+
46+
# Install PHP dependencies (production only)
47+
RUN composer install --no-dev --prefer-dist --optimize-autoloader \
48+
&& php artisan config:cache \
49+
&& php artisan route:cache \
50+
&& php artisan view:cache
51+
52+
# Expose HTTP
53+
EXPOSE 80
54+
55+
ENTRYPOINT ["/entrypoint.sh"]
56+
CMD ["default"]

Diff for: docker/entrypoint.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
set -e
3+
4+
if [ "$1" = "horizon" ]; then
5+
php artisan horizon
6+
else
7+
/usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
8+
fi

Diff for: docker/nginx.conf

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
server {
2+
listen 80;
3+
server_name localhost;
4+
root /var/www/public;
5+
6+
index index.php index.html;
7+
8+
add_header X-Frame-Options "SAMEORIGIN";
9+
add_header X-XSS-Protection "1; mode=block";
10+
add_header X-Content-Type-Options "nosniff";
11+
12+
charset utf-8;
13+
14+
location / {
15+
try_files $uri $uri/ /index.php?$query_string;
16+
}
17+
18+
location = /favicon.ico { access_log off; log_not_found off; }
19+
location = /robots.txt { access_log off; log_not_found off; }
20+
21+
location ~ \.php$ {
22+
try_files $uri /index.php =404;
23+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
24+
fastcgi_pass 127.0.0.1:9000;
25+
fastcgi_index index.php;
26+
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
27+
fastcgi_param PATH_INFO $fastcgi_path_info;
28+
include fastcgi_params;
29+
}
30+
31+
gzip on;
32+
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
33+
gzip_vary on;
34+
35+
location ~ /\.(?!well-known).* {
36+
deny all;
37+
}
38+
}

Diff for: docker/supervisord.conf

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[supervisord]
2+
nodaemon=true
3+
logfile=/var/log/supervisord/supervisord.log
4+
pidfile=/var/run/supervisord/supervisord.pid
5+
6+
[program:php-fpm]
7+
command=/usr/local/sbin/php-fpm
8+
9+
[program:nginx]
10+
command=/usr/sbin/nginx -g "daemon off;"

0 commit comments

Comments
 (0)