0

i have a laravel based project that i have to host on digital ocean using docker. docker is working fine on localhost but shows 404 on server but phpmyadmin working fine on server as well which is running on 8080 port.

Here's my docker-compose.yml

 version: '3'

networks:
  laravel:


services:
  nginx:
    image: nginx:stable-alpine
    container_name: nginx
    ports:
      - "8088:80"
    volumes:
      - ./src:/var/www/html
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - php
      - mysql
    networks:
      - laravel

  mysql:
    image: mysql:5.7.22
    restart: unless-stopped
    tty: true
    ports:
      - "4306:3306"
    volumes:
      - ./mysql:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: "root"
      MYSQL_DATABASE: "laravel_test"
      MYSQL_USER: "root"
      MYSQL_PASSWORD: "root"
      SERVICE_TAGS: "dev"
      SERVICE_NAME: "mysql"
    networks:
      - laravel

  php:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: php
    volumes:
      - ./src:/var/www/html
    ports:
      - "9000:9000"
    restart: unless-stopped

    networks:
      - laravel

  phpmyadmin:
    image: phpmyadmin
    restart: always
    ports:
      - 8080:80
    environment:
      - PMA_ARBITRARY=1
    links:
      - mysql
    networks:
      - laravel

  npm:
    image: node:18-alpine3.14
    container_name: npm
    volumes:
      - ./src:/var/www/html
    working_dir: /var/www/html
    entrypoint: [ 'npm', '--no-bin-links' ]
    networks:
      - laravel

  composer:
    image: composer:latest
    container_name: composer
    volumes:
      - ./src:/var/www/html
    working_dir: /var/www/html
    depends_on:
      - php
    networks:
      - laravel

Dockerfile

FROM php:8.1.0-fpm

RUN docker-php-ext-install pdo pdo_mysql

default.conf

server{
    listen 80;
    index index.php index.html;
    server_name localhost;
    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/html/public;
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    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;
    }
}

my php file is in ./src/public/

rootShiv
  • 101
  • 1
  • (1) Are you sure you're talking directly to the server and not to a caching proxy? (2) What path is within the URL that you're testing with? (3) Does that path match a filename relative to `/var/www/html/public`? (4) Does `/var/www/html/public/index.php` exist? – Martin Kealey May 31 '22 at 05:32
  • yes file does exist , and this is working on localhost. i didn't understood your 1,2 question . im new to docker and server work in general – rootShiv May 31 '22 at 05:35
  • To confirm (1) simply check that _something_ appear in `/var/log/nginx/access.log` or `/var/log/nginx/error.log` when you try to access it from outside. If not then you're not actually connecting to _this_ server, something else is feeding you the 403 error. By (2) I mean, the URL with the `https://domain.name/` stripped off the front and any `?query=string` and `#anchor` stripped off the end. Further question: by "working on localhost", do you mean you're running a client (such as `curl` or `wget`) with a URL like `https://localhost/src/public/yourpage.php` ? – Martin Kealey May 31 '22 at 05:52
  • how do i access `/var/log/nginx/access.log` . im new to linux and ops side of development – rootShiv May 31 '22 at 05:57
  • There are many _many_ options, so the simplest is to say "the same way that you access `./src/public/yourscript`" – Martin Kealey Jun 02 '22 at 09:34

0 Answers0