fix permission and trouble on mysql docker

This commit is contained in:
root
2025-06-11 13:43:24 +07:00
parent f92655e3e2
commit 9b25a772a6
8 changed files with 165 additions and 128 deletions

View File

@@ -63,7 +63,8 @@ RUN mkdir -p /var/www/html/storage/logs \
&& mkdir -p /var/www/html/bootstrap/cache \ && mkdir -p /var/www/html/bootstrap/cache \
&& chown -R www-data:www-data /var/www/html \ && chown -R www-data:www-data /var/www/html \
&& chmod -R 775 /var/www/html/storage \ && chmod -R 775 /var/www/html/storage \
&& chmod -R 775 /var/www/html/bootstrap/cache && chmod -R 775 /var/www/html/bootstrap/cache \
&& chmod -R 755 /var/www/html/public
# Create nginx config # Create nginx config
COPY ./docker/nginx.conf /etc/nginx/sites-available/default COPY ./docker/nginx.conf /etc/nginx/sites-available/default

View File

@@ -71,7 +71,8 @@ RUN mkdir -p /var/www/html/storage/logs \
&& mkdir -p /var/www/html/bootstrap/cache \ && mkdir -p /var/www/html/bootstrap/cache \
&& chown -R www-data:www-data /var/www/html \ && chown -R www-data:www-data /var/www/html \
&& chmod -R 775 /var/www/html/storage \ && chmod -R 775 /var/www/html/storage \
&& chmod -R 775 /var/www/html/bootstrap/cache && chmod -R 775 /var/www/html/bootstrap/cache \
&& chmod -R 755 /var/www/html/public
# Create nginx config for development # Create nginx config for development
COPY ./docker/nginx.dev.conf /etc/nginx/sites-available/default COPY ./docker/nginx.dev.conf /etc/nginx/sites-available/default

View File

@@ -9,6 +9,7 @@ services:
volumes: volumes:
- ./storage:/var/www/html/storage - ./storage:/var/www/html/storage
- ./bootstrap/cache:/var/www/html/bootstrap/cache - ./bootstrap/cache:/var/www/html/bootstrap/cache
- ./docker/php.ini:/usr/local/etc/php/conf.d/local.ini
ports: ports:
- "80:80" - "80:80"
environment: environment:
@@ -22,26 +23,28 @@ services:
db: db:
image: mysql:8.0 image: mysql:8.0
platform: linux/amd64
container_name: ckb-mysql-prod container_name: ckb-mysql-prod
restart: unless-stopped restart: unless-stopped
environment: environment:
MYSQL_DATABASE: ckb_production MYSQL_DATABASE: ${DB_DATABASE:-ckb_production}
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD} MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD:-rootpassword}
MYSQL_PASSWORD: ${DB_PASSWORD} MYSQL_PASSWORD: ${DB_PASSWORD:-password}
MYSQL_USER: ${DB_USERNAME} MYSQL_USER: ${DB_USERNAME:-laravel}
volumes: volumes:
- mysql_data:/var/lib/mysql - mysql_data:/var/lib/mysql
- ./docker/mysql.cnf:/etc/mysql/conf.d/mysql.cnf - ./docker/mysql.cnf:/etc/mysql/conf.d/mysql.cnf:ro
ports: ports:
- "3306:3306" - "3306:3306"
networks: networks:
- ckb-network - ckb-network
command: --default-authentication-plugin=mysql_native_password
redis: redis:
image: redis:7-alpine image: redis:7-alpine
container_name: ckb-redis-prod container_name: ckb-redis-prod
restart: unless-stopped restart: unless-stopped
command: redis-server --appendonly yes --requirepass ${REDIS_PASSWORD} command: redis-server --appendonly yes ${REDIS_PASSWORD:+--requirepass $REDIS_PASSWORD}
volumes: volumes:
- redis_data:/data - redis_data:/data
ports: ports:

View File

