Describe the bug
I tried following the documentation to setup an instance locally using Docker.
I chose the FPM version and once the containers were up I tried loading the application and got "Whoops! Something went wrong" page, after some research I tried a few different things, this is how my docker-compose.yml looks like, note that I added a few comments on relevant lines:
version: "3.4"
services:
app:
image: monicahq/monicahq:fpm
depends_on:
- mysql
environment:
- APP_KEY=5KilLarCr4BDHJxARrwgz0xIcM1NM75s
- APP_DEBUG=1 # display useful error messages
- [email protected] # from https://github.com/monicahq/monica/issues/2175
- DB_DATABASE=monica # seem required from config/database.php
- DB_HOST=mysql
- DB_PASSWORD=secret # seem required from config/database.php
- DB_USERNAME=homestead # THIS IS THE FIX, it was previously DB_USER
volumes:
- html:/var/www/monica
- data:/var/www/monica/storage
links:
- mysql # allow containers to talk to each other
restart: always
web:
image: nginx
ports:
- 80:80
depends_on:
- app
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- html:/var/www/monica:ro
- data:/var/www/monica/storage:ro
restart: always
mysql:
image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=9xmkYcstMCU2tT3Tgq3bTUDUYQK4fYsP
- MYSQL_DATABASE=monica
- MYSQL_USER=homestead
- MYSQL_PASSWORD=secret
volumes:
- mysql:/var/lib/mysql
restart: always
volumes:
data:
name: monica_data
html:
name: monica_html
mysql:
name: monica_mysql
After turning debugging on, this is the error I've got: SQLSTATE[HY000] [2002] Connection refused (SQL: select * fromcachewherekey= laravel_cachecloudflare.proxies limit 1).
I suspect my setup is not allowing the app to communicate with the mysql container. I tried links, I also tried setting DB_ env variables from looking at the source.
Any pointers or things I should try?
Thank you for making this project open source, I appreciate it.
could you give us your nginx.conf file too?
Hi @asbiin sure, I am using the one mentioned in the docs:
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
upstream php-handler {
server app:9000;
}
server {
listen 80;
server_name monica;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
add_header Referrer-Policy no-referrer;
root /var/www/monica/public;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ ^/(?:robots.txt|security.txt) {
allow all;
log_not_found off;
access_log off;
}
error_page 404 500 502 503 504 /index.php;
location = /.well-known/(?:carddav|caldav) {
return 301 $scheme://$host/dav;
}
location = /.well-known/security.txt {
return 301 $scheme://$host/security.txt;
}
location ~ /\.(?!well-known).* {
deny all;
}
# set max upload size
client_max_body_size 10G;
fastcgi_buffers 64 4K;
# Enable gzip but do not remove ETag headers
gzip on;
gzip_vary on;
gzip_comp_level 4;
gzip_min_length 256;
gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;
# Uncomment if your server is build with the ngx_pagespeed module
# This module is currently not supported.
#pagespeed off;
location ~ \.php$ {
# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
# Check that the PHP script exists before passing it
try_files $fastcgi_script_name =404;
fastcgi_pass php-handler;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# Bypass the fact that try_files resets $fastcgi_path_info
# see: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
}
# Adding the cache control header for js and css files
# Make sure it is BELOW the PHP block
location ~ \.(?:css|js|woff2?|svg|gif|json)$ {
try_files $uri /index.php$request_uri;
add_header Cache-Control "public, max-age=15778463";
# Optional: Don't log access to assets
access_log off;
}
location ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ {
try_files $uri /index.php$request_uri;
# Optional: Don't log access to assets
access_log off;
}
}
}
Curiously you set DB_USER=homestead where it should be DB_USERNAME according to config/database.php (I did that too and now can't find any place that says so).
@dejj Good point! I didn't see it :)
@dejj Thanks for spotting that, I updated the docker-compose.yaml but I am still unable to get past the SQLSTATE[HY000] [2002] Connection refused (SQL: select * fromcachewherekey= laravel_cachecloudflare.proxies limit 1) error.
I did the following to recreate everything from scratch:
~/workspace/private/monica
❯ docker-compose down
Stopping monica_web_1 ... done
Stopping monica_app_1 ... done
Stopping monica_mysql_1 ... done
Removing monica_web_1 ... done
Removing monica_app_1 ... done
Removing monica_mysql_1 ... done
Removing network monica_default
~/workspace/private/monica
❯ docker volume rm monica_data monica_html monica_mysql
monica_data
monica_html
monica_mysql
~/workspace/private/monica
❯ docker-compose up --build
Creating network "monica_default" with the default driver
Creating volume "monica_data" with default driver
Creating volume "monica_html" with default driver
...
...
app_1 | ✓ Performing migrations
app_1 | '/usr/bin/php7' 'artisan' migrate --force
app_1 | Migration table created successfully.
app_1 | Migrating: 2014_10_12_000000_create_users_table
app_1 | Migrated: 2014_10_12_000000_create_users_table (0.01 seconds)
app_1 | Migrating: 2014_10_12_100000_create_password_resets_table
app_1 | Migrated: 2014_10_12_100000_create_password_resets_table (0.01 seconds)
app_1 | Migrating: 2016_06_01_000001_create_oauth_auth_codes_table
...
app_1 | Migrating: 2019_09_04_075311_fix_tattoo_or_piercing_translation
app_1 | Migrated: 2019_09_04_075311_fix_tattoo_or_piercing_translation (0 seconds)
app_1 |
app_1 | ✓ Ping for new version
app_1 | '/usr/bin/php7' 'artisan' monica:ping --force
app_1 | Call url:https://version.monicahq.com/ping
app_1 | instance version:2.15.2
app_1 | current version:2.15.2
app_1 |
app_1 | ✓ Maintenance mode: off
app_1 | '/usr/bin/php7' 'artisan' up
app_1 | Application is now live.
app_1 |
app_1 | Monica v2.15.2 is set up, enjoy.
app_1 | Passport keys creation ...
app_1 | Encryption keys generated successfully.
app_1 | Personal access client created successfully.
app_1 | Client ID: 1
app_1 | Client secret: TMxsTjrtGODqMwqK9VExeD5tJ3einxivoPQbEkKc
app_1 | ! Please be careful to backup /var/www/monica/storage/oauth-public.key and /var/www/monica/storage/oauth-private.key files !
app_1 | [31-Dec-2019 17:23:48] NOTICE: fpm is running, pid 1
app_1 | [31-Dec-2019 17:23:48] NOTICE: ready to handle connections
web_1 | 172.29.0.1 - - [31/Dec/2019:17:23:58 +0000] "GET / HTTP/1.1" 500 1495 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:71.0) Gecko/20100101 Firefox/71.0" "-"
I trimmed the output but I see the database migrations being applied so I am confused with the fact that the app is having a connection refused when rendering. 🤔
is your CACHE_DRIVER set to file or database?
Hey all, I've been running into the same issue described here using podman and pods instead of docker-compose. I managed to get everything working by using 127.0.0.1 as the DB_HOST instead of localhost in my case. Not sure why this fixes it but just my two cents.
Using DB_USERNAME on monicahq image fixed it.
DB_HOST must be set at mysql
links should be replaced by depends_on on the docker-compose file.
Updated the issue to reflect the solution, thank you 🙏
Most helpful comment
Curiously you set
DB_USER=homesteadwhere it should beDB_USERNAMEaccording toconfig/database.php(I did that too and now can't find any place that says so).