I have a Nginx, PHP-FPM and MySQL running inside a docker containers. I want install Opencart 3 in subfolder “public” for future developement.
But when I try to install OC3, I get a 404 error from nginx. At the same time, the server is working, the containers are pinging with each other, I can display the phpinfo() and there it is clear that everything is working properly.
Where is the mistake?
docker-compose.yml
version: '3.7'
services:
ktt_nginx:
build: ./docker/nginx
container_name: ktt_nginx
ports:
- '86:80'
volumes:
- ./docker/nginx/conf:/etc/nginx/conf.d
- .:/var/www/html
- ./docker/nginx/log/:/var/log/nginx
- /tmp:/tmp
depends_on:
- ktt_php
networks:
- ktt-net
ktt_php:
build: ./docker/php
container_name: ktt_php
volumes:
- .:/var/www/html
- /tmp:/tmp
- ~/.composer:/var/www/.composer
depends_on:
- ktt_mysql
networks:
- ktt-net
ktt_mysql:
image: mysql:5.7
container_name: ktt_mysql
ports:
- "3386:3306"
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=kttdb
- MYSQL_USER=opencart
- MYSQL_PASSWORD=root
volumes:
- ktt_mysql_data:/var/lib/mysql
networks:
- ktt-net
ktt_pma:
image: phpmyadmin/phpmyadmin
container_name: ktt_pma
environment:
- PMA_ARBITRARY=1
restart: always
ports:
- 8086:80
volumes:
- /sessions
depends_on:
- ktt_mysql
networks:
- ktt-net
networks:
ktt-net:
volumes:
ktt_mysql_data:
server.conf
server {
server_name localhost;
root /var/www/html/public;
location / {
# try to serve file directly, fallback to index.php
try_files $uri /index.php$is_args$args;
}
location ~ ^/index.php(/|$) {
fastcgi_pass ktt_php:9000;
fastcgi_split_path_info ^(.+.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/index.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
# return 404 for all other php files not matching the front controller
# this prevents access to other php files you don't want to be accessible.
location ~ .php$ {
return 404;
}
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
nginx Dockerfile
FROM nginx:latest
RUN apt-get update && apt-get install mc -y
RUN usermod -u 1000 nginx && groupmod -g 1000 nginx
3
Answers
I again had to deal with configuring Opencart to work inside a Docker container. And now I was able to do the correct system configuration. So, an example of a configuration for OpenCart 3.
docker-compose.yml
docker/mysql/Dockerfile
docker/nginx/conf/server.conf
docker/php-fpm/Dockerfile
docker/php-fpm/php.ini
Make sure you have correct permission to the folder containing opencart
chmod -R 777 /var/www/html
opencart folder under html
/var/www/html/opencart
Now try to run opencart from browser.
this works with me.
In my case was the $document_root wrong, because the document root of nginx was different to php-fpm.
Document root of nginx: /usr/share/nginx/html/
Document root of php:8-fpm: /var/www/html