@@ -9,6 +9,7 @@ services:
volumes: volumes:
- ./:/var/www/html - ./:/var/www/html
- ./docker/php.ini:/usr/local/etc/php/conf.d/local.ini - ./docker/php.ini:/usr/local/etc/php/conf.d/local.ini
- ./docker/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
- storage_logs:/var/www/html/storage/logs - storage_logs:/var/www/html/storage/logs
- storage_cache:/var/www/html/storage/framework - storage_cache:/var/www/html/storage/framework
ports: ports:
@@ -24,8 +25,9 @@ services:
- ckb-network - ckb-network
db: db:
image: mysql:8.0 image: mariadb:10.6
container_name: ckb-mysql platform: linux/amd64
container_name: ckb-mysql-dev
restart: unless-stopped restart: unless-stopped
environment: environment:
MYSQL_DATABASE: ckb_db MYSQL_DATABASE: ckb_db
@@ -35,6 +37,7 @@ services:
volumes: volumes:
- mysql_data:/var/lib/mysql - mysql_data:/var/lib/mysql
- ./ckb.sql:/docker-entrypoint-initdb.d/01-init.sql:ro - ./ckb.sql:/docker-entrypoint-initdb.d/01-init.sql:ro
- ./docker/mysql.cnf:/etc/mysql/conf.d/mysql.cnf:ro
ports: ports:
- "3306:3306" - "3306:3306"
networks: networks:
@@ -42,10 +45,12 @@ services:
redis: redis:
image: redis:7-alpine image: redis:7-alpine
container_name: ckb-redis container_name: ckb-redis-dev
restart: unless-stopped restart: unless-stopped
ports: ports:
- "6379:6379" - "6379:6379"
volumes:
- redis_data:/data
networks: networks:
- ckb-network - ckb-network
@@ -77,6 +82,8 @@ services:
volumes: volumes:
mysql_data: mysql_data:
driver: local driver: local
redis_data:
driver: local
storage_logs: storage_logs:
driver: local driver: local
storage_cache: storage_cache:

View File

@@ -107,6 +107,9 @@ start_containers() {
print_status "Waiting for MySQL to be ready..." print_status "Waiting for MySQL to be ready..."
sleep 20 sleep 20
# Wait a bit more for MySQL to be fully ready
sleep 10
# Check if database was imported automatically # Check if database was imported automatically
if docker-compose exec -T db mysql -u root -proot -e "USE ckb_db; SHOW TABLES;" > /dev/null 2>&1; then if docker-compose exec -T db mysql -u root -proot -e "USE ckb_db; SHOW TABLES;" > /dev/null 2>&1; then
table_count=$(docker-compose exec -T db mysql -u root -proot -e "USE ckb_db; SHOW TABLES;" 2>/dev/null | wc -l) table_count=$(docker-compose exec -T db mysql -u root -proot -e "USE ckb_db; SHOW TABLES;" 2>/dev/null | wc -l)
@@ -118,7 +121,7 @@ start_containers() {
fi fi
else else
print_warning "Database not accessible. Running manual import..." print_warning "Database not accessible. Running manual import..."
sleep 10 sleep 15
./docker-import-db.sh dev ./docker-import-db.sh dev
fi fi

View File

@@ -12,34 +12,32 @@ DB_CONNECTION=mysql
DB_HOST=db DB_HOST=db
DB_PORT=3306 DB_PORT=3306
DB_DATABASE=ckb_db DB_DATABASE=ckb_db
DB_USERNAME=laravel DB_USERNAME=root
DB_PASSWORD=password DB_PASSWORD=root
DB_ROOT_PASSWORD=root
# Redis Configuration for Docker # Redis Configuration for Docker
REDIS_HOST=redis REDIS_HOST=redis
REDIS_PASSWORD=null REDIS_PASSWORD=null
REDIS_PORT=6379 REDIS_PORT=6379
# Cache Configuration BROADCAST_DRIVER=log
CACHE_DRIVER=redis CACHE_DRIVER=redis
QUEUE_CONNECTION=redis FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=redis SESSION_DRIVER=redis
SESSION_LIFETIME=120
# Mail Configuration (using MailHog for development) # Mail Configuration for Docker (MailHog)
MAIL_MAILER=smtp MAIL_MAILER=smtp
MAIL_HOST=mailhog MAIL_HOST=mailhog
MAIL_PORT=1025 MAIL_PORT=1025
MAIL_USERNAME=null MAIL_USERNAME=null
MAIL_PASSWORD=null MAIL_PASSWORD=null
MAIL_ENCRYPTION=null MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=noreply@ckb.local MAIL_FROM_ADDRESS=test@ckb.local
MAIL_FROM_NAME="${APP_NAME}" MAIL_FROM_NAME="${APP_NAME}"
# Broadcasting # AWS (if needed for production)
BROADCAST_DRIVER=log
# AWS (if needed)
AWS_ACCESS_KEY_ID= AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY= AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1 AWS_DEFAULT_REGION=us-east-1
@@ -50,7 +48,13 @@ AWS_USE_PATH_STYLE_ENDPOINT=false
PUSHER_APP_ID= PUSHER_APP_ID=
PUSHER_APP_KEY= PUSHER_APP_KEY=
PUSHER_APP_SECRET= PUSHER_APP_SECRET=
PUSHER_HOST=
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_CLUSTER=mt1 PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

View File

@@ -4,27 +4,27 @@ default-authentication-plugin = mysql_native_password
character-set-server = utf8mb4 character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci collation-server = utf8mb4_unicode_ci
# Connection settings # Performance settings
max_connections = 200
connect_timeout = 60
wait_timeout = 600
interactive_timeout = 600
# Buffer settings
innodb_buffer_pool_size = 256M innodb_buffer_pool_size = 256M
innodb_log_file_size = 64M innodb_log_file_size = 64M
innodb_log_buffer_size = 16M
innodb_flush_log_at_trx_commit = 1 innodb_flush_log_at_trx_commit = 1
innodb_flush_method = O_DIRECT
# Query cache # Connection settings
query_cache_type = 1 max_connections = 200
query_cache_size = 32M max_allowed_packet = 16M
query_cache_limit = 2M
# Logging # Logging
general_log = 0
slow_query_log = 1 slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 2 long_query_time = 2
# Security # Security
local_infile = 0 sql_mode = STRICT_TRANS_TABLES,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO
[mysql]
default-character-set = utf8mb4
[client]
default-character-set = utf8mb4

View File

@@ -1,21 +1,16 @@
; PHP Configuration for CKB Laravel App ; PHP Configuration for Laravel
; Maximum execution time ; General settings
max_execution_time = 300
; Maximum input time
max_input_time = 300
; Memory limit
memory_limit = 512M memory_limit = 512M
max_execution_time = 300
; Upload settings max_input_time = 300
upload_max_filesize = 100M
post_max_size = 100M post_max_size = 100M
upload_max_filesize = 100M
max_file_uploads = 20 max_file_uploads = 20
; Error reporting ; Error reporting (will be overridden by environment)
display_errors = Off display_errors = Off
display_startup_errors = Off
log_errors = On log_errors = On
error_log = /var/log/php_errors.log error_log = /var/log/php_errors.log
@@ -23,14 +18,37 @@ error_log = /var/log/php_errors.log
date.timezone = Asia/Jakarta date.timezone = Asia/Jakarta
; Session settings ; Session settings
session.save_handler = files
session.save_path = /var/www/html/storage/framework/sessions
session.gc_maxlifetime = 1440 session.gc_maxlifetime = 1440
session.cookie_lifetime = 0 session.cookie_lifetime = 0
session.cookie_secure = Off
session.cookie_httponly = On
; OPcache settings ; OPcache settings (for production performance)
opcache.enable = 1 opcache.enable = 1
opcache.enable_cli = 0
opcache.memory_consumption = 128 opcache.memory_consumption = 128
opcache.interned_strings_buffer = 8 opcache.interned_strings_buffer = 8
opcache.max_accelerated_files = 4000 opcache.max_accelerated_files = 4000
opcache.revalidate_freq = 2 opcache.revalidate_freq = 2
opcache.fast_shutdown = 1 opcache.fast_shutdown = 1
opcache.enable_cli = 1
; Security settings
expose_php = Off
allow_url_fopen = On
allow_url_include = Off
; File uploads
file_uploads = On
upload_tmp_dir = /tmp
; MySQL settings
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
; Redis extension
extension = redis.so